Drop vertices from a geometry while keeping its shape
Drop vertices from a geometry while keeping its shape. Use it to cut a boundary down before a call whose cost is vertex-driven -- POST /v1/pip caps on points times polygon vertices, and POST /v1/geometry/buffer and the overlay ops cap at 2000 positions -- and to shrink what you store or draw. The response reports outputVertices next to inputVertices, so the saving is measurable before you spend again. The algorithm is Douglas-Peucker. Send toleranceMeters for a ground tolerance applied isotropically: both axes are scaled to metres at the input's centre latitude first, so at 70 deg N the simplification is not three times as aggressive east-west as north-south, which a raw degree tolerance makes it. Send tolerance instead for the raw degree tolerance if you want turf's behaviour unchanged. Retained vertices come back exactly as sent rather than round-tripped through the scaling. Not topology-preserving: adjacent polygons simplified separately can gap or overlap along a shared edge. Input is EPSG:4326 only. Limits: 100000 positions across the whole document, 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": {
"geojson": {
"coordinates": [
[
-150,
61
],
[
-149.98,
61.001
],
[
-149.96,
61.0005
],
[
-149.94,
61.0015
],
[
-149.9,
61.002
]
],
"type": "LineString"
},
"toleranceMeters": 100
},
"bodyType": "json",
"method": "POST",
"type": "http"
},
"output": {
"example": {
"geojson": {
"geometry": {
"coordinates": [
[
-150,
61
],
[
-149.9,
61.002
]
],
"type": "LineString"
},
"properties": null,
"type": "Feature"
},
"inputVertices": 5,
"notes": [
"Tolerance was applied isotropically on the ground by scaling both axes to metres at latitude 61.0010, so 100 m means the same east-west as north-south.",
"Simplification is per-geometry Douglas-Peucker. It does not preserve topology: adjacent polygons simplified separately can gap or overlap along a shared edge."
],
"op": "simplify",
"outputVertices": 2,
"toleranceDegrees": {
"latitude": 0.00089743142433687,
"longitude": 0.0018482314669043616
},
"toleranceMeters": 100
},
"type": "json"
}
},
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"input": {
"additionalProperties": false,
"properties": {
"body": {
"additionalProperties": false,
"oneOf": [
{
"required": [
"toleranceMeters"
]
},
{
"required": [
"tolerance"
]
}
],
"properties": {
"geojson": {
"description": "A GeoJSON Feature, FeatureCollection or Geometry in EPSG:4326, longitude then latitude in degrees. At most 100000 positions across the whole document.",
"type": "object"
},
"highQuality": {
"default": false,
"description": "Skip the radial-distance pre-pass. Slower, and keeps more of the original shape.",
"type": "boolean"
},
"tolerance": {
"description": "Raw Douglas-Peucker tolerance in degrees, applied to longitude and latitude alike and therefore anisotropic away from the equator. Send this or toleranceMeters, never both.",
"maximum": 180,
"minimum": 0,
"type": "number"
},
"toleranceMeters": {
"description": "Ground tolerance in metres. A vertex is dropped when removing it moves the line by less than this. Send this or tolerance, never both.",
"maximum": 1000000,
"minimum": 0,
"type": "number"
}
},
"required": [
"geojson"
],
"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/geometry/simplify" # -> 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/geometry/simplify");
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/geometry/simplify")
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/6757.json, and this resource appears in /discovery/resources and /discovery/search.