Add new Feature Layer to an existing Collection

137
2
11-30-2020 01:22 PM
New Contributor II

I want to add a new Feature Layer to an existing Feature Layer Collection (FLC) that I am already successfully overwriting daily using code like: 

 

feature_layer_collection = FeatureLayerCollection.fromitem(dataitem) 
feature_layer_collection.manager.overwrite(zipped_gdb)

 

However, this requires that the new zipped gdb contain the exact structure of Feature Layers as the existing FLC being overwritten. How do I add a new layer into the FLC so that upon the next overwrite which includes the additional Feature Layer, it won't result in an error?

This FLC contains 6 Feature Layers that are being used in published maps, so I do not want to simply create a new FLC with the additional layer since I would then have to reconfigure all the published maps.  

Reply
0 Kudos
2 Replies
Esri Contributor

Hi Rich,

Try using the Add to Definition method to add an additional feature layer to your hosted feature service: https://developers.arcgis.com/python/api-reference/arcgis.features.managers.html?highlight=add%20def...

Does this have what you need?

-Calvin

Reply
0 Kudos
Esri Contributor

Hi @RichThomas2 ,

If you do a truncate on the feature layer first then overwrite the feature layer collection, it should work.

 

from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection
gis = GIS("url", "username", "password")

# get the feature layer
flc_item = gis.content.get("item_id")
fLyr = flc_item.layers[0]
fLyr.manager.truncate()

# get the gdb item
gdb_item = gis.content.get("gdb_item_id")

feature_layer_collection = FeatureLayerCollection.fromitem(flc_item)
feature_layer_collection.manager.overwrite(gdb_item)

 

MehdiPira1_0-1606961698497.png

I hope that helps.

 

Reply
0 Kudos