Geometry Operations API
The Geometry Operations API provides powerful spatial analysis and geometry manipulation capabilities. It allows you to perform 41 different operations on GeoJSON geometries including:
- Boolean operations - union, intersection, difference of polygons
- Measurements - distance between points, polygon area
- Transformations - buffer, simplify, rotate, scale, translate
- Clustering - DBSCAN, K-means, Voronoi diagrams
- Spatial predicates - contains, intersects, within, valid
- Generators - random points, lines, polygons, grids
This API accepts GeoJSON geometries directly in the request body and returns results in a unified format, making it easy to integrate into any application that works with geographic data.
To make it easy for you to get started with the Geometry Operations API, we have created an API Playground where you can test operations interactively.
Authentication and API key
To use the Geometry Operations API, you'll need an API key. You can register and get a Geometry Operations API Key for free without a credit card.
We offer a free plan, so there's no need to stress about cost. Start for free and upgrade to a paid plan when the needs of your project increase. For more information on our plans, visit the Pricing page.
How to get the Geoapify API key
- Register on the Geoapify MyProjects page.
- Create a new project.
- Go to the API Keys section. One API key is generated automatically. You can generate multiple API keys per project if required.
- Optionally, you can protect the API key by listing allowed IP addresses, HTTP referrers, origins, and CORS.
- Choose "Geometry Operations API" and an API key to generate a URL and programming code.
- Press the "Try" button to execute the API call and get the result object example.
API reference
The Geometry Operations API is an HTTP POST request API that performs spatial analysis and geometry manipulation on GeoJSON data. It supports 41 operations including boolean operations, measurements, transformations, clustering, and more.
Request URL
POST https://api.geoapify.com/v1/geometry/operation?apiKey=YOUR_API_KEY
Query parameters
| Name | Description | Example |
|---|---|---|
| apiKey | Required parameter for API key | apiKey=YOUR_API_KEY |
Request body
All requests are sent as HTTP POST with a JSON body. The request body always includes an operation field.
All other request fields depend on the selected operation and can include:
- operation-specific top-level fields (for example:
points,geometry,bbox) - operation-specific nested parameters in
params(for example:params.units,params.steps)
Use Supported Operations to find each operation's required and optional request fields.
| Name | Type | Description | Example |
|---|---|---|---|
| operation | string | Required. The geometry operation to perform. See Supported Operations. | "union" |
| ... | depends on operation | Additional request fields are operation-specific (top-level fields and params.*). |
points, geometry, bbox, params.units |
Request field conventions
params.<name>in operation docs means the field must be sent inside theparamsobject.bboxcan be sent in array format[minLon, minLat, maxLon, maxLat]or object format{lon1, lat1, lon2, lat2}.- Each operation page uses the same parameter table structure:
Name,Type,Description,Example.
Response object
The Geometry Operations API returns a unified response structure for all operations:
| Name | Type | Description |
|---|---|---|
| type | string | The result type: geojson, number, boolean, or empty |
| data | varies | The result data (geometry, number, boolean, or null) |
Response types:
| Type | Description | Example operations |
|---|---|---|
geojson |
GeoJSON geometry or FeatureCollection | union, buffer, convex, grid |
number |
Numeric result (distance, area) | distance, area, pointToLineDistance |
boolean |
Spatial predicate result | contains, intersects, valid, within |
empty |
No result (null) | When operation produces no output |
Example response (geojson):
{
"type": "geojson",
"data": {
"type": "Polygon",
"coordinates": [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]]
}
}
Example response (number):
{
"type": "number",
"data": 3941.52
}
Example response (boolean):
{
"type": "boolean",
"data": true
}
Response HTTP status codes
| Status | Description |
|---|---|
| 200 | The request was successful and the response contains the operation result. |
| 400 | Bad Request - Invalid input parameters or geometry. The response contains an error message. |
| 401 | Unauthorized - Invalid or missing API key. |
| 429 | Too Many Requests - Rate limit exceeded. |
| 500 | Internal Server Error. |
Supported Operations
The API supports 41 operations organized into 10 categories.
Select an operation to view required inputs, result type, and request examples.
1. Constructive / Polygon Set Operations
These operations combine or compare polygon geometries.
union- Merges multiple polygons into a single polygon, combining all areas.intersection- Finds the overlapping area common to all input polygons.difference- Subtracts subsequent polygons from the first polygon.
2. Point Set / Surface / Clustering
These operations work with point collections to create surfaces, hulls, or clusters.
voronoi- Creates a Voronoi diagram from a set of points. Each cell contains all locations closest to its seed point.clustersDbscan- Performs DBSCAN (Density-Based Spatial Clustering) on points.clustersKmeans- Performs K-means clustering on points.concave- Creates a concave hull (alpha shape) around a set of points.convex- Creates a convex hull around a set of points - the smallest convex polygon containing all points.tin- Creates a Triangulated Irregular Network (TIN) from points.
3. Spatial Predicates (Boolean)
These operations test spatial relationships and return true or false.
contains- Checks if geometry1 completely contains geometry2.crosses- Checks if two geometries cross each other.disjoint- Checks if two geometries have no points in common.intersects- Checks if two geometries have at least one point in common.within- Checks if geometry1 is completely within geometry2.valid- Checks if a geometry is valid according to OGC standards.
4. Measurement (Numeric)
These operations calculate distances and areas, returning numeric values.
distance- Calculates the distance between two points.area- Calculates the area of a polygon in square meters.pointToLineDistance- Calculates the shortest distance from a point to a line.pointToPolygonDistance- Calculates the shortest distance from a point to a polygon boundary.
5. Line Operations
These operations work with lines and points along lines.
pointOnLine- Checks if a point lies on a line. Returnstrueif the point is exactly on the line,falseotherwise.nearestPointOnLine- Finds the nearest point on a line (supports MultiLineString).lineIntersect- Finds all intersection points between two lines.along- Returns a point at a specified distance along a line.
6. Transformations
These operations modify geometries by applying spatial transformations.
buffer- Creates a buffer polygon around a geometry at a specified distance.simplify- Simplifies a geometry by reducing the number of vertices while preserving shape.transformRotate- Rotates a geometry around a pivot point.transformScale- Scales a geometry from a given origin.transformTranslate- Moves a geometry by a specified distance in a given direction.
7. Geometry Centers
These operations calculate different types of center points for geometries.
center- Calculates the absolute center point (centroid of bounding box).centerMean- Calculates the mean center of all vertices.centerMedian- Calculates the median center using iterative approach.centerOfMass- Calculates the center of mass (centroid) of a geometry.
8. Bounding / Envelope
These operations calculate bounding regions for geometries.
bbox- Returns the bounding box of a geometry as a polygon.envelope- Returns the minimum bounding rectangle (envelope) containing all geometries.
9. Grid & Random Generators
These operations generate grids and random geometries within a bounding box.
grid- Generates a grid of cells within a bounding box.randomPoint- Generates random points within a bounding box.randomLineString- Generates random line strings within a bounding box.randomPolygon- Generates random polygons within a bounding box.
10. Geometry Queries & Advanced
These operations provide advanced spatial queries and calculations.
pointsWithinPolygon- Finds all points that fall within a polygon.greatCircle- Calculates the great circle arc between two points on Earth's surface.tesselate- Divides a polygon into triangles.
union
Category: Constructive / Polygon Set Operations
Merges multiple polygons into a single polygon, combining all areas.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "union" |
polygons |
array | Required input. min 2, max 100. | [{"type":"Polygon","coordinates":[[[0,0],[10,0],[10,10],[0,10],[0,0]]]}] |
Example of API request:
{
"operation": "union",
"polygons": [
{
"type": "Polygon",
"coordinates": [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]]
},
{
"type": "Polygon",
"coordinates": [[[5, 5], [15, 5], [15, 15], [5, 15], [5, 5]]]
}
]
}
Result type: geojson
intersection
Category: Constructive / Polygon Set Operations
Finds the overlapping area common to all input polygons.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "intersection" |
polygons |
array | Required input. min 2, max 100. | [{"type":"Polygon","coordinates":[[[0,0],[10,0],[10,10],[0,10],[0,0]]]}] |
Example of API request:
{
"operation": "intersection",
"polygons": [
{
"type": "Polygon",
"coordinates": [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]]
},
{
"type": "Polygon",
"coordinates": [[[5, 5], [15, 5], [15, 15], [5, 15], [5, 5]]]
}
]
}
Result type: geojson
difference
Category: Constructive / Polygon Set Operations
Subtracts subsequent polygons from the first polygon.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "difference" |
polygons |
array | Required input. min 2, max 100. | [{"type":"Polygon","coordinates":[[[0,0],[10,0],[10,10],[0,10],[0,0]]]}] |
Example of API request:
{
"operation": "difference",
"polygons": [
{
"type": "Polygon",
"coordinates": [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]]
},
{
"type": "Polygon",
"coordinates": [[[5, 5], [15, 5], [15, 15], [5, 15], [5, 5]]]
}
]
}
Result type: geojson
voronoi
Category: Point Set / Surface / Clustering
Creates a Voronoi diagram from a set of points. Each cell contains all locations closest to its seed point.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "voronoi" |
points |
array | Required input. min 3, max 1000. | [{"type":"Point","coordinates":[-73.985,40.748]}] |
bbox |
array/object | Required input. Bounding box. Possible formats: array [minLon, minLat, maxLon, maxLat], object {lon1, lat1, lon2, lat2}. |
[-74.02,40.7,-73.9,40.82] |
Example of API request:
{
"operation": "voronoi",
"points": [
{"type": "Point", "coordinates": [-73.985, 40.748]},
{"type": "Point", "coordinates": [-73.979, 40.754]},
{"type": "Point", "coordinates": [-73.968, 40.785]}
],
"bbox": [-74.02, 40.70, -73.90, 40.82]
}
Result type: geojson
clustersDbscan
Category: Point Set / Surface / Clustering
Performs DBSCAN (Density-Based Spatial Clustering) on points.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "clustersDbscan" |
points |
array | Required input. min 3, max 1000. | [{"type":"Point","coordinates":[-73.985,40.748]}] |
maxDistance |
number | Required input. Maximum distance. | 500 |
params.units |
string | Optional parameter (in params). Possible values: meters, kilometers, miles, nauticalmiles, feet, yards, inches, centimeters, millimeters, radians, degrees. |
"meters" |
params.minPoints |
number | Optional parameter (in params). Minimum points for DBSCAN clusters. |
2 |
Example of API request:
{
"operation": "clustersDbscan",
"points": [
{"type": "Point", "coordinates": [-73.985, 40.748]},
{"type": "Point", "coordinates": [-73.984, 40.749]},
{"type": "Point", "coordinates": [-73.968, 40.785]}
],
"maxDistance": 500,
"params": {
"units": "meters",
"minPoints": 2
}
}
Result type: geojson
clustersKmeans
Category: Point Set / Surface / Clustering
Performs K-means clustering on points.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "clustersKmeans" |
points |
array | Required input. min 3, max 1000. | [{"type":"Point","coordinates":[-73.985,40.748]}] |
params.numberOfClusters |
number | Optional parameter (in params). Number of clusters for K-means. |
2 |
Example of API request:
{
"operation": "clustersKmeans",
"points": [
{"type": "Point", "coordinates": [-73.985, 40.748]},
{"type": "Point", "coordinates": [-73.984, 40.749]},
{"type": "Point", "coordinates": [-73.968, 40.785]},
{"type": "Point", "coordinates": [-73.967, 40.784]}
],
"params": {
"numberOfClusters": 2
}
}
Result type: geojson
concave
Category: Point Set / Surface / Clustering
Creates a concave hull (alpha shape) around a set of points.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "concave" |
points |
array | Required input. min 3, max 1000. | [{"type":"Point","coordinates":[-73.985,40.748]}] |
params.maxEdge |
number | Optional parameter (in params). Maximum edge length for concave hull. |
1 |
params.units |
string | Optional parameter (in params). Possible values: meters, kilometers, miles, nauticalmiles, feet, yards, inches, centimeters, millimeters, radians, degrees. |
"kilometers" |
Example of API request:
{
"operation": "concave",
"points": [
{"type": "Point", "coordinates": [-73.985, 40.748]},
{"type": "Point", "coordinates": [-73.979, 40.754]},
{"type": "Point", "coordinates": [-73.968, 40.785]},
{"type": "Point", "coordinates": [-73.990, 40.760]}
],
"params": {
"maxEdge": 1,
"units": "kilometers"
}
}
Result type: geojson or empty (when no hull can be formed with given maxEdge)
Note:
params.maxEdgeis optional. If provided and the points are too spread apart relative tomaxEdge, the operation returns anemptyresult.
convex
Category: Point Set / Surface / Clustering
Creates a convex hull around a set of points - the smallest convex polygon containing all points.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "convex" |
points |
array | Required input. min 3, max 1000. | [{"type":"Point","coordinates":[-73.985,40.748]}] |
params.concavity |
number | Optional parameter (in params). Concavity value. |
- |
Example of API request:
{
"operation": "convex",
"points": [
{"type": "Point", "coordinates": [-73.985, 40.748]},
{"type": "Point", "coordinates": [-73.979, 40.754]},
{"type": "Point", "coordinates": [-73.968, 40.785]},
{"type": "Point", "coordinates": [-73.990, 40.760]}
]
}
Result type: geojson
tin
Category: Point Set / Surface / Clustering
Creates a Triangulated Irregular Network (TIN) from points.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "tin" |
points |
array | Required input. min 3, max 1000. | [{"type":"Point","coordinates":[-73.985,40.748]}] |
Example of API request:
{
"operation": "tin",
"points": [
{"type": "Point", "coordinates": [-73.985, 40.748]},
{"type": "Point", "coordinates": [-73.979, 40.754]},
{"type": "Point", "coordinates": [-73.968, 40.785]},
{"type": "Point", "coordinates": [-73.990, 40.760]}
]
}
Result type: geojson
contains
Category: Spatial Predicates (Boolean)
Checks if geometry1 completely contains geometry2.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "contains" |
geometry1 |
object | Required input. First geometry for comparison. | {"type":"Polygon","coordinates":[[[0,0],[20,0],[20,20],[0,20],[0,0]]]} |
geometry2 |
object | Required input. Second geometry for comparison. | {"type":"Point","coordinates":[10,10]} |
Example of API request:
{
"operation": "contains",
"geometry1": {
"type": "Polygon",
"coordinates": [[[0, 0], [20, 0], [20, 20], [0, 20], [0, 0]]]
},
"geometry2": {
"type": "Point",
"coordinates": [10, 10]
}
}
Result type: boolean
crosses
Category: Spatial Predicates (Boolean)
Checks if two geometries cross each other.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "crosses" |
geometry1 |
object | Required input. First geometry for comparison. | {"type":"LineString","coordinates":[[0,0],[10,10]]} |
geometry2 |
object | Required input. Second geometry for comparison. | {"type":"LineString","coordinates":[[0,10],[10,0]]} |
Example of API request:
{
"operation": "crosses",
"geometry1": {
"type": "LineString",
"coordinates": [[0, 0], [10, 10]]
},
"geometry2": {
"type": "LineString",
"coordinates": [[0, 10], [10, 0]]
}
}
Result type: boolean
disjoint
Category: Spatial Predicates (Boolean)
Checks if two geometries have no points in common.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "disjoint" |
geometry1 |
object | Required input. First geometry for comparison. | {"type":"Polygon","coordinates":[[[0,0],[5,0],[5,5],[0,5],[0,0]]]} |
geometry2 |
object | Required input. Second geometry for comparison. | {"type":"Polygon","coordinates":[[[10,10],[15,10],[15,15],[10,15],[10,10]]]} |
Example of API request:
{
"operation": "disjoint",
"geometry1": {
"type": "Polygon",
"coordinates": [[[0, 0], [5, 0], [5, 5], [0, 5], [0, 0]]]
},
"geometry2": {
"type": "Polygon",
"coordinates": [[[10, 10], [15, 10], [15, 15], [10, 15], [10, 10]]]
}
}
Result type: boolean
intersects
Category: Spatial Predicates (Boolean)
Checks if two geometries have at least one point in common.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "intersects" |
geometry1 |
object | Required input. First geometry for comparison. | {"type":"Polygon","coordinates":[[[0,0],[10,0],[10,10],[0,10],[0,0]]]} |
geometry2 |
object | Required input. Second geometry for comparison. | {"type":"Polygon","coordinates":[[[5,5],[15,5],[15,15],[5,15],[5,5]]]} |
Example of API request:
{
"operation": "intersects",
"geometry1": {
"type": "Polygon",
"coordinates": [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]]
},
"geometry2": {
"type": "Polygon",
"coordinates": [[[5, 5], [15, 5], [15, 15], [5, 15], [5, 5]]]
}
}
Result type: boolean
within
Category: Spatial Predicates (Boolean)
Checks if geometry1 is completely within geometry2.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "within" |
geometry1 |
object | Required input. First geometry for comparison. | {"type":"Point","coordinates":[5,5]} |
geometry2 |
object | Required input. Second geometry for comparison. | {"type":"Polygon","coordinates":[[[0,0],[10,0],[10,10],[0,10],[0,0]]]} |
Example of API request:
{
"operation": "within",
"geometry1": {
"type": "Point",
"coordinates": [5, 5]
},
"geometry2": {
"type": "Polygon",
"coordinates": [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]]
}
}
Result type: boolean
valid
Category: Spatial Predicates (Boolean)
Checks if a geometry is valid according to OGC standards.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "valid" |
geometry |
object | Required input. GeoJSON geometry object. | {"type":"Polygon","coordinates":[[[0,0],[10,0],[10,10],[0,10],[0,0]]]} |
Example of API request:
{
"operation": "valid",
"geometry": {
"type": "Polygon",
"coordinates": [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]]
}
}
Result type: boolean
distance
Category: Measurement (Numeric)
Calculates the distance between two points.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "distance" |
point1 |
object | Required input. First point geometry. | {"type":"Point","coordinates":[-73.985,40.748]} |
point2 |
object | Required input. Second point geometry. | {"type":"Point","coordinates":[-118.243,34.052]} |
params.units |
string | Optional parameter (in params). Default: kilometers. Possible values: meters, kilometers, miles, nauticalmiles, feet, yards, inches, centimeters, millimeters, radians, degrees. |
"kilometers" |
Example of API request:
{
"operation": "distance",
"point1": {"type": "Point", "coordinates": [-73.985, 40.748]},
"point2": {"type": "Point", "coordinates": [-118.243, 34.052]},
"params": {
"units": "kilometers"
}
}
Result type: number
area
Category: Measurement (Numeric)
Calculates the area of a polygon in square meters.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "area" |
polygon |
object | Required input. Polygon geometry. | {"type":"Polygon","coordinates":[[[-73.98,40.75],[-73.97,40.75],[-73.97,40.76],[-73.98,40.76],[-73.98,40.75]]]} |
Example of API request:
{
"operation": "area",
"polygon": {
"type": "Polygon",
"coordinates": [[[-73.98, 40.75], [-73.97, 40.75], [-73.97, 40.76], [-73.98, 40.76], [-73.98, 40.75]]]
}
}
Result type: number
pointToLineDistance
Category: Measurement (Numeric)
Calculates the shortest distance from a point to a line.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "pointToLineDistance" |
point |
object | Required input. Point geometry. | {"type":"Point","coordinates":[5,5]} |
line |
object | Required input. Line geometry. | {"type":"LineString","coordinates":[[0,0],[10,0]]} |
params.units |
string | Optional parameter (in params). Possible values: meters, kilometers, miles, nauticalmiles, feet, yards, inches, centimeters, millimeters, radians, degrees. |
"meters" |
Example of API request:
{
"operation": "pointToLineDistance",
"point": {"type": "Point", "coordinates": [5, 5]},
"line": {
"type": "LineString",
"coordinates": [[0, 0], [10, 0]]
},
"params": {
"units": "meters"
}
}
Result type: number
pointToPolygonDistance
Category: Measurement (Numeric)
Calculates the shortest distance from a point to a polygon boundary.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "pointToPolygonDistance" |
point |
object | Required input. Point geometry. | {"type":"Point","coordinates":[15,15]} |
polygon |
object | Required input. Polygon geometry. | {"type":"Polygon","coordinates":[[[0,0],[10,0],[10,10],[0,10],[0,0]]]} |
params.units |
string | Optional parameter (in params). Possible values: meters, kilometers, miles, nauticalmiles, feet, yards, inches, centimeters, millimeters, radians, degrees. |
"meters" |
Example of API request:
{
"operation": "pointToPolygonDistance",
"point": {"type": "Point", "coordinates": [15, 15]},
"polygon": {
"type": "Polygon",
"coordinates": [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]]
},
"params": {
"units": "meters"
}
}
Result type: number
pointOnLine
Category: Line Operations
Checks if a point lies on a line. Returns true if the point is exactly on the line, false otherwise.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "pointOnLine" |
point |
object | Required input. Point geometry. | {"type":"Point","coordinates":[5,0]} |
line |
object | Required input. Line geometry. | {"type":"LineString","coordinates":[[0,0],[10,0],[10,10]]} |
Example of API request:
{
"operation": "pointOnLine",
"point": {"type": "Point", "coordinates": [5, 0]},
"line": {
"type": "LineString",
"coordinates": [[0, 0], [10, 0], [10, 10]]
}
}
Result type: boolean
Note: To find the closest point on a line from a given point, use
nearestPointOnLineinstead, which returns a GeoJSON point.
nearestPointOnLine
Category: Line Operations
Finds the nearest point on a line (supports MultiLineString).
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "nearestPointOnLine" |
point |
object | Required input. Point geometry. | {"type":"Point","coordinates":[5,5]} |
line |
object | Required input. Line geometry. | {"type":"LineString","coordinates":[[0,0],[10,0],[10,10]]} |
params.units |
string | Optional parameter (in params). Possible values: meters, kilometers, miles, nauticalmiles, feet, yards, inches, centimeters, millimeters, radians, degrees. |
"kilometers" |
Example of API request:
{
"operation": "nearestPointOnLine",
"point": {"type": "Point", "coordinates": [5, 5]},
"line": {
"type": "LineString",
"coordinates": [[0, 0], [10, 0], [10, 10]]
},
"params": {
"units": "kilometers"
}
}
Result type: geojson
lineIntersect
Category: Line Operations
Finds all intersection points between two lines.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "lineIntersect" |
line1 |
object | Required input. First line geometry. | {"type":"LineString","coordinates":[[0,0],[10,10]]} |
line2 |
object | Required input. Second line geometry. | {"type":"LineString","coordinates":[[0,10],[10,0]]} |
Example of API request:
{
"operation": "lineIntersect",
"line1": {
"type": "LineString",
"coordinates": [[0, 0], [10, 10]]
},
"line2": {
"type": "LineString",
"coordinates": [[0, 10], [10, 0]]
}
}
Result type: geojson
along
Category: Line Operations
Returns a point at a specified distance along a line.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "along" |
line |
object | Required input. Line geometry. | {"type":"LineString","coordinates":[[-73.985,40.748],[-73.968,40.785]]} |
distance |
number | Required input. Distance value. | 2 |
params.units |
string | Optional parameter (in params). Possible values: meters, kilometers, miles, nauticalmiles, feet, yards, inches, centimeters, millimeters, radians, degrees. |
"kilometers" |
Example of API request:
{
"operation": "along",
"line": {
"type": "LineString",
"coordinates": [[-73.985, 40.748], [-73.968, 40.785]]
},
"distance": 2,
"params": {
"units": "kilometers"
}
}
Result type: geojson
buffer
Category: Transformations
Creates a buffer polygon around a geometry at a specified distance.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "buffer" |
geometry |
object | Required input. GeoJSON geometry object. | {"type":"Point","coordinates":[-73.985,40.748]} |
distance |
number | Required input. Distance value. | 1 |
params.units |
string | Optional parameter (in params). Possible values: meters, kilometers, miles, nauticalmiles, feet, yards, inches, centimeters, millimeters, radians, degrees. |
"kilometers" |
params.steps |
number | Optional parameter (in params). Number of steps for buffer approximation. |
64 |
Example of API request:
{
"operation": "buffer",
"geometry": {
"type": "Point",
"coordinates": [-73.985, 40.748]
},
"distance": 1,
"params": {
"units": "kilometers",
"steps": 64
}
}
Result type: geojson
simplify
Category: Transformations
Simplifies a geometry by reducing the number of vertices while preserving shape.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "simplify" |
geometry |
object | Required input. GeoJSON geometry object. | {"type":"LineString","coordinates":[[0,0],[1,1],[2,0],[3,1],[4,0],[5,1]]} |
params.tolerance |
number | Optional parameter (in params). Simplification tolerance. |
0.5 |
params.highQuality |
boolean | Optional parameter (in params). Use high-quality simplification. |
true |
params.mutate |
boolean | Optional parameter (in params). Mutate input geometry. |
- |
Example of API request:
{
"operation": "simplify",
"geometry": {
"type": "LineString",
"coordinates": [[0, 0], [1, 1], [2, 0], [3, 1], [4, 0], [5, 1]]
},
"params": {
"tolerance": 0.5,
"highQuality": true
}
}
Result type: geojson
transformRotate
Category: Transformations
Rotates a geometry around a pivot point.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "transformRotate" |
geometry |
object | Required input. GeoJSON geometry object. | {"type":"Polygon","coordinates":[[[0,0],[10,0],[10,10],[0,10],[0,0]]]} |
angle |
number | Required input. Rotation angle in degrees. | 45 |
params.pivot |
array | Optional parameter (in params). Pivot coordinate. |
[5,5] |
params.mutate |
boolean | Optional parameter (in params). Mutate input geometry. |
- |
Example of API request:
{
"operation": "transformRotate",
"geometry": {
"type": "Polygon",
"coordinates": [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]]
},
"angle": 45,
"params": {
"pivot": [5, 5]
}
}
Result type: geojson
transformScale
Category: Transformations
Scales a geometry from a given origin.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "transformScale" |
geometry |
object | Required input. GeoJSON geometry object. | {"type":"Polygon","coordinates":[[[0,0],[10,0],[10,10],[0,10],[0,0]]]} |
factor |
number | Required input. Scale factor. | 2 |
params.origin |
array | Optional parameter (in params). Scaling origin. |
"center" |
params.mutate |
boolean | Optional parameter (in params). Mutate input geometry. |
- |
Example of API request:
{
"operation": "transformScale",
"geometry": {
"type": "Polygon",
"coordinates": [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]]
},
"factor": 2,
"params": {
"origin": "center"
}
}
Result type: geojson
Origin options: center, centroid, sw, se, nw, ne, or [lon, lat] coordinate array.
transformTranslate
Category: Transformations
Moves a geometry by a specified distance in a given direction.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "transformTranslate" |
geometry |
object | Required input. GeoJSON geometry object. | {"type":"Point","coordinates":[-73.985,40.748]} |
distance |
number | Required input. Distance value. | 1 |
direction |
number | Required input. 0 = north. | 90 |
params.units |
string | Optional parameter (in params). Possible values: meters, kilometers, miles, nauticalmiles, feet, yards, inches, centimeters, millimeters, radians, degrees. |
"kilometers" |
params.zTranslation |
number | Optional parameter (in params). Translation along Z axis. |
- |
params.mutate |
boolean | Optional parameter (in params). Mutate input geometry. |
- |
Example of API request:
{
"operation": "transformTranslate",
"geometry": {
"type": "Point",
"coordinates": [-73.985, 40.748]
},
"distance": 1,
"direction": 90,
"params": {
"units": "kilometers"
}
}
Result type: geojson
center
Category: Geometry Centers
Calculates the absolute center point (centroid of bounding box).
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "center" |
geometry |
object | Required input. GeoJSON geometry object. | {"type":"Polygon","coordinates":[[[0,0],[10,0],[10,10],[0,10],[0,0]]]} |
Example of API request:
{
"operation": "center",
"geometry": {
"type": "Polygon",
"coordinates": [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]]
}
}
Result type: geojson
centerMean
Category: Geometry Centers
Calculates the mean center of all vertices.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "centerMean" |
geometry |
object | Required input. GeoJSON geometry object. | {"type":"Polygon","coordinates":[[[0,0],[10,0],[10,5],[0,5],[0,0]]]} |
Example of API request:
{
"operation": "centerMean",
"geometry": {
"type": "Polygon",
"coordinates": [[[0, 0], [10, 0], [10, 5], [0, 5], [0, 0]]]
}
}
Result type: geojson
centerMedian
Category: Geometry Centers
Calculates the median center using iterative approach.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "centerMedian" |
geometry |
object | Required input. GeoJSON geometry object. | {"type":"Polygon","coordinates":[[[0,0],[10,0],[10,10],[0,10],[0,0]]]} |
Example of API request:
{
"operation": "centerMedian",
"geometry": {
"type": "Polygon",
"coordinates": [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]]
}
}
Result type: geojson
centerOfMass
Category: Geometry Centers
Calculates the center of mass (centroid) of a geometry.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "centerOfMass" |
geometry |
object | Required input. GeoJSON geometry object. | {"type":"Polygon","coordinates":[[[0,0],[10,0],[10,10],[0,10],[0,0]]]} |
Example of API request:
{
"operation": "centerOfMass",
"geometry": {
"type": "Polygon",
"coordinates": [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]]
}
}
Result type: geojson
bbox
Category: Bounding / Envelope
Returns the bounding box of a geometry as a polygon.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "bbox" |
geometry |
object | Required input. GeoJSON geometry object. | {"type":"LineString","coordinates":[[0,0],[5,3],[10,8]]} |
params.recompute |
boolean | Optional parameter (in params). Recompute bounding box. |
- |
Example of API request:
{
"operation": "bbox",
"geometry": {
"type": "LineString",
"coordinates": [[0, 0], [5, 3], [10, 8]]
}
}
Result type: geojson
envelope
Category: Bounding / Envelope
Returns the minimum bounding rectangle (envelope) containing all geometries.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "envelope" |
geometries |
array | Required input. min 1, max 100. | [{"type":"Point","coordinates":[0,0]},{"type":"Point","coordinates":[10,10]},{"type":"Point","coordinates":[5,15]}] |
Example of API request:
{
"operation": "envelope",
"geometries": [
{"type": "Point", "coordinates": [0, 0]},
{"type": "Point", "coordinates": [10, 10]},
{"type": "Point", "coordinates": [5, 15]}
]
}
Result type: geojson
grid
Category: Grid & Random Generators
Generates a grid of cells within a bounding box.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "grid" |
bbox |
array/object | Required input. Bounding box. Possible formats: array [minLon, minLat, maxLon, maxLat], object {lon1, lat1, lon2, lat2}. |
[-73.99,40.74,-73.96,40.77] |
type |
string | Required input. Grid type. | "square" |
cellSide |
number | Required input. Cell side length. | 0.5 |
params.units |
string | Optional parameter (in params). Possible values: meters, kilometers, miles, nauticalmiles, feet, yards, inches, centimeters, millimeters, radians, degrees. |
"kilometers" |
Example of API request:
{
"operation": "grid",
"bbox": [-73.99, 40.74, -73.96, 40.77],
"type": "square",
"cellSide": 0.5,
"params": {
"units": "kilometers"
}
}
Result type: geojson
Grid types: hex, point, square, triangle
randomPoint
Category: Grid & Random Generators
Generates random points within a bounding box.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "randomPoint" |
bbox |
array/object | Required input. Bounding box. Possible formats: array [minLon, minLat, maxLon, maxLat], object {lon1, lat1, lon2, lat2}. |
[-73.99,40.74,-73.96,40.77] |
count |
integer | Required input. Number of generated features. | 10 |
Example of API request:
{
"operation": "randomPoint",
"bbox": [-73.99, 40.74, -73.96, 40.77],
"count": 10
}
Result type: geojson
randomLineString
Category: Grid & Random Generators
Generates random line strings within a bounding box.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "randomLineString" |
bbox |
array/object | Required input. Bounding box. Possible formats: array [minLon, minLat, maxLon, maxLat], object {lon1, lat1, lon2, lat2}. |
[-73.99,40.74,-73.96,40.77] |
count |
integer | Required input. Number of generated features. | 5 |
params.numVertices |
number | Optional parameter (in params). Number of vertices to generate. |
10 |
params.maxLength |
number | Optional parameter (in params). Maximum line length. |
0.01 |
params.maxRotation |
number | Optional parameter (in params). Maximum rotation angle. |
- |
Example of API request:
{
"operation": "randomLineString",
"bbox": [-73.99, 40.74, -73.96, 40.77],
"count": 5,
"params": {
"numVertices": 10,
"maxLength": 0.01
}
}
Result type: geojson
randomPolygon
Category: Grid & Random Generators
Generates random polygons within a bounding box.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "randomPolygon" |
bbox |
array/object | Required input. Bounding box. Possible formats: array [minLon, minLat, maxLon, maxLat], object {lon1, lat1, lon2, lat2}. |
[-73.99,40.74,-73.96,40.77] |
count |
integer | Required input. Number of generated features. | 3 |
params.numVertices |
number | Optional parameter (in params). Number of vertices to generate. |
6 |
params.maxRadialLength |
number | Optional parameter (in params). Maximum radial length. |
0.01 |
Example of API request:
{
"operation": "randomPolygon",
"bbox": [-73.99, 40.74, -73.96, 40.77],
"count": 3,
"params": {
"numVertices": 6,
"maxRadialLength": 0.01
}
}
Result type: geojson
pointsWithinPolygon
Category: Geometry Queries & Advanced
Finds all points that fall within a polygon.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "pointsWithinPolygon" |
points |
array | Required input. min 1, max 1000. | [{"type":"Point","coordinates":[-73.985,40.748]}] |
polygon |
object | Required input. Polygon geometry. | {"type":"Polygon","coordinates":[[[0,0],[10,0],[10,10],[0,10],[0,0]]]} |
Example of API request:
{
"operation": "pointsWithinPolygon",
"points": [
{"type": "Point", "coordinates": [5, 5]},
{"type": "Point", "coordinates": [15, 15]},
{"type": "Point", "coordinates": [8, 8]}
],
"polygon": {
"type": "Polygon",
"coordinates": [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]]
}
}
Result type: geojson
greatCircle
Category: Geometry Queries & Advanced
Calculates the great circle arc between two points on Earth's surface.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "greatCircle" |
point1 |
object | Required input. First point geometry. | {"type":"Point","coordinates":[-73.985,40.748]} |
point2 |
object | Required input. Second point geometry. | {"type":"Point","coordinates":[2.352,48.856]} |
params.npoints |
number | Optional parameter (in params). Number of points in great-circle arc. |
100 |
params.offset |
number | Optional parameter (in params). Offset for great-circle split behavior. |
- |
Example of API request:
{
"operation": "greatCircle",
"point1": {"type": "Point", "coordinates": [-73.985, 40.748]},
"point2": {"type": "Point", "coordinates": [2.352, 48.856]},
"params": {
"npoints": 100
}
}
Result type: geojson
tesselate
Category: Geometry Queries & Advanced
Divides a polygon into triangles.
| Name | Type | Description | Example |
|---|---|---|---|
operation |
string | Required input. Exact operation value. | "tesselate" |
polygon |
object | Required input. Polygon geometry. | {"type":"Polygon","coordinates":[[[0,0],[10,0],[10,10],[5,15],[0,10],[0,0]]]} |
Example of API request:
{
"operation": "tesselate",
"polygon": {
"type": "Polygon",
"coordinates": [[[0, 0], [10, 0], [10, 10], [5, 15], [0, 10], [0, 0]]]
}
}
Result type: geojson
Code samples
The Geometry Operations API is an HTTP POST request that accepts JSON and returns GeoJSON or other data types. Requests are platform-independent and can be made from most programming languages. For our code samples, we use JavaScript.
Call Geometry Operations API
The call to the Geometry Operations API is a simple HTTP POST request. For example:
const myAPIKey = "YOUR_API_KEY";
async function geometryOperation(requestBody) {
const response = await fetch(
`https://api.geoapify.com/v1/geometry/operation?apiKey=${myAPIKey}`,
{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(requestBody)
}
);
return response.json();
}
// Example: Calculate union of two polygons
const result = await geometryOperation({
operation: "union",
polygons: [
{
type: "Polygon",
coordinates: [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]]
},
{
type: "Polygon",
coordinates: [[[5, 5], [15, 5], [15, 15], [5, 15], [5, 5]]]
}
]
});
console.log(result);
// { type: "geojson", data: { type: "Polygon", coordinates: [...] } }
Visualize geometry result with Leaflet
When the operation returns a GeoJSON result, you can display it on a Leaflet map:
// Call the API
const result = await geometryOperation({
operation: "buffer",
geometry: { type: "Point", coordinates: [-73.985, 40.748] },
distance: 1,
params: { units: "kilometers" }
});
// Add result to map
if (result.type === "geojson") {
L.geoJSON(result.data, {
style: function (feature) {
return {
color: '#3388ff',
fillColor: '#3388ff',
fillOpacity: 0.3,
weight: 2
};
}
}).addTo(map);
}
Visualize geometry result with MapLibre GL
You can also visualize geometry results on a MapLibre GL map:
// Call the API
const result = await geometryOperation({
operation: "convex",
points: [
{ type: "Point", coordinates: [-73.985, 40.748] },
{ type: "Point", coordinates: [-73.979, 40.754] },
{ type: "Point", coordinates: [-73.968, 40.785] },
{ type: "Point", coordinates: [-73.990, 40.760] }
]
});
// Add result to map
if (result.type === "geojson") {
map.addSource('geometry-result', {
type: 'geojson',
data: result.data
});
map.addLayer({
id: 'geometry-fill',
type: 'fill',
source: 'geometry-result',
paint: {
'fill-color': '#3388ff',
'fill-opacity': 0.3
}
});
map.addLayer({
id: 'geometry-line',
type: 'line',
source: 'geometry-result',
paint: {
'line-color': '#3388ff',
'line-width': 2
}
});
}
Handle different result types
The Geometry Operations API returns different result types depending on the operation:
async function handleResult(requestBody) {
const result = await geometryOperation(requestBody);
switch (result.type) {
case 'geojson':
// Display on map or process geometry
console.log('Geometry result:', result.data);
L.geoJSON(result.data).addTo(map);
break;
case 'number':
// Display numeric result (distance, area)
console.log('Numeric result:', result.data);
break;
case 'boolean':
// Handle spatial predicate result
console.log('Boolean result:', result.data);
break;
case 'empty':
// No result
console.log('No result');
break;
}
}
// Example: Check if point is within polygon
handleResult({
operation: "within",
geometry1: { type: "Point", coordinates: [5, 5] },
geometry2: {
type: "Polygon",
coordinates: [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]]
}
});
// Output: Boolean result: true
Visualize geometry result with OpenLayers
Here's how to display geometry results using OpenLayers:
// Call the API
const result = await geometryOperation({
operation: "grid",
bbox: [-73.99, 40.74, -73.96, 40.77],
type: "hex",
cellSide: 0.2,
params: { units: "kilometers" }
});
// Add result to map
if (result.type === "geojson") {
const vectorSource = new ol.source.Vector({
features: new ol.format.GeoJSON({
featureProjection: "EPSG:3857"
}).readFeatures(result.data)
});
const style = new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(51, 136, 255, 1.0)',
width: 2
}),
fill: new ol.style.Fill({
color: 'rgba(51, 136, 255, 0.2)'
})
});
const vectorLayer = new ol.layer.Vector({
source: vectorSource,
style: style
});
map.addLayer(vectorLayer);
}
Pricing
The API call cost is calculated in credits. This helps us keep pricing simple and make our APIs universally usable:
| API name | Cost in credits | Example |
|---|---|---|
| Geometry Operations API | 1 request = 1 credit | Any operation (union, buffer, distance, area, etc.) costs 1 credit |
Each POST request to the Geometry Operations API consumes 1 credit regardless of the operation performed or the complexity of input geometries.
Please choose from our various Pricing Plans to suit your needs, including a Free Plan with 3000 credits/day included.
