Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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 = ""
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 =
# Write response to json text file
foo = open("jsonOutput.json", "wb")
# Create Feature Class
ws = os.getcwd() + os.sep
arcpy.JSONToFeatures_conversion("jsonOutput.json", ws + "finalShapfile.shp")

This comment has been minimized.

Copy link

@vonmoosa 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