Home arrow Site Info arrow Latest Portal Content arrow VBA: Standardize, Automate Common Metadata Elements
VBA: Standardize, Automate Common Metadata Elements PDF Print E-mail

Written by Bert Granberg,

Ahhh metadata. You have 35 GIS data layers and need to change your metadata's contact information and disclaimer language for all of them. Metadata is bad enough, right? There must be an easier way to do this than manually/menially/mundanely opening up each layer, one-at-a-time in the ArcCatalog metadata editor?

Luckily, there is an easier way. This VBA script will operate on selected feature classes and/or feature datasets in ArcCatalog and allows for bulk selected updating of metadata element values. The example code shows an update by AGRC of its standard online linkage, disclaimer, and distribution contact elements for SGID data.

Before customizing this script to meet your needs you will need to do two things:

  1. Figure out the mapping from FGDC metadata elements you would like to update to the ArcObjects-based xml tags (ex. FGDC's "Identification_Information/Use_Constraints = ArcObjects "idinfo/useconst". This is not hard but takes some time/effort...here's a list of most of the ArcObjects metadata property elements
  2. BE CAREFUL! This script will operate on all the feature classes that you have selected in the Contents tab in ArcCatalog. Do you really want to override contact info (for example) for all the feature classes? or are there some that need to stay the same? Take a deep breath and give it some thought.

To use this script:

  1. Open ArcCatalog's VBA Editor from the Tools --> Macros -->Visual Basic Editor and open the Project Explorer window from the View menu.
  2. Paste the code below, consisting of 2 subprocedures, into the Normal --> ArcCatalog Objects --> ThisDocument. The code is a little long but it includes many lines required for the current Utah SGID data disclaimer.
  3. Customize the pMetadataXMLPropertySet2.SetPropertyX statements to use and set values for metadata elements you want to chang
  4. In the ArcCatalog Contents view (not the tree view on the left side of AC) select feature class(es) or feature dataset(s) to operate on. Start on a test feature class first!!!
  5. In the VBA editor, put your cursor anywhere in the GetSelectedFeatureClasses() procedure and select Run Sub/UserForm from the Run menu (or hit the F5 key)

Note: I have included, but commented out, a line that will allow you to load a custom layer thumbnail image into the metadata. If you're tired of the standard black dots, black lines and yellow polygons with absolutely no other context information, you might experiment with exporting a better image and customizing this code to get it to load.

 

'updated 9/22/08 4:07pm 

Public Sub GetSelectedFeatureClasses()

    'declare variables
    Dim pGxApp As IGxApplication
    Dim pSelGxObject As IGxObject
    Dim pGxSel As IGxSelection
    Dim pEnumGxObjSel As IEnumGxObject
    Dim pGxObjContainer As IGxObjectContainer
    Dim pEnumGxObj As IEnumGxObject
    Dim pCurrGxObject As IGxObject
   
   
    'get pointer to AC app and current selection
    Set pGxApp = Application
    Set pGxSel = pGxApp.Selection
    Set pEnumGxObjSel = pGxSel.SelectedObjects
    pEnumGxObjSel.Reset
   
   
    'iterate thru selected AC objects
    Set pSelGxObject = pEnumGxObjSel.Next
    Do Until pSelGxObject Is Nothing
       
        If InStr(pSelGxObject.Category, "Feature Class") > 0 Or pSelGxObject.Category = "Shapefile" Then
            'selected object is feature class
            Debug.Print pSelGxObject.FullName
            Call SetMetadataElements(pSelGxObject)
           
        ElseIf pSelGxObject.Category = "SDE Feature Dataset" Then
            'selected object is feature dataset
            Set pGxObjContainer = pSelGxObject
            If pGxObjContainer.HasChildren Then
                Set pEnumGxObj = pGxObjContainer.Children
                If Not pEnumGxObj Is Nothing Then
                    Set pCurrGxObject = pEnumGxObj.Next
                    Do Until pCurrGxObject Is Nothing
                        If pCurrGxObject.Category = "SDE Feature Class" Then
                            Debug.Print pCurrGxObject.FullName
                            Call SetMetadataElements(pCurrGxObject)
                        End If
                        Set pCurrGxObject = pEnumGxObj.Next
                    Loop
                End If
            End If
        End If
        Set pSelGxObject = pEnumGxObjSel.Next
    Loop

End Sub

 

Public Sub SetMetadataElements(inGxObject As IGxObject)
   
    'declare variables
    Dim pMetadata As IMetadata
    Dim pMetadataPropertySet As IPropertySet
    Dim pMetadataXMLPropertySet2 As IXmlPropertySet2
    Dim sgidURL As String
    Dim sgidDisclaimer As String
    Set pMetadata = inGxObject 'Query Interface so we can get the name property of the featureclassname object        Set pMetadata = pFCName 'Query Interface so we can get the metadata property set
   
    'get metadata property set
    Set pMetadataPropertySet = pMetadata.Metadata
    Set pMetadataXMLPropertySet2 = pMetadataPropertySet ' QI
   
    sgidURL = "http://gis.utah.gov/sgid-vector-download/utah-sgid-vector-gis-data-layers-by-category"
    pMetadataXMLPropertySet2.SetPropertyX "idinfo/citation/citeinfo/onlink", _
               sgidURL, esriXPTLink, esriXSPAAddOrReplace, False
   
    sgidDisclaimer = "The Utah Automated Geographic Reference Center has adopted the following spatial data disclaimer to be explicitedly included or referenced in all geospatial data, mapping products, and services created or hosted at AGRC including the contents of State Geographic Information Database (SGID)." & vbNewLine & vbNewLine & _
                     "'This product is for informational purposes and may not have been prepared for, or be suitable for legal, engineering, or surveying purposes. Users of this information should review or consult the primary data and information sources to ascertain the usability of the information. AGRC provides these data in good faith and shall in no event be liable for any incorrect results, any lost profits and special, indirect or consequential damages to any party, arising out of or in connection with the use or the inability to use the data hereon or the services provided. AGRC shall not be held liable for any third party's interpretation of data provided by AGRC. AGRC provides these data and services as a convenience to the public. Furthermore, AGRC reserves the right to change or revise published data and/or these services at any time.'" & vbNewLine & vbNewLine & _
                     "Furthermore, it is the official policy of the AGRC:" & vbNewLine & vbNewLine & _
                     "    - that the adopted disclaimer be used on all hard copy maps produced from geospatial data, and that the date and source of the data be included on the map;" & vbNewLine & vbNewLine & _
                     "    - that spatial data producers be allowed to extend the adopted disclaimer with additional language further defining the limits of their liability;" & vbNewLine & vbNewLine & _
                     "    - that a more robust disclaimer may be used in conjunction with any and all geospatial data published on the Internet, on a separate page preceding access to the data, with an accept/reject option for users;" & vbNewLine & vbNewLine & _
                     "    - that standardized metadata be included with any distribution of all geospatial data; and" & vbNewLine & vbNewLine & _
                     "    - that the disclaimer above may be used as a blanket disclaimer for documents containing a number of small maps." & vbNewLine
    pMetadataXMLPropertySet2.SetPropertyX "idinfo/useconst", _
               sgidDisclaimer, esriXPTText, esriXSPAAddOrReplace, False
       
       
    pMetadataXMLPropertySet2.SetPropertyX "distinfo/distrib/cntinfo/cntaddr/addrtype", "physical", esriXPTText, esriXSPAAddOrReplace, False
    pMetadataXMLPropertySet2.SetPropertyX "distinfo/distrib/cntinfo/cntaddr/address", "1 State Office Building, Room 5130", esriXPTText, esriXSPAAddOrReplace, False
    pMetadataXMLPropertySet2.SetPropertyX "distinfo/distrib/cntinfo/cntaddr/city", "Salt Lake City", esriXPTText, esriXSPAAddOrReplace, False
    pMetadataXMLPropertySet2.SetPropertyX "distinfo/distrib/cntinfo/cntaddr/state", "UT", esriXPTText, esriXSPAAddOrReplace, False
    pMetadataXMLPropertySet2.SetPropertyX "distinfo/distrib/cntinfo/cntaddr/postal", "84114", esriXPTText, esriXSPAAddOrReplace, False
    pMetadataXMLPropertySet2.SetPropertyX "distinfo/distrib/cntinfo/cntaddr/country", "USA", esriXPTText, esriXSPAAddOrReplace, False
    pMetadataXMLPropertySet2.SetPropertyX "distinfo/distrib/cntinfo/cntvoice", "801.538.3665", esriXPTText, esriXSPAAddOrReplace, False
    pMetadataXMLPropertySet2.SetPropertyX "distinfo/distrib/cntinfo/cntfax", "801.538.3317", esriXPTText, esriXSPAAddOrReplace, False
    pMetadataXMLPropertySet2.SetPropertyX "distinfo/distrib/cntinfo/cntemail", " This e-mail address is being protected from spam bots, you need JavaScript enabled to view it ", esriXPTText, esriXSPAAddOrReplace, False
    pMetadataXMLPropertySet2.SetPropertyX "distinfo/distrib/cntinfo/cntorgp/cntorg", "Utah Automated Geographic Reference Center (AGRC)", esriXPTText, esriXSPAAddOrReplace, False
    pMetadataXMLPropertySet2.SetPropertyX "distinfo/distrib/cntinfo/cntorgp/cntper", "", esriXPTText, esriXSPAAddOrReplace, False
    pMetadataXMLPropertySet2.SetPropertyX "distinfo/distrib/cntinfo/hours", "Mon - Thurs 7am - 6pm, Closed Fridays", esriXPTText, esriXSPAAddOrReplace, False
       
     
    'example for using a custom thumbnail, picture must prexist on drive space...maybe export it from ArcMap?
    'pMetadataPropertySet.SetPropertyX "Binary/Thumbnail/Data", _
        LoadPicture("C:/muni.gif"), esriXPTPicture, esriXSPAAddOrReplace, False
       
    pMetadata.Metadata = pMetadataPropertySet

End Sub

 


Users' Comments  
 

Display 2 of 2 comments

1. Tue, 02-10-2009 at 10:44 AM

Bert, 
 
This is great stuff and works really well for us. My question is how can you edit meta data in the mxd file itself. We change the metadata within the .mxd file and currently use MS word to change the XML document, can you think of a more elegant solution. 
 
 
Is there anyway to easily find out which stylesheet formats display what property data. 
 
Many Thanks, 
 
Oliver

2. Thu, 09-03-2009 at 05:32 PM

This script works great. The only thing that was confusing for me was editing metadata elements where there is more than one element. For example attribute definitions all can be found at the  
"eainfo/detailed/attr/attrdef" path, so if you use the SetPropertyX method to set definition values it will change all of the definition values to the same text if you pass "eainfo/detailed/attr/attrdef" . After getting into it a little more I figured out how to interate through each attribute and give them specific definitions. In order to delve into multiple elements you have to add a numeric qualifier in the XML path: "eainfo/detailed/attr[1]/ attrdef" (this would give you the definition of the first field and so on). I use the code below to set specific values for each attribute field: 
'***************************** ****************************** ************ 
'Go through attributes definitions and change the values 
 
Dim XSLPath As String 
Dim XSLPath2 As String 
Dim Count As Integer 
XSLPath = "eainfo/detailed/attr[" & CStr(Count) & "]/attrlabl" 
XSLPath2 = "eainfo/detailed/attr[" & CStr(Count) & "]/attrdef" 
FieldName = pMetadataXMLPropertySet2.Simpl eGetProperty(XSLPath) 
'***************************** ****************************** ***************** 
Do Until FieldName = "" 
 
XSLPath = "eainfo/detailed/attr[" & CStr(Count) & "]/attrlabl" 
XSLPath2 = "eainfo/detailed/attr[" & CStr(Count) & "]/attrdef" 
 
Count = Count + 1 
FieldName = pMetadataXMLPropertySet2.Simpl eGetProperty(XSLPath) 
 
If FieldName = "nameofthefield" Then 
pMetadataXMLPropertySet2.SetPr opertyX XSLPath2, "insert definition here", esriXPTText, esriXSPAAddOrReplace, False 
End If 
' Use other if-then statements to set the attribute defintion of other fields 
pMetadata.Metadata = pMetadataPropertySet 
 
Loop

Display 2 of 2 comments

Add your comment

22, Sep. 2008
Last Updated ( 22, Sep. 2008 )
 
< Prev   Next >

AGRC Contacts | UGIC Contacts

feed image feed image

Utah GIS Portal © 2009 AGRC

Optimized for