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

  • Navigate to the above site in your browser
  • Click on View In ArcGIS.com map viewer to see what this service provides. Expand the legend for the Wildfire Response Polygons.
  • Back in the main service page, click on the link for the Coarse Counties layer

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']