points GPS in web service

617
2
04-19-2020 11:01 AM
PamelaLandy
Occasional Contributor

I have an external web services that will provide me with information on the locations of gps points, what I want is for the data to be loaded into a table from my DB  and then have a view in my corporate gdb. Is there a way to bring this information ?

0 Kudos
2 Replies
FC_Basson
MVP Regular Contributor

You'll have to run a query on the map service to retrieve the data and then write it to a local GDB.  You can do all this with Python (arcpy), with specific focus on the os, urllib, urllib2 and json modules.  If the service is secure, you might need to obtain a token from the server first, which you then include in query request.

An query example could look like this:

import arcpy, os, urllib2, urllib, json
service_url = 'https://myserver/arcgis/rest/services/GPS/MapServer/0/query'
params = {'where': '1=1', 'outFields': '*', 'returnIdsOnly': 'false', 'returnGeometry': 'false', 'f': 'pjson'}
req = urllib2.Request(service_url, urllib.urlencode(params)) 
response = urllib2.urlopen(req) 
data = json.load(response)‍‍‍‍‍‍

You can then write the json to a local file and convert it to a GDB table:

with open('gpspoints.json', 'w') as outfile:
    json.dump(data, outfile)

arcpy.JSONToFeatures_conversion("gpspoints.json", "C:/project/GPS/outputgdb.gdb/gps_points"))
PamelaLandy
Occasional Contributor

Thanks so much 

0 Kudos