AnsweredAssumed Answered

Way to publish by addition to AGOL, an alternative to overwrite?

Question asked by pedgls on Aug 18, 2020

Question

Is it possible to script adding a new layer from an ArcGIS Pro project to a hosted feature service on AGOL, rather than overwriting?

 

e.g. desired scenario:

*I have an AGOL hosted feature service with a layer called: "2007"

*In ArcGIS Pro I have another layer "2008". I want to add this layer to the above service.

 

Currently, I am using the arcgis.gis module and the "publish" function to overwrite the whole hosted feature service, however, I am looking for an alternative that is more efficient for large services.

 

Platform:

ArcGIS Pro 2.4

Python 3

Windows Server 2016

ArcGIS 10.8

AGOL

 

Dead ends I explored:

1) "append"

documentation: https://developers.arcgis.com/python/guide/appending-features/

Reason rejected:

The feature layer collection's append function is for appending from a file geodatabase, or CSV or excel file. I am not seeing a good way to pull from the current Pro project's map itself. Also, it appears to append to an existing feature layer, not add a new layer to the data set.

 

 

2) GeoAnalytics' append

documentation: https://enterprise.arcgis.com/en/portal/latest/use/geoanalytics-append-data.htm

Reason rejected:

The GeoAnalytics append is for adding data to an existing layer, not a new layer to an existing dataset.

 

3) add_to_definition

documentation: https://developers.arcgis.com/python/api-reference/arcgis.features.managers.html

Reason rejected: Incompatible json.

I used this in conjunction with FeaturesToJson to convert my Pro project's layer 2008 into json, but it doesn't appear to be compatible:

FeaturesToJson:

https://desktop.arcgis.com/en/arcmap/latest/tools/conversion-toolbox/features-to-json.htm

 

sample code I used:

...

proj = arcpy.mp.ArcGISProject(projPath)

map = proj.listMaps()[0]

layer2008 = map.listLayers()[-2]

...

searchResultsFlc = gis.content.search("title:" + serviceName, item_type="Feature Layer Collection")
flcItem = searchResultsFlc[0]
flcol = arcgis.features.FeatureLayerCollection(flcItem.url, gis)

arcpy.conversion.FeaturesToJSON(layer2008, "layer2008.json")
<Result 'layer2008.json'>

 

flcol.manager.add_to_definition("layer2008.json")
Unable to add feature service definition.
Invalid definition for ESRI.ArcGIS.SDS.Metadata.FeatureServiceDescriptor
"layer2008.json"

 

4) addDefinition, web api:
documentation: https://developers.arcgis.com/rest/services-reference/add-to-definition-feature-service-.htm

Reason rejected: incompatible json

The json generated by FeaturesToJSON is incompatible with the sample json posted in the documentation.

 

 

-Pete

Outcomes