geoprimsField-grade geospatial math

How two shapes relate

Whether two shapes (points, a line, or a polygon with holes) intersect, touch, cross, overlap, or lie one inside the other, with the matrix behind every answer, on geodesic or straight edges.

crosses

The first shape crosses the second.

Each test
TestAnswer
intersectsyes
disjointno
equalsno
withinno
containsno
touchesno
crossesyes
overlapsno
DE-9IM matrix
Provenance
Computed by
geometry.predicate.relate 1.0.0, core 0.1.0
Model
Both shapes noded against each other; the DE-9IM matrix read from every node (dimension 0), every edge piece between nodes (1), and both sides of every polygon edge piece (2), each located in both shapes; the named tests from the matrix patterns of OGC 06-103r4 (Simple feature access). Planar: straight edges in longitude and latitude, with Shewchuk's exact orientation test. Geodesic: edges cut into 5 km geodesic pieces on the ellipsoidal gnomonic plane at the shapes' center (Karney 2013), on an edge within 1 mm
Accuracy
Planar: exact for the coordinates as given. Geodesic: on an edge within 1 mm; geodesic pieces follow their chords to 0.05 mm within 1,000 km of the shapes' center
Notes
None
Cites
Open Geospatial Consortium, OpenGIS Implementation Specification for Geographic information - Simple feature access - Part 1: Common architecture; Shewchuk, J. R., Discrete & Computational Geometry, Adaptive precision floating-point arithmetic and fast robust geometric predicates; Karney, C. F. F., Journal of Geodesy, Algorithms for geodesics

Something look off?

Your values

Showing an example. Change anything.
KML, KMZ, GPX, GeoJSON, CSV, WKT, or WKB — or drop it on the box. Read on this device.
KML, KMZ, GPX, GeoJSON, CSV, WKT, or WKB — or drop it on the box. Read on this device.
More options 1
Run many at once from a CSV

Loading…

How we got thisFormula, worked example, sources, and proof

Model: Both shapes noded against each other; the DE-9IM matrix read from every node (dimension 0), every edge piece between nodes (1), and both sides of every polygon edge piece (2), each located in both shapes; the named tests from the matrix patterns of OGC 06-103r4 (Simple feature access). Planar: straight edges in longitude and latitude, with Shewchuk's exact orientation test. Geodesic: edges cut into 5 km geodesic pieces on the ellipsoidal gnomonic plane at the shapes' center (Karney 2013), on an edge within 1 mm

Accuracy: Planar: exact for the coordinates as given. Geodesic: on an edge within 1 mm; geodesic pieces follow their chords to 0.05 mm within 1,000 km of the shapes' center

When to use this: Use this to ask how two shapes sit against each other rather than how big their overlap is: whether a planned flight line crosses a restricted zone or only grazes its edge, whether a parcel lies wholly inside a district, whether two survey blocks share a boundary without overlapping, whether any of a set of points falls in an area. Every answer comes with the DE-9IM matrix, the standard nine-cell record of which parts meet, so the result can be checked against any GIS that follows the same standard.

Limitations: Inside here is strict, as in the standard: a point on a polygon's boundary is not within it, and a line along a polygon's edge touches it rather than lying inside. The shapes must be valid, with a polygon's holes inside its outline and no ring crossing itself or another; repair one first with the make-valid tool. A line is one unbranched path, and one that crosses itself is read as if it did not. Geodesic mode needs both shapes within 1,000 km of their shared center and treats places within a millimetre of an edge as on it; planar mode draws straight lines in longitude and latitude, which is what most GIS software does with unprojected data and which differs from the ground for long edges, most of all near the poles and for east-west edges.

Worked example: Does a flight line cross a restricted zone?. Source: GEOS 3.11.4 through shapely (the reference implementation of the DE-9IM) on the same gnomonic plane gives the matrix 101FF0212; the line enters the zone's west edge and leaves by its north edge. It is golden test vector v001, and every build checks the tool still gives its answer within its tolerance.

You enter

First shape
40.001, -105.004 40.009, -104.991
Second shape
40, -105 40, -104.99 40.006, -104.99 40.006, -105
First shape is
line
Second shape is
polygon

You get

Relation
crosses
DE-9IM matrix
101FF0212

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.0.0, core 0.1.0. See this tool in the verification report.

Checked against: 35 golden test vectors (download the test vectors, each with its source and tolerance). See how results are checked and every source.

Sources

Terms

DE-9IM: Dimensionally Extended Nine-Intersection Model
A nine-cell record of how two shapes meet: whether each one's inside, edge, and outside touches each of the other's, and whether they meet at points, along lines, or over an area. Source: OGC Simple Feature Access, Part 1: Common Architecture

DE-9IM — Dimensionally Extended Nine-Intersection Model

A nine-cell record of how two shapes meet: whether each one's inside, edge, and outside touches each of the other's, and whether they meet at points, along lines, or over an area.

Source: OGC Simple Feature Access, Part 1: Common Architecture