Update metadata for feature layer in hosted service?

3070
8
Jump to solution
10-03-2018 05:48 AM
LeonS
by
Occasional Contributor III

I have a hosted feature service in AGOL that I would like to overwrite the metadata from an xml file.  It can be done manually (as shown circled in red in image below). Is the ability to update the metadata for a layer exposed in the ArcGIS API for Python?

I'm able to update the item metadata (as shown in circled in blue), with this script:

gis = GIS(agol_url, agol_user, agol_pass)

myItem = gis.content.get(itemid)

myItem.update(metadata="C:\gis_scripts\myMetadata.xml")

However, the ability to update the layer level metadata is not as straightforward (or maybe not available).

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

OK, I understand now.  The short answer is no, the ArcGIS API for Python doesn't currently support updating XML metadata at the feature layer level.

I don't see this lack of support as an ArcGIS API for Python oversight but an ArcGIS REST API one.  The hasMetadata property for feature layers was only introduced in ArcGIS 10.6.1, and the URL that AGOL calls (https://<featurelayer-url>/metatdata/update) isn't documented yet in the ArcGIS REST API online documentation.  The ArcGIS API for Python team would be going out on a limb if they start implementing ArcGIS REST API functionality that isn't publicly documented.

View solution in original post

0 Kudos
8 Replies
JoshuaBixby
MVP Esteemed Contributor

See Update definition.   What is described is updating FeatureLayerCollection properties (a.k.a., metadata), but the same steps can be used to update FeatureLayer as well.

0 Kudos
LeonS
by
Occasional Contributor III

If I have metadata created for the FeatuerLayerCollection item, it seems I can set the metadata for a FeatureLayer to use that metadata using the Update Defintion method.

update_dict = {'metadata':'metadata.xml'}
myLayer.manager.update_definition(update_dict)

However, I'm unable to find a method to upload and update the metadata for a FeatureLayer.  I would like to upload metadata for each of the layers in my Feature Service, if I happen to have more than one.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

It can be confusing because the AGOL/Portal web interface and REST API terminology don't always line up cleanly.  For example, what users see labeled as a Feature Layer is really a Feature Service.  On the content page in AGOL/Portal, users will see both terms if they hover over the source type:

So, is it a Feature Layer, Feature Service, hosted Feature Layer in a Feature Service, or Feature Service-based hosted Feature Layer?

And if that isn't fun enough, the ArcGIS API for Python goes out and introduces something called a Feature Layer Collection, which doesn't exist in name in the REST API.

Just like the FeatureLayerCollection has a manager, so does each FeatureLayer.  In your two lines of code, does myLayer refer to a FeatureLayerCollection or a FeatureLayer?

LeonS
by
Occasional Contributor III

Agreed, the terminology can be a bit much.  Your screenshot sums it up! The "ArcGIS API for Python" is a mouthful in its own right! 

Yes, myLayer refers the FeatureLayer.  I should have been clearer.

gis = GIS(agol_url, agol_user, agol_pass)

myItem = gis.content.get(itemid)

myLayer = myItem.layers[0]

update_dict = {'metadata':'metadata.xml'}
myLayer.manager.update_definition(update_dict)

I don't see in the Feature Layer Manager a method for updating the metadata like you can for an Item using the update  method.  ( arcgis.gis module — arcgis 1.5.0 documentation )

It looks like I can update the properties that you see on the REST endpoint of the layer, but not the metadata associated with the layer.

Essentially, I want to automate the process of clicking the Metadata button (circled red in original post), clicking Overwrite on the metadata editor, selecting a local xml file  and saving.  It works for the Item metadata (blue circle).

0 Kudos
KhaledHassen
Esri Contributor

You can update the feature service xml layer metadata using the feature service API directly if needed.

You can use:

..../FeatureServer/0/metadata/update url to update but you will need to be the owner.

You will get a chance to directly pass the xml file as an uploadId or as an itemId. Pl. note using the API does not update the featureService Item xml metadata. It only update the layer xml metadata. You can do this for all the layers within your feature service.

To view the xml metadata, you can use .../FeatureService/0/metadata resource.

LeonS
by
Occasional Contributor III

Thanks for the info on accessing the metadata through the REST API.  I hadn't come across that.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

OK, I understand now.  The short answer is no, the ArcGIS API for Python doesn't currently support updating XML metadata at the feature layer level.

I don't see this lack of support as an ArcGIS API for Python oversight but an ArcGIS REST API one.  The hasMetadata property for feature layers was only introduced in ArcGIS 10.6.1, and the URL that AGOL calls (https://<featurelayer-url>/metatdata/update) isn't documented yet in the ArcGIS REST API online documentation.  The ArcGIS API for Python team would be going out on a limb if they start implementing ArcGIS REST API functionality that isn't publicly documented.

0 Kudos
LeonS
by
Occasional Contributor III

Thanks!  That is what I suspected regarding the ArcGIS API for Python.  I'm a little surprised its not documented in the REST API documentation.  I just spent 15 minutes looking for it; thinking how rusty I've gotten at navigating these API documentations.  So thanks for clarifying that too!

0 Kudos