Skip to content

Instantly share code, notes, and snippets.

@ojoaoaugusto
Forked from TheBryanMac/MapService2Shapefile.py
Last active October 19, 2017 15:25
Show Gist options
  • Save ojoaoaugusto/836f305e61409489eb85410aa37a6e2a to your computer and use it in GitHub Desktop.
Save ojoaoaugusto/836f305e61409489eb85410aa37a6e2a to your computer and use it in GitHub Desktop.
Export ArcGIS Server Map Service Layer to Shapefile
#Name: Export ArcGIS Server Map Service Layer to Shapefile
#Author: Bryan McIntosh
import urllib2, os, arcpy
# Variables
myUrl = "https://www.geoservicos1.segeth.df.gov.br/arcgis/rest/services"
myService = "/Luos/LUOS_PLC/MapServer"
myParams = "/0/query?where=1%3D1&text=&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=&returnGeometry=true&returnTrueCurves=false&maxAllowableOffset=&geometryPrecision=&outSR=&returnIdsOnly=false&returnCountOnly=true&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&gdbVersion=&returnDistinctValues=false&resultOffset=&resultRecordCount=&queryByDistance=&returnExtentsOnly=false&datumTransformation=&parameterValues=&rangeValues=&f=pjson"
# Query ArcGIS Server Map Service
myRequest = myUrl + myService + myParams
response = urllib2.urlopen(myRequest)
myJSON = response.read()
# Write response to json text file
foo = open("testeOutput.json", "wb")
foo.write(myJSON);
foo.close()
# Create Feature Class
ws = os.getcwd() + os.sep
arcpy.JSONToFeatures_conversion("testeOutput.json", ws + "LuosfinalShapfile.shp")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment