<< All versions

Skill v1.0.0

currentAutomated scan100/100
kendrick-oppong/geoskills/geospatial-api-design
──Details
PublishedOctober 25, 2026 at 04:51 PM
Content Hashsha256:7961331dfa976a5d...
Git SHAfe4762133b94
──Files
Files (1 file, 4.9 KB)
SKILL.md4.9 KBactive
SKILL.md · 61 lines · 4.9 KB

version: "1.0.0" name: geospatial-api-design description: Use when designing a REST or GraphQL API that serves geospatial data — bbox/geometry query parameters, GeoJSON response conventions, pagination of spatial results, filtering by distance/area, and structuring endpoints in a NestJS backend.


Geospatial API Design

When to use this skill

  • Designing endpoints for a NestJS/Express backend that return or accept geometry
  • "How should bbox filtering / nearby search work as a query parameter"
  • Deciding GeoJSON vs a custom response shape for API consumers

Core conventions (principal-level defaults)

  • Response format: return GeoJSON (FeatureCollection/Feature) for anything a frontend map will consume directly — it's a widely-understood standard every map library ingests natively, rather than a bespoke schema requiring a translation layer.
  • CRS assumption: GeoJSON is WGS84 lon/lat by spec — don't silently return a different CRS; if a projected CRS is genuinely needed by a consumer, make it an explicit, documented parameter/alternate endpoint, not a surprise.
  • Bounding box parameter convention: bbox=minLon,minLat,maxLon,maxLat (matches OGC API - Features convention) rather than inventing a custom shape — consumers and tooling already expect this order.
  • Pagination for large spatial result sets: cursor-based or limit/offset — never return an unbounded feature collection; cap response size and document the cap.
  • Distance/radius search: accept a center point + radius in meters (not degrees) as explicit parameters (lat, lon, radiusMeters) — avoids the degrees-vs-meters ambiguity trap from crs-and-reprojection.
  • Geometry simplification for list/overview endpoints: consider returning simplified geometry (or just centroids) for endpoints used to populate a low-zoom overview, with a separate "detail" endpoint returning full-precision geometry — mirrors the zoom-aware tiling principle even outside a tile pipeline.

Checklist

  • [ ] Every geometry-bearing response documents its CRS explicitly (default: WGS84/EPSG:4326) even if it's "obviously" GeoJSON
  • [ ] bbox/radius query params validated server-side (reject nonsensical bbox where min > max, reject radius beyond a sane cap) before hitting the database
  • [ ] Spatial queries are backed by an actual spatial index (spatial-indexing-strategy/postgis-geospatial) — an API contract that implies "fast nearby search" needs the database layer to actually support it
  • [ ] Large polygon/line geometries have a size guard — a single request shouldn't be able to return an unbounded multi-megabyte geometry blob without pagination or simplification
  • [ ], For GraphQL: geometry fields are typed explicitly (e.g., a custom GeoJSON scalar) rather than an untyped JSON blob, so client codegen produces useful types
  • [ ] Errors distinguish "invalid geometry/parameters" (400) from "not found" (404) from "query too broad, refine bbox/filters" (413/422) — geospatial APIs benefit from an explicit "too broad a query" error class since spatial queries can accidentally request enormous result sets
  • [ ] Versioning/documentation (OpenAPI/Swagger in NestJS via @nestjs/swagger) includes concrete bbox/geometry examples, since these parameter shapes aren't self-evident from a generic REST doc

Common pitfalls

  • Returning raw database geometry types (WKB hex strings) instead of GeoJSON: forces every consumer to parse WKB — do the ST_AsGeoJSON conversion server-side.
  • Unbounded bbox queries: an endpoint accepting an arbitrary bbox without a maximum-area guard can be trivially abused to request "the entire planet" and return an enormous payload — cap bbox area or feature count.
  • Mixing degrees and meters in the same parameter name: e.g. a radius param that's sometimes degrees, sometimes meters depending on internal implementation — always name and document units explicitly (radiusMeters).
  • No caching layer for expensive spatial aggregations: repeated identical bbox+filter combinations (e.g., a dashboard reloading the same viewport) hitting the database every time instead of a short-TTL cache.

Reference snippets

typescript
// NestJS controller — bbox + validated params
@Get('features')
async getFeatures(
@Query('bbox', new ParseBboxPipe()) bbox: [number, number, number, number],
@Query('limit', new DefaultValuePipe(500), ParseIntPipe) limit: number,
) {
if (limit > 2000) throw new BadRequestException('limit exceeds maximum of 2000');
const features = await this.featuresService.findInBbox(bbox, limit);
return { type: 'FeatureCollection', features }; // GeoJSON convention
}

Related skills

  • postgis-geospatial — the query layer backing these endpoints
  • crs-and-reprojection — units/CRS discipline referenced throughout
  • ogc-services-and-interop — the standardized alternative (OGC API - Features) to a fully custom API
All versions