Unable to get set_value to work when updating the attributes of a feature

1106
3
04-24-2017 03:54 PM
CharlieWare
New Contributor II

I'm trying to use the set_value function on a feature in a feature layer hosted on AGOL. The set_value function seems to work and does not return an error but when I query the feature service none of the features have the updated values.

I set up a layer:

dataSearch = gis.content.search("pointService", "feature service")
for layer in dataSearch[0].layers:
   if layer.properties.name == "pointService":
   pointLayer = layer

Then I get the feature set for that layer:

updateFeatures = pointLayer.query()

Then I try to set the values of some attributes:

for feature in updateFeatures.features
   feature.set_value('RegionID', 1)
   feature.set_value('RegionNm', "SouthEast")

The updated attributes show up when I use get_value()


print(str(feature.get_value('RegionNm')))

<SouthEast>

But when I query the feature service from the REST endpoint or download it as a shapefile, the attributes are empty. I have tried using the refresh() method on the feature layer manager but it had no effect. 

Tags (1)
0 Kudos
3 Replies
AtmaMani
Esri Contributor

It looks you are not pushing the changes you made in-memory. Can you try this: call the `edit_features()` method on your FeatureLayer object, pass the changes to the `updates` parameter and then try to query using either the REST endpoint or download as shapefile.

The workflow for editing is explained here https://developers.arcgis.com/python/guide/editing-features/#Updating-features

0 Kudos
CharlieWare
New Contributor II

Well that works - thanks. I also got it to work using the calculate() function on the feature layer. 

What is the intended use of the set_value() function? Is there a method to push changes from in_memory?

0 Kudos
AtmaMani
Esri Contributor

The set_value() is powerful in that, you can use it to safely set or update not only attribute values of a feature but also its geometry. If you constructed your geometry as a arcgis.geometry.Polyline object say, you can call the set_value('geometry', your_polyline_obj) and the API takes care of updating the geometry.

Still, the changes are local. You need to call the update() as discussed earlier if you want to push them to the server and persist.

0 Kudos