Passing a variable in Python to Update Feature

208
1
Jump to solution
11-12-2021 03:33 PM
MeleKoneya
Regular Contributor

I am trying to update features in an AGOL feature layer  in Python.   

I am looping through some Json returning routers and then want to update the feature that matches the router ID

The example works below, but I can't figure out how to change  router_feature = [f for f in router_features if f.attributes['id']==557159][0] to use a variable.

In the same vein,   I need to update the geometry and setting a point works, but again I need to put in the new location values from the Json for x,y

pt = Point({"x" : -111.93345, "y" : 33.59674,
"spatialReference" : {"wkid" : 4326}}) 

 

search_result = gis.content.search('title:my Routers')
router_item = search_result[0]
search_result[0]

router_item = search_result[0]
print (router_item)
router_layers = router_item.layers
router_layers

router_fset = router_layers[0].query()

router_features = router_fset.features

router_flayer = router_layers[0]
router_flayer.properties.capabilities

router_feature = [f for f in router_features if f.attributes['id']==557159][0]
router_feature.attributes

route_edit = router_feature


pt = Point({"x" : -111.93345, "y" : 33.59674,
"spatialReference" : {"wkid" : 4326}})

router_feature.geometry = pt

display(route_edit)
update_result = router_flayer.edit_features(updates=[route_edit])
update_result

 Thanks for any help

Mele

0 Kudos
1 Solution

Accepted Solutions
MeleKoneya
Regular Contributor

I found a solution router_feature = [f for f in router_features if f.attributes['id']== + id][0]

pt = Point({"x" : longitude, "y" : latitude,
"spatialReference" : {"wkid" : 4326}})

View solution in original post

0 Kudos
1 Reply
MeleKoneya
Regular Contributor

I found a solution router_feature = [f for f in router_features if f.attributes['id']== + id][0]

pt = Point({"x" : longitude, "y" : latitude,
"spatialReference" : {"wkid" : 4326}})

0 Kudos