I have a point feature class in a geodatabase. It doesn't contain metadata yet. I want to write one for it. I think I need to use XML Templater. But I can't read directly from GDB by adding a Esri GDB reader. what should my source be?
I have a point feature class in a geodatabase. It doesn't contain metadata yet. I want to write one for it. I think I need to use XML Templater. But I can't read directly from GDB by adding a Esri GDB reader. what should my source be?
A couple ways to go about this since this is metadata for an ESRI point feature class in a geodatabase. One option would be to read in the geodatabase metadata by setting the geodatabase reader parameter to – Feature Read Mode – to 'Metadata'. Safe have a couple good articles and demos on how to go about this.
Also see: FME and Metadata
Another option is to basically save out the current metadata of the feature class as an XML using say ArcGISPRO - python and then read that into your FME workspace using a XML reader and start creating the metadata from that. Once you are done, you can copy the metadata XML back onto the feature class using the same basic python commands.
Example for save and export to XML python function:
import arcpy
from arcpy import metadata as md
##feel free to adjust the function for your needs
def update_sync_saveOut(source, export_location):
'''An automated way to upgrade, synchronize,
and saveAs - All Content for a feature class.
This function serves the basis of this automation and follows the ESRI
step-by-step process to perform these actions in ArcGIS PRO. Takes a source metadata
location (feature class path) and then a xml file export location.
Uses: src_item_md.saveAsXML(export_location, EXACT_COPY)
'''
text = ''
text +='##################\n'
text += str(source)+'\n'
text += str(export_location)+'\n'
#
#Metadata
src_item_md = md.Metadata(source)
try:
#Upgrade
src_item_md.upgrade('FGDC_CSDGM')
text += 'Upgraded metadata for {}\n'.format(source)
except:
text += 'Upgrade not needed for {}\n'.format(source)
try:
#synchronize
src_item_md.synchronize('ALWAYS')
text += 'Synchronized\n'
# Save
src_item_md.saveAsXML(export_location, 'EXACT_COPY')
text += 'Saved out successfully.\n'
except:
text +=arcpy.GetMessages(0)
#
text +=arcpy.GetMessages(0)+'\n'
return text
Once your metadata xml has been updated through FME and written back out. You could use the following commands to save it back to the feature class.
import arcpy
from arcpy import metadata as md
# scratch = new updated xml with the new metadata
# export_path = where the metadata should be saved to; feature class
def xml_import_save(scratch, export_path):
text = ''
#Import the metadata into export_path (ArcPro)
src_template_md = md.Metadata(scratch)
tgt_item_md = md.Metadata(export_path)
tgt_item_md.copy(src_template_md)
tgt_item_md.save()
#
text += 'Md copied and saved successfully.\n'
text +=arcpy.GetMessages(0)+'\n'
return text