I am creating a tool that takes records from an Access Database and inserts them into a feature service layer. I'd like this tool to be available as a stand-alone Python script.
I currently have the script working and inserting new features/table records into feature classes in a file geodatabase. However, I would really like for users to be able to run the tool and insert their features/records directly into a feature service.
Is there a particular path I should be using for the feature service layers? How do I deal with this path changing depending on the user? If someone could give me some input on this or direct me to resources where I could get a start on the best way to do this, I'd appreciate it!
An easy way to do it is make an edit in an application like the map viewer and record the traffic using Fiddler. Then, recreate the request using Python. For example, when editing a feature service on sampleserver6, here's the request:
URL:
Parameters:
f=json
adds=[{"geometry":{"x":-13046217.213390766,"y":4038225.1985029248,"spatialReference":{"wkid":102100,"latestWkid":3857}},"attributes":{"unitname":null,"status":0,"lastreport":null,"type":0,"callnumber":null,"speed":null}}]
In Python, this would look like:
import urllib, json
url = 'http://sampleserver6.arcgisonline.com/arcgis/rest/services/RedlandsEmergencyVehicles/FeatureServer/0...'
addsParam = [{"geometry":
{"x":-13046217.3,
"y":4038225.4,
"spatialReference":
{"wkid":102100,
"latestWkid":3857}
},
"attributes":
{"unitname":"new1",
"status":0,
"lastreport":5,
"type":0,
"callnumber":"",
"speed":5}
}
]
requestParams = dict(adds=addsParam,
f="json")
response = urllib.urlopen(url,urllib.urlencode(requestParams))
print(response.read())
Update the geometry, WKID, and then bring in the proper fields from your Access database.