I am trying to update point geometry from an outside data set. I can update all the other data and can successfully create new points with the correct geometry but when I try to update the geometry of an existing point the data layer does not update its location. The pre and post geometry tags are updated correctly but when I requery the point it still has the old geometry.
Solved! Go to Solution.
There's your problem, your geometry is nested in a list in the second case.
Edit: geometry.project() is returning a list with a single geometry, and your code is handling it as if it were just a geometry.
Is this an AGOL hosted feature layer? You very well may have already done this, but from the item page's Settings make sure to check two things:
I appreciate the response. I had already made sure those were checked and the layer is checked. I had done that when I created the layer since we do allow our field staff to update the layer through the Web Map App. Thanks again for responding I appreciate any help I can get.
Can you print gwp_f to the console to see what it looks like immediately before you call edit_features()? Not looking for anything in particular, but if it's structured in a weird way that might cause the update to be a no-op.
Here is a console shot of the pre, the geo and the post. It shows it changed but doesn't push the geo to AGOL. If I update any of the other fields it will push those to AGOL.
Pre gwp_f {"geometry": {"x": -11734292.3359, "y": 4841408.441699997, "spatialReference": {"wkid": 102100, "latestWkid": 3857}}, "attributes": {"FID": 6762, "buildingID": 1575, "UTMX": 464835.62, "UTMY": 4409076.96, "UTMZone": "13", "UTMDatum": "NAD 83", "Status": "IN-SERVICE", "Record": "YES", "Method": "CONSULTANT", "CreatedBy": "PotterG", "CreatedDat": 1521612000000, "ModifiedBy": "PotterG", "ModifiedDa": 1678860000000, "Title": "Bandimere Cabin", "GUIDID": " ", "URL": "http:// ", "POINT_X": -105.410941666, "POINT_Y": 39.830963216, "GlobalID": "{9952BC6F-69D7-4FC0-8A07-432249E937EF}", "RMID": "NRPO4274", "GlobalID_2": "94584ada-21d5-499d-bda1-b78e0c185757", "Latitude": "39\u00b049'51.47\" N", "Longitude": "105\u00b024'39.39\" W", "End_Date": null, "Begin_Date": -2208988800000, "AssetID": "B1575", "F_": null, "AssetSubType": "Bunkhouse"}}
Geo: [{'x': -11734292.350298584, 'y': 4841408.633804429, 'spatialReference': {'wkid': 102100, 'latestWkid': 3857}}]
Post gwp_f {"geometry": [{"x": -11734292.350298584, "y": 4841408.633804429, "spatialReference": {"wkid": 102100, "latestWkid": 3857}}], "attributes": {"FID": 6762, "buildingID": 1575, "UTMX": 464835.62, "UTMY": 4409076.96, "UTMZone": 13.0, "UTMDatum": "NAD 83", "Status": "IN-SERVICE", "Record": "YES", "Method": "CONSULTANT", "CreatedBy": "PotterG", "CreatedDat": 1521612000000, "ModifiedBy": "PotterG", "ModifiedDa": 1678860000000, "Title": "Bandimere Cabin", "GUIDID": " ", "URL": "http:// ", "POINT_X": -105.410941666, "POINT_Y": 39.830963216, "GlobalID": "{9952BC6F-69D7-4FC0-8A07-432249E937EF}", "RMID": "NRPO4274", "GlobalID_2": "94584ada-21d5-499d-bda1-b78e0c185757", "Latitude": "39\u00b049'51.47\" N", "Longitude": "105\u00b024'39.39\" W", "End_Date": null, "Begin_Date": -2208988800000, "AssetID": "B1575", "F_": null, "AssetSubType": "Bunkhouse"}}
There's your problem, your geometry is nested in a list in the second case.
Edit: geometry.project() is returning a list with a single geometry, and your code is handling it as if it were just a geometry.
Thanks, changed it to
Hey,
Not sure if this will help you, but here's a simple example that works for me to update an existing point:
from arcgis import GIS
from arcgis.geometry import Point
from arcgis.features import FeatureLayer
gis = GIS("https://www.arcgis.com", "username", "password")
fl_url = url = "https://server.com/arcgis/rest/services/ex/FeatureServer/0"
fl = FeatureLayer(url, gis)
sdf = fl.query(as_df=True)
example_df = sdf.loc[sdf.OBJECTID==1].copy()[["OBJECTID", "SHAPE"]]
example_df.at[0, "SHAPE"] = Point({"x" : -118.15, "y" : 33.80, "spatialReference" : {"wkid" : 4326}})
update_fs = example_df.spatial.to_featureset()
fl.edit_features(updates=update_fs)
Thanks for helping. I was able to stay with my current code after MobiusSnake pointed out the error in my ways.