Repair GeoJSON and get the fixed document back with a log of every alteration: rings rewou
Repair GeoJSON and get the fixed document back with a log of every alteration: rings rewound to RFC 7946 winding order, consecutive duplicate vertices dropped, unclosed rings closed, and polygon nesting fixed (mis-ordered exterior rings, holes that fall outside their exterior, MultiPolygon members that are really holes). Reach for it when POST /v1/geojson/validate reported errors, or when /v1/geometry, /v1/h3/polyfill or /v1/pip refused your document -- unclosed rings are the usual reason, and this is the cheapest way to clear them. Conservative by design: it only rewrites the classes above, and anything else it found is returned in unrepaired rather than guessed at, so it will not invent geometry or move a coordinate. Idempotent -- a conformant document comes back untouched with changed:false, so a second call costs money and changes nothing. Your input object is never mutated. Coordinate values are preserved exactly; nothing is rounded or reprojected. Limit: 1 MiB request body.
Provider
api.geoprimitives.dev · discovered, not yet claimed by its owner
Payment (x402 accepts[])
[
{
"scheme": "exact",
"network": "eip155:8453",
"payTo": "0x76A51b5Dd3729950B3b60c17f19252d221968FCe",
"asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"amount": "10000",
"maxTimeoutSeconds": 300
}
]Output schema
{
"bazaar": {
"info": {
"input": {
"body": {
"coordinates": [
[
[
0,
0
],
[
0,
1
],
[
0,
1
],
[
1,
1
],
[
1,
0
],
[
0,
0
]
]
],
"type": "Polygon"
},
"bodyType": "json",
"method": "POST",
"type": "http"
},
"output": {
"example": {
"changeCount": 2,
"changed": true,
"changes": [
{
"code": "deduped_vertices",
"message": "Removed 1 consecutive duplicate position.",
"path": "$.coordinates[0]",
"ringIndex": 0
},
{
"code": "rewound_ring",
"message": "Reversed exterior ring to counterclockwise.",
"path": "$.coordinates[0]",
"ringIndex": 0
}
],
"geojson": {
"coordinates": [
[
[
0,
0
],
[
1,
0
],
[
1,
1
],
[
0,
1
],
[
0,
0
]
]
],
"type": "Polygon"
},
"unrepaired": []
},
"type": "json"
}
},
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"input": {
"additionalProperties": false,
"properties": {
"body": {
"additionalProperties": true,
"properties": {
"coordinates": {
"description": "Present on a bare Geometry other than GeometryCollection.",
"type": "array"
},
"features": {
"description": "Present when type is FeatureCollection.",
"items": {
"type": "object"
},
"type": "array"
},
"geometries": {
"description": "Present when type is GeometryCollection.",
"items": {
"type": "object"
},
"type": "array"
},
"geometry": {
"description": "Present when type is Feature. May be null.",
"type": "object"
},
"type": {
"description": "GeoJSON type. Post the document itself: a Feature, a FeatureCollection, or a bare Geometry.",
"enum": [
"FeatureCollection",
"Feature",
"Point",
"MultiPoint",
"LineString",
"MultiLineString",
"Polygon",
"MultiPolygon",
"GeometryCollection"
],
"type": "string"
}
},
"required": [
"type"
],
"type": "object"
},
"bodyType": {
"enum": [
"json",
"form-data",
"text"
],
"type": "string"
},
"method": {
"enum": [
"POST"
],
"type": "string"
},
"type": {
"const": "http",
"type": "string"
}
},
"required": [
"type",
"method",
"bodyType",
"body"
],
"type": "object"
},
"output": {
"properties": {
"example": {
"type": "object"
},
"type": {
"type": "string"
}
},
"required": [
"type"
],
"type": "object"
}
},
"required": [
"input"
],
"type": "object"
}
}
}Use it
curl
curl "https://api.geoprimitives.dev/v1/geojson/repair" # -> 402 Payment Required, accepts[] lists how to pay # retry with a PAYMENT-SIGNATURE (or PAYMENT header) once paid
JavaScript
const res = await fetch("https://api.geoprimitives.dev/v1/geojson/repair");
if (res.status === 402) {
const { accepts } = await res.json();
// pay one of accepts[] via an x402 client, then retry with the payment header
}Python
import httpx
res = httpx.get("https://api.geoprimitives.dev/v1/geojson/repair")
if res.status_code == 402:
accepts = res.json()["accepts"]
# pay one of accepts[] via an x402 client, then retry with the payment headerMachine-readable
Everything on this page is also available as clean JSON at /resources/6765.json, and this resource appears in /discovery/resources and /discovery/search.