AnsweredAssumed Answered

How to extract metadata of feature classes and save it as a csv, using ISO19139 translator in ArcGIS environment ?

Question asked by saravanaganesh18 on Jan 5, 2017
Latest reply on Jan 11, 2017 by curtvprice

We are trying to extract the feature_classes metadata and save it as csv. With the help of this code we are extracting Abstract, Title, Purpose, Spatial Ref, Extent without any hiccups. But in addition to that we need "Lineage" info and i don't see any lineage info in xml files converted using "ARCGIS2FGDC.xml" translator. But lineage details are getting exported when ARCGIS2ISO19139.xml translator is used.

The problem is, i couldn't able to extract any of the details (Abstract, Lineage, Title etc..) from the output xml translated using ARCGIS2ISO19139.xml. This is the code i am using

import os
import arcpy
import csv
from xml.etree.ElementTree import ElementTree
from arcpy import env

arcpy.env.overwriteOutput = True

def inventory_data(workspace, datatypes):
    for path, path_names, data_names in arcpy.da.Walk(
            workspace, datatype=datatypes):
        for data_name in data_names:
            yield os.path.join(path, data_name)

AGSHOME = arcpy.GetInstallInfo("Desktop")["InstallDir"] 
translatorpath = AGSHOME + "Metadata\\Translator\\ARCGIS2ISO19139.xml"

#These two variables need to be updated each time this script is run on a new workspace
outfile = r"D:\QAQC\Metadata\GIS_Data_Inventory.csv"
xmlfile = r"D:\QAQC\Metadata\GIS_Data_Inventory.xml"

with open (outfile, 'wb') as csvfile:
    csvwriter = csv.writer(csvfile)
    #You need to update workspace in the line below
    for feature_class in inventory_data(r"D:\QAQC\Metadata\Test", "FeatureClass"):
            desc = arcpy.Describe(feature_class)
            sr = desc.spatialReference
            arcpy.ExportMetadata_conversion(feature_class, translatorpath, xmlfile) 
            tree = ElementTree() 
                title = tree.find ("identificationInfo/MD_DataIdentification/citation/CI_Citation/title").text
                title = "No Title"

                abstract = tree.find ("identificationInfo/MD_DataIdentification/abstract").text
                abstract = "No Abstract"

                lineage = tree.find ("dataQualityInfo/DQ_DataQuality/lineage/LI_Lineage/statement").text
                lineage = "No Lineage"

            csvwriter.writerow([desc.path.encode('utf-8'), desc.file.encode('utf-8'), desc.dataType.encode('utf-8'),'utf-8'), purpose.encode('utf-8'), title.encode('utf-8'), abstract.encode('utf-8')])

        except Exception:
            e = sys.exc_info()[1]
All i am getting in the output csv is "No Title, No Abstract, No Lineage". But the output xml file has these parameters (image attached below).