Still struggling a bit with the FeatureLayerManager class and when to useadd_to_defintion,updateDefinitionordelete_from_definition.
This time, I am trying to enable editing and editor tracking on a hosted feature service. I started by opening up the Chrome developer tools Network monitor, then on the Feature Layer settings page I manually checked the options 'Enable editing', 'Keep track of created and updated features' and 'Keep track of who created and last updated features', then hit Save. I then saw the console send an update_definition request.
I copied the form data and popped that into my update_definition method in my python notebook @ line 13
# Convert to a Spatially Enabled Dataframe sdf = pd.DataFrame.spatial.from_xy(df, "lon_y", "lat_x", sr=4326) print('Publishing layer...') item = sdf.spatial.to_featurelayer('myFeatureLayer', tags=["test"], folder="My Folder") print("Deleting interim fGDB...") interimGDB = gis.content.get(gis.content.search(query="title:myFeatureLayer", item_type="File Geodatabase")[0].id).delete() featureLayer = gis.content.get(item.id).layers[0] print("Enabling Change Tracking...") resp = featureLayer.manager.update_definition({ "hasStaticData":False, "capabilities": "Query, Editing, Create, Update, Delete, ChangeTracking", "editorTrackingInfo":{ "enableEditorTracking":True, "enableOwnershipAccessControl":False, "allowOthersToUpdate":True, "allowOthersToDelete":True, "allowOthersToQuery":True, "allowAnonymousToUpdate":True, "allowAnonymousToDelete":True} }) print(resp) print(featureLayer.properties)
Reviewing the properties/definition however, I noticed that under nothing in the definition actually was updated, other than 'hasStaticData' which was changed from False to True. 'ChangeTracking' is not listed as a capability and the editorTrackingInfo array is not present in the updated definition.
Solved!去解决方案。
Hi,
I noticed you're trying to enable editing on a FeatureLayer, but you want to be enabling it on the FeatureLayerCollection since it's a service-level property. Can you report back what happens when you update the flc?
The below works perfectly for me:
from arcgis import GIS from arcgis.features import eatureLayerCollection gis = GIS("https://www.arcgis.com", "username", "password") url = "https://your/server/url/FeatureServer" flc = FeatureLayerCollection(url, gis=gis) edit_dict = { "hasStaticData":False, "capabilities": "Query, Editing, Create, Update, Delete, ChangeTracking", "editorTrackingInfo":{ "enableEditorTracking":True, "enableOwnershipAccessControl":False, "allowOthersToUpdate":True, "allowOthersToDelete":True, "allowOthersToQuery":True, "allowAnonymousToUpdate":True, "allowAnonymousToDelete":True} } flc.manager.update_definition(edit_dict)
Hi,
I noticed you're trying to enable editing on a FeatureLayer, but you want to be enabling it on the FeatureLayerCollection since it's a service-level property. Can you report back what happens when you update the flc?
The below works perfectly for me:
from arcgis import GIS from arcgis.features import eatureLayerCollection gis = GIS("https://www.arcgis.com", "username", "password") url = "https://your/server/url/FeatureServer" flc = FeatureLayerCollection(url, gis=gis) edit_dict = { "hasStaticData":False, "capabilities": "Query, Editing, Create, Update, Delete, ChangeTracking", "editorTrackingInfo":{ "enableEditorTracking":True, "enableOwnershipAccessControl":False, "allowOthersToUpdate":True, "allowOthersToDelete":True, "allowOthersToQuery":True, "allowAnonymousToUpdate":True, "allowAnonymousToDelete":True} } flc.manager.update_definition(edit_dict)
Thank you so much@emedina! With your guidance, I was able to get it to work.
It's interesting, apparently the gis parameter on FeatureLayerCollection is not so optional. If I left it off, I would get errors, even though the GIS object is already instantiated in a previous cell.
The other thing I thought was unexpected was that simply using the featureLayer.url would not suffice because that resolves to the first layer in the collection (eg. .../FeatureServer/0), but it actually needs the Collection so I had to use featureLayer.container.url.