How the ST_Crosses Geometry Checker works, and what it assumes
ST_Crosses(A, B) is true when a geometry passes through another of higher dimension, part inside and part outside, or when two lines cut across each other at points. It is defined for point and line, point and area, line and area, and line and line. Two areas cannot cross; they overlap instead.
The DE-9IM pattern depends on the pair. When A is the lower dimension it is T*T******: the interiors meet and part of A lies outside B. When A is the higher dimension it is T*****T**. For two lines it is 0********: their interiors meet, and only at points, because two lines sharing a stretch overlap rather than cross.
The explanation under the verdict covers the common reasons for a false answer: the line lies wholly inside the area, it only reaches the boundary, or the two geometries are of a kind that cannot cross. ST_Intersection gives the part of a line that lies inside an area.
Where this comes up in GIS work
- Finding roads, rivers or cables that pass through an administrative boundary or a protected area.
- Checking whether two routes cross each other rather than meeting at a junction.
- Validating that a network edge does not cut through a building footprint.
A worked example
A line that runs straight through a square:
A: LINESTRING (-2 4, 12 4)
B: POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))
ST_Crosses(A, B) = true
DE-9IM matrix: 101FF0212
The two diagonals of the square, LINESTRING (0 0, 10 10) and LINESTRING (0 10, 10 0), cross with the matrix 0F1FF0102: the leading 0 is the single crossing point. A line wholly inside the square, LINESTRING (2 2, 8 8), does not cross it (1FF0FF212): it is within it.
Using the ST_Crosses Geometry Checker
- Paste a line, or a set of points, into Geometry A, or select Load example.
- Paste the line or polygon it may cross into Geometry B.
- Select Check ST_Crosses, or press Ctrl + Enter (Cmd + Enter on a Mac).
- Read the verdict and its explanation. ST_Intersection gives the part of the line inside the polygon.
When the output looks wrong
- A line entirely inside a polygon does not cross it
- Crossing needs part of the line inside and part outside. A line wholly inside is within the polygon; one wholly outside is disjoint from it.
- Two overlapping polygons do not cross
- ST_Crosses is not defined for two areas: polygons overlap rather than cross. Use ST_Overlaps for that case.
- Two lines sharing a stretch of road do not cross
- Lines cross only when they meet at points. When they share a length of line, that is overlap, which ST_Overlaps reports as true.
- A line ending on the polygon's edge does not cross it
- It touches: its end point is on the boundary and it does not enter the interior. Extend it inside, and it crosses.
Questions about the ST_Crosses Geometry Checker
Which geometry combinations can cross?
Point with line, point with polygon, line with polygon, and line with line. For the first three, the lower-dimension geometry must be partly inside and partly outside the other; two lines cross when their interiors meet at points only.
What DE-9IM patterns does it use?
T*T****** when A is the lower dimension (point/line, point/area, line/area), T*****T** when A is the higher one, and 0******** for two lines.
Is ST_Crosses symmetric?
For two lines, yes. For mixed types PostGIS evaluates the pattern that fits the order of the arguments, and the answer for a line and a polygon comes out the same either way round.
Is my data uploaded?
No. Everything runs in your browser.