Skip to content
This repository has been archived by the owner on Mar 31, 2020. It is now read-only.

using updateFeatures to update attributes from dictionary #42

Closed
DShokes opened this issue Apr 2, 2015 · 1 comment
Closed

using updateFeatures to update attributes from dictionary #42

DShokes opened this issue Apr 2, 2015 · 1 comment
Labels

Comments

@DShokes
Copy link
Contributor

DShokes commented Apr 2, 2015

I can update features from the updateFeatures REST page with the following:

/* This is a valid updateFeatures parameter */
[{"attributes" : {"OBJECTID": 3325, "Name" : null}},
{"attributes" : {"OBJECTID": 152504, "Name" : "Joe Smith"}}]

ArcREST's layer function to updateFeatures only appears to update from fully built feature objects. No error is thrown when the features parameter only contains attributes. updateFeatures succeeds but only returns {'updateResults': []} instead of {'updateResults': [{'objectId': 3325, 'globalId': None, 'success': True}, {'objectId': 152504, 'globalId': None, 'success': True}]}

Here is my workaround, but it would be nice to allow attribute updates from the function:

"""
dict1 - is a dictionary of hosted features. Values have been changed to match a different data source.
list_CustomerIDs -  is a list. It lists the dict1 keys which are used to update specific features
attributes - is a list of dicts of individual feature attribute updates
"""
attributes = [{"attributes":{"OBJECTID":dict1[key][4],"Name":dict1[key][0],"CustomerID":dict1[key][1],"Address":dict1[key][3]}} for key in list_CustomerIDs]
# setup initial params dict
params = {"f" : "json", "rollbackOnFailure" : True}
result = None
 # There should be a check here to make sure the attributes has at least the feature layer OID or GlobalID
if len(attributes) > 0:
        #add features key:values
        # using json dumps here change syntax from python to json (None to null, escape special characters, etc...)
        params['features'] = json.dumps(attributes)
        params['token'] = fl._token
        uurl= fl.url + "/updateFeatures"
        result = fl._do_post(url=uurl, param_dict=params, proxy_port=fl._proxy_port, proxy_url=fl._proxy_url)
        print result
        # {'updateResults': [{'objectId': 152504, 'globalId': None, 'success': True}, {'objectId': 3325, 'globalId': None, 'success': True}]}

It would be nice to just call:

fl.updateFeatures(attributes)

My code above is a little too workflow specific, but updateFeatures could take a list of dicts of field:attribute like:

attributeUpdates = [{"OBJECTID":3325,"Name":None},{"OBJECTID":152504,"Name":"Jeff's Grocery Store"}]
#build features param for post
params['features'] =[{"attributes":{fields:values for fields,values in row.iteritems()} for fields,values in row.iteritems()} for row in attributeUpdates]
#Results in [{'attributes': {'Name': None, 'OBJECTID': 3325}}, {'attributes': {'Name': "Jeff's Grocery Store", 'OBJECTID': 152504}}]

Hope this is useful

@achapkowski
Copy link
Collaborator

Thank you for the suggestion. We will consider it for the next major release, but at this time, we will not add this feature. I am going to go ahead and close this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants