This notebook is a quick demonstration of the ArcGIS-Rest-Query package we installed with ArcGIS Pro Package manager.
Briefly, this package is used to extract data from ESRI Online Services (which we will return to later). Here we will use the services hosted at this "REST service endpoint": https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer
We will use the ArcGIS-Rest-Query package to facilitate accessing services such as these in Jupyter notebooks or Python scripts.
Full documentation on this package is located here: https://github.com/Schwanksta/python-arcgis-rest-query
In [ ]:
#Import the package...
import arcgis
In [ ]:
#Link to a web service hosted on ArcGIS's web server
source = "https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"
In [ ]:
#Use the package's ARCGIS function to connect to the service
service = arcgis.ArcGIS(source)
In [ ]:
#Get the fourth layer, i.e. the Coarse Counties layer
layer_id = 3
In [ ]:
#Get all the county features for NC
records = service.get(layer=layer_id,where="STATE_NAME='North Carolina'")
In [ ]:
#What type of object does this return
type(records)
In [ ]:
#What are the keys in this dictionary
records.keys()
In [ ]:
#Get the features from the records
features = records['features']
len(features)
In [ ]:
#Get one feature object
f = features[0]
f.keys()
In [ ]:
f['properties']
In [ ]:
#Print a list of median ages for all counties
for f in features:
print f['properties']['NAME'],f['properties']['MED_AGE']