Overlap, union, or difference of two polygons
Where two areas overlap, their combined outline, what one has that the other lacks, or both, as valid polygons with geodesic areas, like the overlap of two geofences.
The result covers 0.18961711 km² in 1 part.
| Latitude | Longitude | Part | Ring |
|---|---|---|---|
| 40.0080000 deg | -104.9900000 deg | 0 | 0 |
| 40.0080001 deg | -104.9950000 deg | 0 | 0 |
| 40.0040000 deg | -104.9950000 deg | 0 | 0 |
| 40.0040001 deg | -104.9900000 deg | 0 | 0 |
- Parts
- First polygon's area
- Second polygon's area
Provenance
- Computed by
- geometry.overlay.boolean 1.2.1, core 0.1.0
- Model
- Both polygons' geodesic edges cut into 5 km pieces on one azimuthal equidistant plane at their corners' mean, each read by the even-odd rule; corners within a millionth of the shapes' size (at most 1 mm) of another ring are first put on it, so boundaries either meet exactly or stay clearly apart; every piece of either boundary is kept exactly when the result's inside differs on its two sides, and the pieces are joined into rings, taking the sharpest left turn where rings meet at a corner, so pieces that touch at a point come out as separate parts. Areas by Karney's geodesic polygon area (Karney 2013)
- Accuracy
- Edges follow the geodesics to about 1 mm for shapes of a few hundred kilometers; areas exact for the returned corners. Inputs within 5,000 km of their shared center. Planar edges: the overlay is exact on the longitude-latitude plane, and areas follow its straight edges to well under a part in a million
- Notes
- None
- Cites
- Karney, C. F. F., Journal of Geodesy, Algorithms for geodesics
Something look off?
How we got thisFormula, worked example, sources, and proof
Model: Both polygons' geodesic edges cut into 5 km pieces on one azimuthal equidistant plane at their corners' mean, each read by the even-odd rule; corners within a millionth of the shapes' size (at most 1 mm) of another ring are first put on it, so boundaries either meet exactly or stay clearly apart; every piece of either boundary is kept exactly when the result's inside differs on its two sides, and the pieces are joined into rings, taking the sharpest left turn where rings meet at a corner, so pieces that touch at a point come out as separate parts. Areas by Karney's geodesic polygon area (Karney 2013)
Accuracy: Edges follow the geodesics to about 1 mm for shapes of a few hundred kilometers; areas exact for the returned corners. Inputs within 5,000 km of their shared center. Planar edges: the overlay is exact on the longitude-latitude plane, and areas follow its straight edges to well under a part in a million
When to use this: Use this to ask how two areas relate as areas rather than as outlines: how much of a flight restriction falls inside a planned survey block, what a parcel keeps after a right of way is taken out of it, the combined footprint of two coverage zones, the part of a search area nobody has swept yet. It answers with the polygon itself and with its area on the ellipsoid, so the result can be drawn, measured, or fed straight back in.
Limitations: Both polygons and their result must sit within 5,000 km of their shared centre, because the overlay is done on one plane placed there and a plane cannot hold more of the Earth than that faithfully; further apart and the tool refuses rather than distorting. Edges are cut into 5 km pieces before the overlay, so a result boundary follows the geodesic to about a millimetre rather than exactly. A result can be empty, or break into several pieces, or acquire a hole, all of which are reported rather than treated as failure — a difference that leaves nothing is a correct answer. Self-intersecting inputs have no well-defined inside and should be repaired first. With planar edges the overlay is done on longitude and latitude as they are written, as GIS software does with such data; a shape crossing the antimeridian must be written with longitudes that run past 180 rather than jumping to -180.
Worked example: Where two geofences overlap. Source: GEOS 3.11.4 through shapely, the reference implementation for this operation, run on the same azimuthal equidistant plane and measured back on the ellipsoid by geographiclib: over ten cases across all four operations the areas agree to 2.2e-11 relative and the part counts exactly. It is golden test vector v001, and every build checks the tool still gives its answer within its tolerance.
You enter
- Operation
- intersection
- First polygon
- 40, -105 40, -104.99 40.008, -104.99 40.008, -105
- Second polygon
- 40.004, -104.995 40.004, -104.985 40.012, -104.985 40.012, -104.995
You get
- Result area
- 0.18961711 km²
- Parts
- 1
- First polygon's area
- 0.7584903 km²
- Second polygon's area
- 0.75844656 km²
Review: Not yet independently reviewed by a GIS professional.
Last verified: 2026-09-18, when a maintainer last confirmed this tool's sources at the issuer. See the sources ledger.
Status: version 1.2.1, core 0.1.0. See this tool in the verification report.
Changes
- 2026-10-09, fixed: The polygon overlap tool, with planar edges, stopped with an internal error when a longitude was absurdly large; it now refuses longitudes past 540° with a clear message. The motion-blur tool now lists the no-solution answer it gives at zero groundspeed among its errors. Both found by the fuzzer. Changelog
- 2026-09-24, changed: The overlap, union, and difference of two polygons (version 1.2.0) can now treat edges as straight in longitude and latitude, as most mapping software draws them, beside the geodesic edges it uses by default. The overlay is then done on the coordinates as written, and the areas follow those straight edges. Results with geodesic edges are unchanged. Changelog
- 2026-09-24, fixed: Check and repair a polygon (version 1.1.0) now returns pieces that touch at a single point as separate parts, as a valid polygon needs, where it used to join them into one ring touching itself; and it no longer repairs some small rings to nothing: a corner lying on another part of its own ring sits a fraction of a micron off it once projected, and the side test could step across. Corners that nearly touch another part of the ring are now put on it first, and crossing points that fall at one place are made one point. The overlay (version 1.1.1) gets the same crossing-point fix, for three edges crossing at one place. Checked against GEOS on 600 self-crossing rings; results for rings that do not touch themselves are unchanged. Changelog
- 2026-09-24, fixed: Overlap, union, or difference of two polygons (version 1.1.0) no longer loses or invents pieces where the polygons touch. A corner lying on the other polygon's edge, or on its own polygon's outline, sits a fraction of a micron off it once projected, and the side test could step across that gap: some unions came back empty and some differences a third too small. Corners within a millionth of the shapes' size (at most 1 mm) of another ring are now put on it first. Pieces that touch at a single point are now separate parts rather than one ring touching itself, which is not a valid polygon. Checked against GEOS on 400 pairs of touching and overlapping shapes through all four operations; results for polygons that do not touch are unchanged, and every earlier vector still passes. Changelog
Checked against: 36 golden test vectors (download the test vectors, each with its source and tolerance). See how results are checked and every source.
Sources
- Algorithms for geodesics, Karney, C. F. F., Journal of Geodesy, Vol. 87, No. 1. pp. 43-55 (direct and inverse problems; area of geodesic polygons, section 6).