Prompt
How do I pull geospatial data from an API?
Latest observation
Oct 8, 2026
OpenAI APIWeb search: off
Pulling geospatial data from an API is usually the same as pulling any other API data, with a few extra things to watch for: geometry format, coordinates/reference system, and pagination/filtering by area.
1) Find the API endpoint
Look for documentation that tells you:
- the base URL
- the endpoint for spatial features (e.g.
/locations,/features,/parcels) - required authentication (API key, OAuth token, etc.)
2) Request data in a geospatial format
Common geospatial response formats:
- GeoJSON: easiest for web and Python
- JSON with lat/lon fields
- WKT/WKB
- Esri REST JSON
- CSV with columns like
latitude,longitude
If the API supports it, request GeoJSON or a similar geometry-friendly format.
Example request
curl "https://api.example.com/features?bbox=-122.6,37.6,-122.3,37.9" \
-H "Authorization: Bearer YOUR_TOKEN"
3) Use spatial filters if available
Many APIs let you filter by:
- bounding box (
bbox) - radius / distance
- polygon
- city/state/region
- viewport extent
This is important because geospatial datasets can be large.
4) Handle pagination
If there are many features, the API may return results in pages:
pagelimit/offsetnextcursor token
Always loop until all pages are collected.
5) Parse the geometry
If you get GeoJSON, you can load it into GIS tools or Python libraries directly.
Python example: GeoJSON response
import requests
import geopandas as gpd
from shapely.geometry import shape
url = "https://api.example.com/features"
headers = {"Authorization": "Bearer YOUR_TOKEN"}
params = {"bbox": "-122.6,37.6,-122.3,37.9"}
resp = requests.get(url, headers=headers, params=params)
resp.raise_for_status()
data = resp.json()
# If response is a GeoJSON FeatureCollection
gdf = gpd.GeoDataFrame.from_features(data["features"])
print(gdf.head())
6) Convert to a GIS-friendly format if needed
You can save to:
- GeoPackage (
.gpkg) - Shapefile (
.shp) - GeoJSON
- PostGIS
Example:
gdf.to_file("features.gpkg", layer="features", driver="GPKG")
7) Check coordinate reference system (CRS)
Many APIs return coordinates in:
- WGS84 / EPSG:4326 (lon/lat)
- or a projected CRS
If needed, reproject:
gdf = gdf.set_crs("EPSG:4326")
gdf = gdf.to_crs("EPSG:3857")
8) Watch for common pitfalls
- Coordinates reversed: GeoJSON uses
[longitude, latitude] - Missing CRS info
- Rate limits
- Invalid geometry
- Large payloads
- Different geometry types: Point, LineString, Polygon, MultiPolygon
Simple “recipe”
- Read API docs
- Authenticate
- Request spatial data with bbox/filters
- Parse JSON/GeoJSON
- Convert to GeoPandas/Shapely/PostGIS
- Reproject if needed
- Save/use the data
If you want, I can show you:
- a Python example for a specific API
- how to pull from ArcGIS REST, Overpass, or GeoJSON APIs
- how to load the result into PostGIS or QGIS