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.
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
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)
I hope that helps.