Select to view content in your preferred language

How to populate metadata title from alias name of feature class?

1116
2
01-02-2018 08:02 AM
StefanOffermann
Deactivated User

I have a SDE with a lot of feature classes. I want to populate the metadata of the feature classes mostly automatic. Can I update the metadata title of all feature classes by using the alias name of the feature class? I have used the geoprocessing tool "Synchronize Metadata", it is useful for bounding box, spatial reference, etc. but it wont update the metadata title.

Tags (1)
2 Replies
curtvprice
MVP Esteemed Contributor

I'm fairly certain this would require some scripting to edit the metadata record, either using the metadata toolkit or exporting to XML and and editing with python tools and re-importing. Would really like to see some arcpy functionality to edit the main item/description components easily! Please vote the idea up!

https://community.esri.com/ideas/4618

StefanOffermann
Deactivated User

So I made a python script for automatic updates of all feature classes in a geodatabase (also in feature datasets), my be this is helpful to others.

import arcpy
import codecs
import os
import xml.dom.minidom

workspace = r'C:\data\geodatabase.gdb' # or path to sde-file
temporaryXmlFile = r'C:\temp\xmlMetadataTransferFile.xml'

def getAlias(featureClass):
    return arcpy.Describe(featureClass).aliasName

def createTemporaryXmlMetadataFile():
    with open(temporaryXmlFile, 'w') as theFile:
        theFile.write('<metadata />')

def writeAliasToTemporaryXmlMetadataFile(alias):
    xmlFile = open(temporaryXmlFile)
    dom = xml.dom.minidom.parse(xmlFile)
    titles = dom.getElementsByTagName("resTitle")
    for title in titles:
        title.firstChild.data = alias
        title.setAttribute('Sync', 'FALSE')
        with codecs.open(temporaryXmlFile, 'w', 'utf-8') as file2:
            dom.writexml(file2)
    
def doUpdate(path):
    arcpy.env.workspace = path
    fcList = arcpy.ListFeatureClasses()
    if fcList is None:
        print '- WARN: No feature classes found'
        return
    for fc in fcList:
        print '- Feature class: ' + fc
        alias = getAlias(fc)
        print '  Alias: ' + alias
        createTemporaryXmlMetadataFile()
        arcpy.SynchronizeMetadata_conversion(fc, "ALWAYS")
        arcpy.MetadataImporter_conversion(fc, temporaryXmlFile)
        writeAliasToTemporaryXmlMetadataFile(alias)
        arcpy.MetadataImporter_conversion(temporaryXmlFile, fc)
        arcpy.SynchronizeMetadata_conversion(fc, "ALWAYS")

print 'Set resource title to alias name of all feature classes'
doUpdate(workspace)
fdsList = arcpy.ListDatasets("*", "Feature")
if fdsList is None:
    print '- WARN: No feature datasets found'
else:
    for fds in fdsList:
        print 'Feature dataset: ' + fds
        path = os.path.join(workspace, fds)
        doUpdate(path)
                
print 'done.'
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍