Parameters for Downloading Feature Layer Metadata?

513
1
07-12-2021 09:15 AM
GB_MattPanunto_GISS
Occasional Contributor II

Trying to download a metadata xml file from a feature layer (not to be confused with a feature service).

 

I'm having a hard time figuring out how to specify an output directory or path for the downloaded file. Looking at the documentation, it seems to accept a string parameter, but I only get errors when I feed it either an output directory, or a full file path. 

GB_MattPanunto_GISS_1-1626105911633.png

 

If I don't specify anything, it just downloads the xml to a temp folder. Am I doing something wrong?

0 Kudos
1 Reply
HamishMorton
Esri Contributor

Hi,

Perhaps a slightly long-winded aproach, but the following may solve your issue.

from arcgis.gis import GIS
import xml.etree.ElementTree as ET

gis = GIS("<url>", "<username>", "<password>")
item = gis.content.get("<itemID>")
layer = item.layers[0]

if layer.properties["hasMetadata"]:
    
    ET.register_namespace("", "http://www.isotc211.org/2005/gmd")
    ET.register_namespace("gco", "http://www.isotc211.org/2005/gco")
    ET.register_namespace("gts", "http://www.isotc211.org/2005/gts")
    ET.register_namespace("srv", "http://www.isotc211.org/2005/srv")
    ET.register_namespace("gml", "http://www.opengis.net/gml")
    ET.register_namespace("gmx", "http://www.isotc211.org/2005/gmx")
    ET.register_namespace("xlink", "http://www.w3.org/1999/xlink")
    ET.register_namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance")
    
    # Parse  document
    tree = ET.parse(layer.metadata)
    
    # Write file
    tree.write("/path/to/output/file.xml")

Unfortunately I couldnt get the method that you are trying to use to work either.

Hamish
0 Kudos