Guide - ArcGIS REST API

Overview

The ArcGIS REST API provides access to Esri’s ArcGIS Server, ArcGIS Online, and ArcGIS Enterprise services. This guide covers common endpoints and usage patterns for querying geospatial data.

Base URL Structure

https://<host>/<instance>/rest/services/<folder>/<serviceName>/<serviceType>

Examples:

  • FEMA: https://hazards.fema.gov/arcgis/rest/services
  • ArcGIS Online: https://services.arcgis.com/<orgId>/arcgis/rest/services

Server Info Endpoint

/info

Returns server metadata and authentication information.

Request:

GET https://hazards.fema.gov/arcgis/rest/info?f=json HTTP/1.1
Host: hazards.fema.gov

Response:

{
  "currentVersion": 11.1,
  "fullVersion": "11.1.0",
  "soapUrl": "https://hazards.fema.gov/arcgis/services",
  "secureSoapUrl": null,
  "authInfo": {
    "isTokenBasedSecurity": true,
    "tokenServicesUrl": "https://hazards.fema.gov/arcgis/tokens/",
    "shortLivedTokenValidity": 60
  }
}

/info/healthCheck

Returns service health status.

GET https://hazards.fema.gov/arcgis/rest/info/healthCheck?f=pjson

Service Types

TypeURL SuffixDescription
MapServer/MapServerMap service (rendering + query)
FeatureServer/FeatureServerFeature service (CRUD operations)
ImageServer/ImageServerRaster imagery service
GeocodeServer/GeocodeServerGeocoding service
GeometryServer/GeometryServerGeometry operations

Querying Features

MapServer/FeatureServer Query

Endpoint: /<ServiceName>/MapServer/<LayerID>/query

Common Parameters:

ParameterDescriptionExample
whereSQL where clauseSTATE='CA'
geometrySpatial filter geometry{"x":-122,"y":37}
geometryTypeType of geometryesriGeometryPoint
spatialRelSpatial relationshipesriSpatialRelIntersects
outFieldsFields to return* or OBJECTID,NAME
returnGeometryReturn shapestrue or false
outSROutput spatial reference4326
fOutput formatjson, geojson, pjson

Example - Query FEMA Flood Zones:

GET https://hazards.fema.gov/gis/nfhl/rest/services/public/NFHL/MapServer/28/query
?where=1=1
&outFields=*
&geometry=-122.4,37.8,-122.3,37.9
&geometryType=esriGeometryEnvelope
&spatialRel=esriSpatialRelIntersects
&returnGeometry=true
&outSR=4326
&f=geojson

Spatial Relationships

ValueDescription
esriSpatialRelIntersectsGeometry intersects
esriSpatialRelContainsGeometry contains
esriSpatialRelWithinGeometry within
esriSpatialRelTouchesGeometry touches
esriSpatialRelOverlapsGeometry overlaps

Geometry Types

ValueDescription
esriGeometryPointSingle point
esriGeometryPolylineLine geometry
esriGeometryPolygonPolygon geometry
esriGeometryEnvelopeBounding box

Authentication

Token-Based Authentication

  1. Request token from token service:
POST https://server/arcgis/tokens/generateToken
Content-Type: application/x-www-form-urlencoded
 
username=myuser&password=mypassword&f=json
  1. Include token in requests:
?token=<your_token>&f=json

API Keys (ArcGIS Online)

For ArcGIS Online, use an API key in the header or query parameter:

?token=<api_key>

R Integration

Using httr2 for ArcGIS REST API queries:

library(httr2)
library(sf)
 
query_arcgis <- function(base_url, layer_id, where = "1=1", bbox = NULL) {
  url <- paste0(base_url, "/", layer_id, "/query")
  
  req <- httr2::request(url) |>
    httr2::req_url_query(
      where = where,
      outFields = "*",
      returnGeometry = "true",
      outSR = 4326,
      f = "geojson"
    )
  
  if (!is.null(bbox)) {
    req <- req |>
      httr2::req_url_query(
        geometry = paste(bbox, collapse = ","),
        geometryType = "esriGeometryEnvelope",
        spatialRel = "esriSpatialRelIntersects"
      )
  }
  
  resp <- req |> httr2::req_perform()
  geojson <- httr2::resp_body_json(resp)
  
  sf::st_read(jsonlite::toJSON(geojson, auto_unbox = TRUE), quiet = TRUE)
}

Common Services

ServiceBase URL
FEMA NFHLhttps://hazards.fema.gov/gis/nfhl/rest/services/public/NFHL/MapServer
Census TIGERwebhttps://tigerweb.geo.census.gov/arcgis/rest/services
USGS National Maphttps://apps.nationalmap.gov/arcgis/rest/services

Notes

  • Always check /info first to understand server capabilities
  • Use f=geojson for direct import into GIS tools
  • For large queries, use pagination with resultOffset and resultRecordCount
  • Consider using the arcgislayers R package for simplified access

Appendix

Created: 2024-12-22 | Modified: 2024-12-22

See Also


(c) No Clocks, LLC | 2024