How the ST_Intersection Geometry Tool works, and what it assumes

ST_Intersection(A, B) returns the points the two geometries share, as a new geometry. Two overlapping polygons give the overlapping area; a line and a polygon give the part of the line inside; two crossing lines give the crossing points. When the geometries share nothing, the result is an empty geometry, as it is in PostGIS.

Both inputs are checked for validity first. An overlay of an invalid polygon, such as one whose outline crosses itself, has no correct answer, so it is refused with the reason and its location, the same way PostGIS raises a TopologyException. A FeatureCollection of polygons is overlaid as the union of its polygons, and the page says so.

The calculation uses the coordinates as written, with straight edges, as PostGIS does for the geometry type. The result's area or length is then measured: geodesically for longitude and latitude, so you get square metres and kilometres rather than square degrees, and in the input's own units for projected data. The overlay itself always runs at full precision; the decimal places option only rounds the output.

Where this comes up in GIS work

  • Clipping a dataset to a study area or an administrative boundary.
  • Measuring how much of a parcel lies inside a flood zone or a conservation area.
  • Finding the length of a road, river or cable inside a region.
  • Getting the overlap between two service areas that should not overlap.

A worked example

Two 6 by 6 squares, offset by 3 in each direction:

A: POLYGON ((0 0, 6 0, 6 6, 0 6, 0 0))
B: POLYGON ((3 3, 9 3, 9 9, 3 9, 3 3))

ST_Intersection(A, B) = POLYGON ((3 6, 6 6, 6 3, 3 3, 3 6))

The shared part is the 3 by 3 square in the middle, area 9. A line through the 10 by 10 square, LINESTRING (-2 4, 12 4), gives LINESTRING (0 4, 10 4), the stretch inside it; two squares that do not meet give POLYGON EMPTY.

Using the ST_Intersection Geometry Tool

  1. Paste the first geometry into Geometry A, or select Load example.
  2. Paste the second geometry into Geometry B.
  3. Choose the output format and decimal places.
  4. Select Compute intersection, or press Ctrl + Enter (Cmd + Enter on a Mac).
  5. Check the plot and the measurements, then copy or download the result.

When the output looks wrong

The result is POLYGON EMPTY
The geometries do not share any point, or share only boundary points of a lower dimension. Check ST_Intersects first: if it is false, an empty intersection is the correct answer.
TopologyException: Input geom is invalid
One of the inputs is not a valid geometry, and the tool refuses it just as PostGIS does. The message names the problem and its location; fix it with the help of the Geometry Validator and try again.
The result is a line or a point instead of a polygon
Two polygons that only share an edge intersect in that edge, which is a line, and ones meeting at a corner intersect in a point. That is the correct result, not a failure.
The coordinates have long tails of decimals
Intersection points are calculated, so they rarely land on round numbers. Choose a number of decimal places to round the output; the calculation itself is always done at full precision.

Questions about the ST_Intersection Geometry Tool

What does ST_Intersection return?

The set of points A and B share, as a geometry: a polygon or multipolygon where areas overlap, lines where lines run through areas or along each other, and points where lines cross. When nothing is shared the result is empty.

Is the area of the result geodesic?

Yes, when the coordinates are longitude and latitude: the area and length are measured on the earth, not in square degrees. For projected coordinates they are given in the input's own units.

Are the edges treated as straight lines?

Yes, as PostGIS does for the geometry type: an edge is a straight line in the coordinates as written. For edges under a few hundred kilometres the difference from a great-circle edge is negligible.

Why was my FeatureCollection merged?

A collection of polygons is overlaid as the union of its polygons, because overlaying overlapping parts of one input would be undefined. The page says when this happens.

Is my data uploaded?

No. The overlay is computed in your browser.