Hi,
I'm seeking assistance to update my hosted feature layer titled "Stands_nd_statistics" using a zipped shapefile. My objective is to both update existing features with new data and add new features where necessary. I've attempted to achieve this using the append operation in ArcGIS Python API, but I encountered an Unknown Error with error code 500.
import arcpy, os, json, zipfile
from arcgis.gis import GIS
from arcgis import features
from arcgis.mapping import WebMap
from arcgis.features import FeatureLayerCollection
from arcgis.features import FeatureLayergis = GIS("https://www.arcgis.com", "username", "password")
search_result = gis.content.search("title:Stands_nd_statistics", item_type = "Feature Layer")
layer_item = search_result[0]
feature_layer = FeatureLayer(layer_item.url)# Upload the zipped shapefile as an item to your GIS
zip_path = r"P:\Projects\Stands_nd_statistics.zip"
shapefile_item = gis.content.add({'title': 'Stands_nd_statistics_upload','type': 'Shapefile'}, data=zip_path)feature_layer.append(item_id=shapefile_item.id, upload_format="shapefile", upsert=False)
Exception: Unknown Error
Any guidance or insights on how to troubleshoot and resolve this issue would be greatly appreciated! Thank you.
I'm seeing the same type of error as I posted here :
It looks like it could be a file size issue but I don't see anywhere in the updated documentation how to get around it.
Here's an idea. Load that shapefile into a spatial dataframe.
sdf = pd.DataFrame.spatial.from_featureclass("path\to\your\data\census_example\cities.shp")
Then append like this instead:
adds = sdf.spatial.to_featureset()
feature_layer.edit_features(adds=adds)
@LienPham1 have you tried executing ArcGIS Pro's Append tool? This provides an upsert option which will update existing features with new data and add new features. To use the upsert option, make sure the field your using in the hosted feature service has a unique index: