|
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: - 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
- 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: - Open ArcCatalog's VBA Editor from the Tools --> Macros -->Visual Basic Editor and open the Project Explorer window from the View menu.
- 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.
- Customize the pMetadataXMLPropertySet2.SetPropertyX statements to use and set values for metadata elements you want to chang
- 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!!!
- 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 |