How to Subtract One Area from Another

API or service
Geometry Operations API
Task
Target polygon − excluded polygons → remaining area
Examples
URL
Difficulty
Beginner
Time
7 min

Subtract one area from another

You have a target polygon and one or more regions that must be removed—for example restricted zones, existing coverage, water, or unavailable property. Use the Geometry Operations API difference operation to construct the remainder.

Task flow: target polygon − excluded polygons → remaining Polygon, MultiPolygon, or empty result.

Input order is essential. The API subtracts every polygon after the first from the first polygon. Put the target first and exclusions after it.

Subtract the polygons

This request removes the second Berlin rectangle from the first:

POST https://api.geoapify.com/v1/geometry/operation?apiKey=YOUR_API_KEY
Content-Type: application/json
{
  "operation": "difference",
  "polygons": [
    {
      "type": "Polygon",
      "coordinates": [[
        [13.38, 52.50], [13.42, 52.50],
        [13.42, 52.54], [13.38, 52.54],
        [13.38, 52.50]
      ]]
    },
    {
      "type": "Polygon",
      "coordinates": [[
        [13.40, 52.51], [13.44, 52.51],
        [13.44, 52.55], [13.40, 52.55],
        [13.40, 52.51]
      ]]
    }
  ]
}

The result retains the portion of the first rectangle that the second does not cover:

{
  "type": "geojson",
  "data": {
    "type": "Feature",
    "properties": {},
    "geometry": {
      "type": "Polygon",
      "coordinates": [[
        [13.38, 52.50], [13.42, 52.50],
        [13.42, 52.51], [13.40, 52.51],
        [13.40, 52.54], [13.38, 52.54],
        [13.38, 52.50]
      ]]
    }
  }
}

The subtraction can split one target into several pieces, so accept both Polygon and MultiPolygon. If exclusions cover the whole target, handle the empty result as a valid outcome.