Add new Feature Layer to an existing Collection

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) 


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.  

0 Kudos
2 Replies
by Anonymous User
Not applicable

Hi Rich,

Try using the Add to Definition method to add an additional feature layer to your hosted feature service:

Does this have what you need?


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]

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

feature_layer_collection = FeatureLayerCollection.fromitem(flc_item)



I hope that helps.


0 Kudos