Boundaries part-of
Returns the boundaries (administrative, postal, timezone, protected areas and more) that contain a point or a known place.
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.
apiKey<token>Your API key from the dashboard, sent as ?apiKey=<key>.
id?stringDeviation (unsupported): Geoapify hex place IDs are not accepted by this service; gp:addr, gp:tz and gp:iso IDs return an empty result (gp:tz:<tzid> is returned as place_id on timezone features but does not resolve as an id).
3 <= length <= 2048lat?numberLatitude of the place. Alternative to id; provide together with lon.
-90 <= value <= 90lon?numberLongitude of the place. Alternative to id; provide together with lat.
-180 <= value <= 180osm_id?integerNumeric OpenStreetMap object identifier. Alternative to id; use together with osm_type.
1 <= valueosm_type?stringOpenStreetMap object type used with osm_id: n for node, w for way, or r for relation (case-insensitive).
"r""w""n"boundaries?array<|string|>Boundary types to return. Multiple values are comma-separated; duplicates are collapsed and there is no cap on the number of types. Defaults to administrative when omitted. The special value all (not an enum item) expands to every type below, including the types without a data layer.
Deviation (extra): protected_area, national_park, aboriginal_lands, census, school_district, forest, hazard and regional_park are our additions, and all is ours; Geoapify caps the list at 10 types.
Deviation (empty): religious, municipality, barony, town, health and historic:administrative are accepted but have no data layer (layer: false in the response layers).
1 <= itemsgeometry?stringGeometry 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.
Deviation (approximated): simplification uses PostGIS ST_SimplifyPreserveTopology with a tolerance of N meters converted to degrees (N / 111320), so accuracy differs slightly from Geoapify's.
"point""point""geometry_1000""geometry_5000""geometry_10000"lang?stringLanguage used for boundary names and address fields (ISO 639-1). Uses the OSM name:<lang> tag and falls back to the default name when a boundary has no translation.
"en""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"Boundaries containing the requested place (possibly an empty FeatureCollection).
application/json- response
GeoJSON FeatureCollection of the boundaries that contain the requested place, smallest first (administrative), then postal codes. Empty features when nothing matches, every requested type has no data layer, or the Place ID has no boundary geometry.
type*unknownfeatures*array<>layers?array<>One entry per requested type: layer = a data layer exists; within = how many of its boundaries contain the point.
curl -X GET 'https://api.data.graphitelab.ai/v1/boundaries/part-of?id=gp%3Aosm%3Ar161816&lat=39.7684&lon=-86.1581&osm_id=161816&osm_type=r&boundaries=administrative%2Cpostal_code&geometry=point&lang=en'{ "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": { "name": "Indianapolis", "country": "United States", "continent": "North America", "country_code": "us", "state": "Indiana", "state_code": "IN", "iso3166_2": "US-IN", "county": "Marion County", "county_district": "Center Township", "city": "Indianapolis", "lon": -86.0932472869693, "lat": 39.7798447, "place_id": "gp:osm:r18438530", "datasource": { "sourcename": "openstreetmap", "attribution": "© OpenStreetMap contributors", "license": "Open Database License", "url": "https://www.openstreetmap.org/copyright", "raw": { "osm_id": 18438530, "osm_type": "r", "admin_level": 8, "wikidata": "Q6346", "wikipedia": "en:Indianapolis" } } }, "geometry": { "type": "Point", "coordinates": [ -86.093247, 39.779845 ] }, "bbox": [ -86.3281207, 39.6321626, -85.9380401, 39.9275253 ] }, { "type": "Feature", "properties": { "name": "Center Township", "country": "United States", "continent": "North America", "country_code": "us", "state": "Indiana", "state_code": "IN", "iso3166_2": "US-IN", "county": "Marion County", "county_district": "Center Township", "lon": -86.13982193886923, "lat": 39.75229160000001, "place_id": "gp:osm:r21364355", "datasource": { "sourcename": "openstreetmap", "attribution": "© OpenStreetMap contributors", "license": "Open Database License", "url": "https://www.openstreetmap.org/copyright", "raw": { "osm_id": 21364355, "osm_type": "r", "admin_level": 7, "wikidata": "Q5059398", "wikipedia": "en:Center Township, Marion County, Indiana" } } }, "geometry": { "type": "Point", "coordinates": [ -86.139822, 39.752292 ] }, "bbox": [ -86.1973736, 39.7216856, -86.0824946, 39.8255186 ] } ]}Full schema: API reference
GET /v1/boundaries/part-of answers "what boundaries is this place inside?" Give it a Place ID, a coordinate, or an OSM object, and it returns the containing city, township, county, state and country, plus optionally the ZIP-like postal area, the timezone, or OSM polygons such as a national park. Use it to enrich a location with its jurisdictions, or to fetch a boundary polygon for a map.
How it works
The gateway answers this route directly from PostGIS; no geocoding Engine or Valhalla is involved.
- It resolves the lookup to a point. A lat/lon pair is used as is. A
gp:osm:Place ID orosm_id/osm_typepair is looked up in the Nominatimplacextable and reduced to a representative point on its surface. Agp:pc:Place ID is looked up in the postal polygons. administrative: every OSM boundary withadmin_level2 to 11 whose polygon covers the point, smallest first. For an administrative Place ID, only that boundary and its ancestors are kept.postal_code: the Census ZCTA5 (US) or StatCan FSA (Canada) polygon covering the point.timezone: the timezone-boundary-builder polygon covering the point, withplace_idgp:tz:<tzid>.- Other OSM polygon layers (
neighborhood,place,region,political,historic,protected_area,national_park,aboriginal_lands,census,school_district,forest,hazard,regional_park,religious_administration,low_emission_zone,public_transport,traditional): every polygon of that type covering the point.protected_areaincludesleisure=nature_reserve;national_parkisboundary=national_park, or a nature reserve named "... National Park". religious,municipality,barony,town,healthandhistoric:administrativeare accepted but have no data layer: they return nothing.boundaries=allexpands to every type, and there is no cap on how many types you list (duplicates are collapsed). The top-levellayersarray reports each requested type withlayer(a data layer exists) andwithin(how many of its boundaries contain the point).- Names for each feature (
state,county,city, ...) come from the chain of containing administrative boundaries.
Data sources: OpenStreetMap (Geofabrik US and Canada extract, imported by Nominatim), Census ZCTA5, StatCan FSA boundaries, and timezone-boundary-builder (ODbL).
Quick start
curl -s "https://api.data.graphitelab.ai/v1/boundaries/part-of?lat=39.7684&lon=-86.1581&apiKey=$GRAPHITE_API_KEY"Response (trimmed to the first feature; the full response also has Center Township, Marion County, Indiana and the United States):
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "Indianapolis",
"country": "United States",
"country_code": "us",
"state": "Indiana",
"state_code": "IN",
"iso3166_2": "US-IN",
"county": "Marion County",
"county_district": "Center Township",
"city": "Indianapolis",
"lon": -86.0932472869693,
"lat": 39.7798447,
"place_id": "gp:osm:r18438530",
"datasource": {
"sourcename": "openstreetmap",
"attribution": "© OpenStreetMap contributors",
"license": "Open Database License",
"url": "https://www.openstreetmap.org/copyright",
"raw": { "osm_id": 18438530, "osm_type": "r", "admin_level": 8 }
}
},
"geometry": { "type": "Point", "coordinates": [-86.093247, 39.779845] },
"bbox": [-86.3281207, 39.6321626, -85.9380401, 39.9275253]
}
]
}Parameters
Use exactly one lookup method: id, lat with lon, or osm_id with osm_type.
| Name | Type | Required | What it does |
|---|---|---|---|
id | string (3 to 2048 chars) | One lookup method | Place ID of an administrative boundary (gp:osm:r161816) or postal boundary (gp:pc:US-46204). Recommended. |
lat | number (-90 to 90) | With lon | Latitude of the place. |
lon | number (-180 to 180) | With lat | Longitude of the place. |
osm_id | integer (1 or more) | With osm_type | Numeric OpenStreetMap object ID. |
osm_type | string: r, w, n | With osm_id | OSM object type (case-insensitive). |
boundaries | comma-separated list, or all | No | Boundary types to return, no cap on the count. Defaults to administrative. all expands to every type. Includes our extra types protected_area, national_park, aboriginal_lands, census, school_district, forest, hazard, regional_park. Types without a data layer return nothing. |
geometry | point, geometry_1000, geometry_5000, geometry_10000 | No | point (default) returns a representative point. geometry_N returns a Polygon or MultiPolygon simplified to about N meters. |
lang | ISO 639-1 code | No | Language for names. Uses the OSM name:<lang> tag, falling back to the default name. Default en. |
Response
The response is a GeoJSON FeatureCollection with one feature per containing boundary. Administrative features come smallest first (city before county before state before country).
| Field | Meaning |
|---|---|
layers | One entry per requested type: { type, layer, within }. layer is false for types without a data layer; within is how many of that type's boundaries contain the point. |
properties.boundary_type | The boundary type the feature was returned for. Non-administrative OSM features have no admin_level. |
properties.place_id | Our Place ID, gp:<kind>:<key>. Administrative boundaries are gp:osm:<n|w|r><osm id>; postal boundaries are gp:pc:<country>-<code>. Pass it as id to this and other endpoints. |
properties.name | Boundary name in lang. For postal boundaries, the code itself. |
properties.state, county, city, ... | Names of the containing boundaries, mapped from OSM admin_level (4 state, 5 or 6 county, 7 county district, 8 city, 9 city district, 10 suburb, 11 neighbourhood). |
properties.lon, lat | A representative point on the boundary surface (not the centroid). |
properties.postcode, postal_code | Postal boundaries only. |
properties.datasource | Where the boundary came from, with the attribution you must show to end users. openstreetmap, census-zcta5, statcan-fsa or timezone-boundary-builder (raw.tzid). For OSM raw carries admin_level (administrative boundaries only) and, when present, wikidata, wikipedia and ISO3166-2. |
geometry | A Point by default, or the simplified Polygon or MultiPolygon with geometry_N. |
bbox | Bounding box [min lon, min lat, max lon, max lat]. |
This endpoint has no rank object, distances or times.
Differences from Geoapify
-
empty:
religious,municipality,barony,town,healthandhistoric:administrativeare accepted but have no data layer (layer: falseinlayers). TheX-Boundaries-Noteheader is sent only when at least one requested type has no data layer: "Some requested boundary types have no data layer: seelayersin the response (layer: false)." -
extra: the types
protected_area,national_park,aboriginal_lands,census,school_district,forest,hazardandregional_park, the valueboundaries=all, no cap on the number of types (Geoapify allows 10), thelayerssummary andboundary_type. -
empty: optional descriptive fields (
formatted,address_line1,address_line2,categories,name_international,population, thetimezonedescriptor object, ...) are never returned. Atimezoneboundary feature is returned when you requestboundaries=timezone. -
unsupported:
idresolves onlygp:osm:andgp:pc:Place IDs.gp:addr:,gp:tz:,gp:iso:and Geoapify hex IDs return an empty FeatureCollection (gp:tz:<tzid>is a returnedplace_idon timezone features but is not an input). Malformedgp:IDs return 400. -
extra:
place_iduses ourgp:<kind>:<key>format, anddatasourcedescribes the OSM, ZCTA5, FSA or timezone-boundary-builder source. -
approximated:
geometry_Nsimplification uses PostGISST_SimplifyPreserveTopologywith a tolerance of N / 111320 degrees, so accuracy differs slightly from Geoapify.
US and Canada notes
-
Administrative boundaries are OSM, so levels are sparse and vary by place. Indianapolis returns a city and a township, while the Montreal example returns a city and an urban agglomeration as
county. -
US postal boundaries are Census ZCTA5, which approximate ZIP codes but are not USPS ZIPs. PO-box-only ZIPs have no polygon.
-
Canadian postal boundaries are StatCan FSA (the first three characters, like
H3B). Full six-character postal codes have no polygon here. -
The
langparameter helps in bilingual areas: Canadian boundaries often havename:fr.
More examples
Montreal with administrative and postal boundaries as simplified polygons. The FSA feature has datasource.sourcename statcan-fsa.
curl -s "https://api.data.graphitelab.ai/v1/boundaries/part-of?lat=45.5019&lon=-73.5674&boundaries=administrative,postal_code&geometry=geometry_5000&apiKey=$GRAPHITE_API_KEY"Errors and limits
| Status | Meaning |
|---|---|
| 400 | Bad request: no lookup method or more than one, osm_id without osm_type, invalid osm_type, unknown boundaries value, out-of-range lat/lon, a malformed gp: ID. |
| 401 | Missing or invalid API key. |
| 429 | Rate limited. |
| 500 | Internal error. |
An ID or OSM object that does not resolve, or a point outside any boundary, returns 200 with an empty FeatureCollection, not 404.
Known gateway issue: the sibling endpoint /v1/boundaries/consists-of takes about 11.5 seconds per call because it scans every administrative boundary without a bounding-box prefilter. part-of is not affected. The progress notes also record cold-engine latency outliers of 6 to 13 seconds right after a deploy.
Try in Playground (signed in to your Graphite Lab organization). Signed out, use the paste-your-key widget on the reference page.