Skip to content

Instantly share code, notes, and snippets.

@TheBryanMac
Last active November 26, 2023 06:04
Show Gist options
  • Save TheBryanMac/f7979f9ba76ab734026f to your computer and use it in GitHub Desktop.
Save TheBryanMac/f7979f9ba76ab734026f 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://sampleserver6.arcgisonline.com/arcgis/rest/services"
myService = "/Census/MapServer"
myParams = "/3/query?where=1%3D1&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=*&returnGeometry=true&geometryPrecision=&outSR=&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&returnZ=false&returnM=false&returnDistinctValues=false&returnTrueCurves=false&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("jsonOutput.json", "wb")
foo.write(myJSON);
foo.close()
# Create Feature Class
ws = os.getcwd() + os.sep
arcpy.JSONToFeatures_conversion("jsonOutput.json", ws + "finalShapfile.shp")
@vonmoosa
Copy link

vonmoosa commented Jul 20, 2018

I'm new to Python and would like to know how to modify this to download it to a local drive and also how would I modify it to use my sign in credentials for feature services that are not shared?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment