Run python script on feature layer

03-13-2017 11:48 AM
New Contributor II

I got a feature point layer running on a arcgis server 10.2 on Windows, I have added this layer to map and got the ID and put it into a Geoform schema hosted on the same machine as the arcgis server.

The geoform works flawless, and new points can be seen in my map.

After the geoform is filled out by the user only two fields are filled out (witch is the point) and then my python script would parse various .xml files from the web to fill out rest of the fields.

I made two different versions, one that would get the OBJECTID as input the run the script on that row, and one version that would look for the first empty row, and fill in the xml stuff.

But I cant figure out how to do any of the above, I did try to upload the script as a geoprosessing service, but no luck there either.

I tried to setup a scheduled task and pointed the python script to the local folder on the server (C:\arcgisserver\directories\arcgissystem\arcgisinput\obsPoint\obsPoint.MapServer\extracted\v101) but it seems to be locked by the server, and if I copy that database to my local computer the newly created points are missing.

Hope that someone can point me in the right direction!

0 Kudos
2 Replies
Esri Esteemed Contributor

Hi Oddbjorn,

You will want to use the ArcGIS REST API to update the feature server.  Take a look at the update features function:


0 Kudos
New Contributor II

Thanks, python code went from:

with arcpy.da.UpdateCursor(workspace, ("OBJECTID", "TIMEFROM"), expression) as cursor:
    for row in cursor:
        row[1] = timeFrom
        cursor.updateRow(row) ‍‍‍‍‍‍‍‍


import urllib, urllib2, json  
updateBaseURL = ""
updateAttr = [{"attributes" : {"OBJECTID": OID, "TIMEFROM" : timeFrom }}]
params = urllib.urlencode({'f': 'json', 'features': updateAttr})
updateURL = urllib2.Request(updateBaseURL,params)
response = urllib2.urlopen(updateURL)
jsonResult = json.load(response)
print jsonResult‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

If anyone wonders about the same thing

Also guess I can set a trigger on the SQL database to launch the python script every time a new row is inserted.