Skip to content

Extracting data from ArcGIS REST Services

Maybe you have an unpleasant-seeming ESRI MapServer webpage, that has data you want - polygons, shapes, points - that you can't seem to just click and download.

Try esri2gpd, which will take an ESRI url and convert it to a geopandas geodataframe.

Their example looks like this:

import esri2gpd

url = "https://services.arcgis.com/fLeGjb7u4uXqeF9q/ArcGIS/rest/services/Philly_Neighborhoods/FeatureServer/0"
gdf = esri2gpd.get(url, fields=['MAPNAME'], where="MAPNAME='Chestnut Hill'")

gdf.head()

To select the fields, look at the map description near the bottom. This one has a handful:

  • OBJECTID ( type: esriFieldTypeOID, alias: OBJECTID )
  • Shape ( type: esriFieldTypeGeometry, alias: Shape )
  • Fireshed_Name ( type: esriFieldTypeString, alias: Fireshed Name, length: 255 )
  • Shape_Length ( type: esriFieldTypeDouble, alias: Shape_Length )
  • Shape_Area ( type: esriFieldTypeDouble, alias: Shape_Area )
  • MajRegion ( type: esriFieldTypeString, alias: Forest Service Region, length: 4 )
  • MATURE_ACRES ( type: esriFieldTypeInteger, alias: Acres of Mature Forest )
  • ...etc...

You just pop them into the esri2gpd and you're ready to go:

import esri2gpd

url = "https://services.arcgis.com/fLeGjb7u4uXqeF9q/ArcGIS/rest/services/Philly_Neighborhoods/FeatureServer/0"
gdf = esri2gpd.get(url, fields=['OBJECTID' 'Fireshed_Name', 'MajRegion', 'MATURE_ACRES'], where="MAPNAME='Chestnut Hill'")

gdf.head()

To save it, you'll use the normal geopandas way of saving. For example, if you want a shapefile, you'll use to_file with a shapefile filename.

gdf.to_file('dataframe.shp')