Boundaries

Boundaries consists-of

Lists the child boundaries (counties, townships, postal code areas) that sit inside a parent boundary.

Signed in? Open this endpoint in the dashboard playground, which uses your organization automatically. Signed out, use Try in Playground below with your API key.

GET
/boundaries/consists-of

Authorization

queryapiKey<token>

Your API key from the dashboard, sent as ?apiKey=<key>.

Query Parameters

id*string

Place ID of the parent boundary, as returned in properties.place_id by this API (recommended source: /boundaries/part-of). Formats: gp:osm:<n|w|r><osm id> for an OpenStreetMap boundary, gp:pc:<US-ZIP|CA-FSA> for a postal code boundary. gp:addr, gp:tz and gp:iso ids have no

Length3 <= length <= 2048
boundary?string

Boundary type to return. Only administrative and postal_code have data.

Deviation (empty): every other value is valid but returns an empty FeatureCollection.

Deviation (extra): protected_area, national_park, aboriginal_lands, census, school_district, forest, hazard and regional_park are our additions to Geoapify's enum (they return an empty result here, as consists-of data covers only the two types above).

Default"administrative"
Value in"administrative""postal_code""political""low_emission_zone""public_transport""traditional""timezone""religious_administration""religious""place""neighborhood""region""municipality""barony""town""health""historic""historic:administrative""protected_area""national_park""aboriginal_lands""census""school_district""forest""hazard""regional_park"
sublevel?integer

Nested boundary depth.

Deviation (approximated): counts the distinct admin_level values present below the parent (levels are sparse in OpenStreetMap), not parent level plus N. For postal_code, only 1 returns data.

Range1 <= value <= 20
Default1
geometry?string

Geometry representation for returned boundaries. point returns representative points and is the default. The geometry_* values return simplified Polygon or MultiPolygon geometry at the specified accuracy in meters.

Default"point"
Value in"point""geometry_1000""geometry_5000""geometry_10000"
lang?string

Language used for boundary names and address fields (falls back to the default OpenStreetMap name when a boundary has no name in that language).

Default"en"
Value in"ab""aa""af""ak""sq""am""ar""an""hy""as""av""ae""ay""az""bm""ba""eu""be""bn""bh""bi""bs""br""bg""my""ca""ch""ce""ny""zh""cv""kw""co""cr""hr""cs""da""dv""nl""en""eo""et""ee""fo""fj""fi""fr""ff""gl""ka""de""el""gn""gu""ht""ha""he""hz""hi""ho""hu""ia""id""ie""ga""ig""ik""io""is""it""iu""ja""jv""kl""kn""kr""ks""kk""km""ki""rw""ky""kv""kg""ko""ku""kj""la""lb""lg""li""ln""lo""lt""lu""lv""gv""mk""mg""ms""ml""mt""mi""mr""mh""mn""na""nv""nb""nd""ne""ng""nn""no""ii""nr""oc""oj""cu""om""or""os""pa""pi""fa""pl""ps""pt""qu""rm""rn""ro""ru""sa""sc""sd""se""sm""sg""sr""gd""sn""si""sk""sl""so""st""es""su""sw""ss""sv""ta""te""tg""th""ti""bo""tk""tl""tn""to""tr""ts""tt""tw""ty""ug""uk""ur""uz""ve""vi""vo""wa""cy""wo""fy""xh""yi""yo""za"

Response Body

Boundaries contained by the requested place. An actual response can contain many features; examples are shortened. Empty features means no data for the request (see Deviation (empty)).

application/json
  1. response
type*unknown
features*array<>
Example Request
curl -X GET 'https://api.data.graphitelab.ai/v1/boundaries/consists-of?id=gp%3Aosm%3Ar161816&boundary=postal_code&sublevel=1&geometry=point&lang=en'
Example Response
{  "type": "FeatureCollection",  "features": [    {      "type": "Feature",      "properties": {        "name": "Adams County",        "country": "United States",        "continent": "North America",        "country_code": "us",        "state": "Indiana",        "state_code": "IN",        "iso3166_2": "US-IN",        "county": "Adams County",        "lon": -84.93671397818535,        "lat": 40.745785850000004,        "place_id": "gp:osm:r1797289",        "datasource": {          "sourcename": "openstreetmap",          "attribution": "© OpenStreetMap contributors",          "license": "Open Database License",          "url": "https://www.openstreetmap.org/copyright",          "raw": {            "osm_id": 1797289,            "osm_type": "r",            "admin_level": 6,            "wikidata": "Q351808",            "wikipedia": "en:Adams County, Indiana"          }        }      },      "geometry": {        "type": "Point",        "coordinates": [          -84.936714,          40.745786        ]      },      "bbox": [        -85.0738683,        40.568253,        -84.80217,        40.9225978      ]    },    {      "type": "Feature",      "properties": {        "name": "Allen County",        "country": "United States",        "continent": "North America",        "country_code": "us",        "state": "Indiana",        "state_code": "IN",        "iso3166_2": "US-IN",        "county": "Allen County",        "lon": -85.07039859151354,        "lat": 41.09943735,        "place_id": "gp:osm:r1527345",        "datasource": {          "sourcename": "openstreetmap",          "attribution": "© OpenStreetMap contributors",          "license": "Open Database License",          "url": "https://www.openstreetmap.org/copyright",          "raw": {            "osm_id": 1527345,            "osm_type": "r",            "admin_level": 6,            "wikidata": "Q493443",            "wikipedia": "en:Allen County, Indiana"          }        }      },      "geometry": {        "type": "Point",        "coordinates": [          -85.070399,          41.099437        ]      },      "bbox": [        -85.3381614,        40.9170272,        -84.8029428,        41.2711639      ]    }  ]}

GET /v1/boundaries/consists-of takes the Place ID of a boundary and returns the boundaries contained inside it, as a GeoJSON FeatureCollection. Use it to list the counties of a state, the subdivisions of a province, or the postal code areas inside a county. Get the parent id from /boundaries/part-of (the properties.place_id of the boundary you want).

How it works

The gateway answers this route with SQL only: no Geocoding Waterfall, Valhalla or VROOM.

  1. The id is decoded and resolved to a parent geometry. gp:osm:... ids look up the OpenStreetMap boundary in the Nominatim placex table; gp:pc:... ids look up a postal polygon.
  2. For boundary=administrative, it selects OpenStreetMap administrative boundaries (admin_level 2 to 11) that are deeper than the parent and whose representative point lies inside the parent. sublevel picks the N-th distinct admin_level found below the parent.
  3. For boundary=postal_code, it selects ZCTA5 polygons (US, Census) or FSA polygons (Canada, Statistics Canada) whose representative point lies inside the parent.
  4. Results are ordered by name (administrative) or code (postal). Polygon geometry is simplified with PostGIS ST_SimplifyPreserveTopology.

Administrative data comes from the Geofabrik US and Canada OpenStreetMap extract, loaded through Nominatim.

Quick start

All of Indiana's counties:

curl -s "https://api.data.graphitelab.ai/v1/boundaries/consists-of?id=gp:osm:r161816&apiKey=$GRAPHITE_API_KEY"

Response (trimmed to the first feature of 92):

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "name": "Adams County",
        "country": "United States",
        "continent": "North America",
        "country_code": "us",
        "state": "Indiana",
        "state_code": "IN",
        "iso3166_2": "US-IN",
        "county": "Adams County",
        "lon": -84.93671397818535,
        "lat": 40.745785850000004,
        "place_id": "gp:osm:r1797289",
        "datasource": {
          "sourcename": "openstreetmap",
          "attribution": "© OpenStreetMap contributors",
          "license": "Open Database License",
          "url": "https://www.openstreetmap.org/copyright",
          "raw": {
            "osm_id": 1797289,
            "osm_type": "r",
            "admin_level": 6,
            "wikidata": "Q351808",
            "wikipedia": "en:Adams County, Indiana"
          }
        }
      },
      "geometry": { "type": "Point", "coordinates": [-84.936714, 40.745786] },
      "bbox": [-85.0738683, 40.568253, -84.80217, 40.9225978]
    }
  ]
}

Parameters

NameTypeRequiredWhat it does
idstring (3 to 2048 chars)yesPlace ID of the parent boundary, as returned in properties.place_id. Formats: gp:osm:<n|w|r><osm id> or gp:pc:<US-ZIP|CA-FSA>. A malformed id returns 400.
boundarystring enum, default administrativenoBoundary type to return. Only administrative and postal_code have data.
sublevelinteger 1 to 20, default 1noNested depth. Counts distinct admin_level values below the parent. For postal_code, only 1 returns data.
geometryenum point, geometry_1000, geometry_5000, geometry_10000, default pointnopoint returns representative points. The geometry_* values return simplified Polygon or MultiPolygon geometry at that accuracy in meters.
langtwo-letter code, default ennoLanguage for boundary names; falls back to the default OpenStreetMap name.

Full parameter reference

Response

A GeoJSON FeatureCollection. Each feature has properties, geometry and bbox.

  • place_id: opaque string of the form gp:<kind>:<key>. Administrative features use gp:osm:r161816; postal features use gp:pc:US-46201. Pass it back as id to walk down another level.
  • name, country, country_code, state, state_code, iso3166_2, county and similar address fields describe the boundary and its parents.
  • lon and lat: the boundary's representative point.
  • datasource: where the boundary came from. OpenStreetMap boundaries cite "© OpenStreetMap contributors" under the Open Database License. Postal features use census-zcta5 or statcan-fsa and cite their source.
  • datasource.raw: source identifiers. Administrative features carry osm_id, osm_type, admin_level and, when present, wikidata, wikipedia, ISO3166-2. Postal features carry code.
  • Postal features also carry postcode and postal_code.
  • geometry: a Point by default, or a simplified Polygon or MultiPolygon with geometry_*.

This endpoint has no rank field and no distances or times.

Differences from Geoapify

  • empty: only administrative and postal_code boundaries have data. Other boundary values, unknown ids and non-boundary Place IDs (gp:addr, gp:tz, gp:iso) return an empty FeatureCollection, not 404. Other boundary types also set the X-Boundaries-Note response header: "consists-of has data for administrative and postal_code only".

  • extra: datasource.raw is a small set of source identifiers instead of the full OpenStreetMap tag set, and many optional Geoapify properties (formatted, categories, website, name_international, timezone and others) are not populated. Postal features add postcode and postal_code.

  • approximated: sublevel counts distinct admin_level values present below the parent, not parent level plus N. Containment is decided by each child's representative point, not by polygon overlap.

Geoapify's own place ids are not understood; use ids returned by this API.

US and Canada notes

  • US postal results are Census ZCTA5 polygons, which approximate ZIP codes. PO-box-only ZIPs have no polygon.
  • Canadian postal results are FSA polygons (the first three characters of a postal code), from Statistics Canada.
  • OpenStreetMap admin levels are sparse and differ by region. Indiana's counties are level 6; Ontario's children come back as OpenStreetMap subdivisions such as "Central Ontario". Use sublevel to step down.
  • Names follow lang. Ask for fr to get French names where OpenStreetMap has them.

More examples

Administrative boundaries below Ontario, Canada.

curl -s "https://api.data.graphitelab.ai/v1/boundaries/consists-of?id=gp:osm:r68841&apiKey=$GRAPHITE_API_KEY"

Errors and limits

StatusMeaning
200FeatureCollection, possibly empty.
400Missing id, malformed id, or invalid boundary, sublevel, geometry or lang.
401Missing or invalid credentials.
500Internal error.
503Service unavailable.

Limits: id is 3 to 2048 characters, and sublevel is 1 to 20.

Known issue: this endpoint takes about 11.5 seconds per call in production. It runs a full administrative scan of the placex table with no bounding-box prefilter. Set a generous client timeout.

Try in Playground (signed in to your Graphite Lab organization). Signed out, use the paste-your-key widget on the reference page.