Last active
November 26, 2023 06:04
-
-
Save TheBryanMac/f7979f9ba76ab734026f to your computer and use it in GitHub Desktop.
Export ArcGIS Server Map Service Layer to Shapefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?