Python script to consume JSON web service to file geodatabase

7266
1
01-28-2015 01:25 PM
GeoffreyWest1
New Contributor

I am working on a proof of concept for a larger project and am sure this has been done and is possible, however I cannot find any examples anywhere.  I would like to use my own ArcGIS Feature Service as an example where I use a Python script to parse fields that I would like to keep and print and all geometries.  I can handle to print portion to CSV, then table to table conversion.  The block below works fine in printing the feature service info.  Later, I would like to use UPDATE to apply changes made in a web service directly to our feature service.

import json
import urllib2

url = 'url'
r = urllib2.urlopen(url)
data = json.loads(r.read().decode(r.info().getparam('charset') or 'utf-8'))
print data

Prints:

{u'maxRecordCount': 1000, u'layers': [{u'id': 0, u'name': u'ServiceRequest.DBO.ServiceTypeDevSchema'}], u'allowGeometryUpdates': True, u'supportsDisconnectedEditing': False, u'description': u'', u'tables': [{u'id': 1, u'name': u'ServiceRequest.DBO.queryTable'}, {u'id': 2, u'name': u'ServiceRequest.DBO.queryTableLocation'}], u'initialExtent': {u'xmin': -118.79175291224679, u'ymin': 34.0096898681482, u'ymax': 34.27571360860003, u'xmax': -118.36725706880667, u'spatialReference': {u'wkid': 4326, u'latestWkid': 4326}}, u'documentInfo': {u'Category': u'', u'Author': u'', u'Title': u'', u'Comments': u'', u'Keywords': u'', u'Subject': u''}, u'capabilities': u'Create,Delete,Query,Update,Uploads,Editing', u'copyrightText': u'', u'units': u'esriDecimalDegrees', u'currentVersion': 10.21, u'enableZDefaults': False, u'hasVersionedData': False, u'spatialReference': {u'wkid': 4326, u'latestWkid': 4326}, u'fullExtent': {u'xmin': -118.54056884699997, u'ymin': 33.941116961000034, u'ymax': 34.222864945000026, u'xmax': -118.23978848099995, u'spatialReference': {u'wkid': 4326, u'latestWkid': 4326}}, u'syncEnabled': False, u'serviceDescription': u'', u'supportedQueryFormats': u'JSON, AMF'}
0 Kudos
1 Reply
XanderBakker
Esri Esteemed Contributor

If you want some python examples of how to extract features from a REST end point using python, you can find some in this thread: Re: Extract Features From MapServer/ Rest/ Soap/ etc?  Jake Skinner created a toolbox to do this.

There are also references to some python code I write to do this:

the simple way: https://community.esri.com/thread/118781#445348

or using a little more advanced: https://community.esri.com/thread/118781#445572

You can find an example of updating a feature service through Python and REST here:

Re: UpdateFeature REST API Python Script Unexpected Error