Hello everyone,
Anyone can recommend samples of Python source code updating hosted feature layers?
Thanks
Jose
If you're looking to append then give this a try...
import arcgis
# Set the URL of your ArcGIS Online organizationportal_url = "https://www.arcgis.com/"
# Set the credentials for your ArcGIS Online accountusername = "<username>"password = "<password>"
# Set the ID of the feature service you want to updateservice_id = "<service_id>"
# Set the name of the feature class in your geodatabase that you want to update the service withfc_name = "<feature_class_name>"
# Connect to your ArcGIS Online organizationgis = arcgis.gis.GIS(portal_url, username, password)
# Get the feature servicefeature_service = arcgis.features.FeatureLayerCollection.fromitem(gis.content.get(service_id))
# Get the feature layer from the feature servicefeature_layer = feature_service.layers[0]
# Get the feature class from the geodatabasefeature_class = arcgis.features.FeatureSet.from_featureclass(fc_name)
# Update the feature service with the feature setfeature_layer.edit_features(updates=feature_class)
# Disconnect from the ArcGIS Online organizationgis = None
Thanks @avonmoos
In my case I am getting a feature class with new records that have to be append to the hosted feature class.
Does this line append the hosted feature with records?
# Use the feature set to update the feature layer
layer.edit_features(updates=feature_set)
import arcgisfrom arcgis.gis import GIS
# Connect to your ArcGIS Online organizationgis = GIS("https://www.arcgis.com", "username", "password")
# Get the feature layer you want to updatelayer = gis.content.get("feature_layer_item_id").layers[0]
# Create a feature set object containing the features you want to updatefeature_set = arcgis.features.FeatureSet.from_csv("path_to_csv_file")
# Use the feature set to update the feature layerlayer.edit_features(updates=feature_set)
print("Feature layer updated successfully!")
Thank you Jacob!
There's plenty of documentation, like here: https://developers.arcgis.com/python/guide/appending-features/
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.