6

I am working on a python script to create some feature classes from dbf tables. As part of the script I would like to pull two values (FGDC "publication date" and ArcGIS Spatial Reference ArcGIS Coordiante System "Projection") from the metadata of a linear referencing feature class and write them to a field in the feature class. I've looked at some of the modules that parse .xml files, but the linear referencing feature class doesn't have a standalone .xml. Below is the part of the script where i'd like to pull and calculate the values.

#Pull COORDSYS and MAPVERSION from RCI Metadata

    #Calculate Values for Coordsys, Mapsource, MapVersion, publish date, CAR xfer date, coord xfer date
    today = datetime.date.today()
    pub_date = today.strftime("%m/%d/%y")
    arcpy.CalculateField_management(input,"COORDSYS",XXX,"PYTHON_9.3")
    arcpy.CalculateField_management(input,"MAPSOURCE",mapsource_ON,"PYTHON_9.3")
    arcpy.CalculateField_management(input,"MAPVERSION",XXX,"PYTHON_9.3")
    arcpy.CalculateField_management(input,"DTPUBLISHE",pub_date,"PYTHON_9.3")
    arcpy.CalculateField_management(input,"DTCARXTRCT",pulldate,"PYTHON_9.3")
    arcpy.CalculateField_management(input,"DTCOORDXTR",pub_date,"PYTHON_9.3")

2 Answers 2

4

is creating a standalone .xml file for the feature class an option? ... for instance a temporary XML, which you delete extracting the information you need?

If yes, you might want to look into the arcpy command "XSLTransform_conversion". To get acquainted with it, look into ArcToolbox: Conversion Tools > Metadata toolset. The arcpy command only calls this tool.

Essentially, this tool allows you to convert metadata from a format to another. In your case, you could expose the feature class metadata into a XML file using the tool's parameter "XSL sheet" called "exact copy of". These XSL sheets are available in your ArcGIS install folder, under ..\Metadata\Stylesheets\gpTools. As it says, this particular XSL sheet will make NO modification to the contents on the feature class metadata, it will only export it into a XML file.

ESRI help on this tool is available here, and here is further help on the metadata toolset.

1
  • ... plus you probably want to "synchronise" your feature class metadata if the feature class does not have any metadata : the "synchronize metadata" tool populates the metadata fields with the data properties (such as the coordinate system, bounding box, list of attribute fields, etc.). This tools is located in the same toolbox as above, and is also available via arcpy.
    – Hélène
    Commented Dec 23, 2014 at 16:23
4

Here is the code that finally did the trick. This is the same method proposed by Helene above. Any comments on how to improve this are welcome.

    #Create XML from RCI Basemap Metadata
    translator = "C:\Program Files (x86)\ArcGIS\Desktop10.2\Metadata\Translator\ARCGIS2FGDC.xml"
    arcpy.ExportMetadata_conversion(roads,translator,arcpy.env.workspace+"\\"+"roads_Export.xml")

    #Get MAPVERSION from RCI Basemap
    from xml.etree.ElementTree import ElementTree
    from xml.etree.ElementTree import Element, SubElement

    xmlfile = arcpy.env.workspace+"\\"+"roads_Export.xml"

    tree = ElementTree()
    tree.parse(xmlfile)

    spot = tree.find("idinfo/citation/citeinfo/pubdate")
    pub_date = spot.text

    year = pub_date[0:4]
    month = pub_date[4:6]
    month_num = int(month)

    if 0 < month_num < 3:
        version = year+"Q1"
    elif 3 < month_num < 6:
        version = year+"Q2"
    elif 6 < month_num < 9:
        version = year+"Q3"
    elif 9 < month_num < 12:
        version = year+"Q4"

    #Calculate Values for Coordsys, Mapsource, MapVersion, publish date, CAR xfer date, coord xfer date

    arcpy.CalculateField_management(input,"MAPVERSION",'"{0}"'.format(version),"PYTHON")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.