Model / geo · All operations

Combine or cut shapes

A variant of Work with geography

Take the intersection, difference or union of geometries, or clip one layer by another.

Status

In arcform

Runs as a SQL step

arcform carries it as a sql: step today, with the spatial extension.

The DuckDB step

Take the intersection, difference and union of shapes, and clip one layer by another

SQL
INSTALL spatial; LOAD spatial; SET geometry_always_xy = true;

CREATE TEMP TABLE a AS SELECT ST_GeomFromText('POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0))') AS geom;
CREATE TEMP TABLE b AS SELECT ST_GeomFromText('POLYGON ((2 2, 6 2, 6 6, 2 6, 2 2))') AS geom;
CREATE TEMP TABLE overlay AS
SELECT ST_Intersection(a.geom, b.geom) AS both_shapes, ST_Difference(a.geom, b.geom) AS only_a, ST_Union(a.geom, b.geom) AS either FROM a, b;
-- clip a layer of parcels by a window: keep the part of each parcel inside it, and drop the parcels that miss it
CREATE TEMP TABLE parcels AS SELECT * FROM (VALUES (1, ST_GeomFromText('POLYGON ((0 0, 2 0, 2 2, 0 2, 0 0))')), (2, ST_GeomFromText('POLYGON ((3 0, 6 0, 6 2, 3 2, 3 0))')), (3, ST_GeomFromText('POLYGON ((8 8, 9 8, 9 9, 8 9, 8 8))'))) t(id, geom);
CREATE TEMP TABLE clipped AS
SELECT p.id, ST_Intersection(p.geom, w.geom) AS geom FROM parcels p, (SELECT ST_MakeEnvelope(1, 0, 4, 5) AS geom) w WHERE ST_Intersects(p.geom, w.geom);
-- erase is the same layer cut the other way: what of each parcel lies outside the window
CREATE TEMP TABLE erased AS
SELECT p.id, ST_Difference(p.geom, w.geom) AS geom FROM parcels p, (SELECT ST_MakeEnvelope(1, 0, 4, 5) AS geom) w;
SELECT ST_Area(both_shapes) AS both_area, ST_Area(only_a) AS only_a_area, ST_Area(either) AS either_area FROM overlay;
SELECT id, ST_Area(geom) AS clipped_area FROM clipped ORDER BY id;
SELECT CASE WHEN ((SELECT ST_Area(both_shapes) = 4 AND ST_Equals(both_shapes, ST_GeomFromText('POLYGON ((2 2, 4 2, 4 4, 2 4, 2 2))')) AND ST_Area(only_a) = 12 AND ST_Area(either) = 28 AND ST_GeometryType(either) = 'POLYGON' FROM overlay)
  AND (SELECT count(*) = 2 AND list(id ORDER BY id) = [1, 2] AND list(ST_Area(geom) ORDER BY id) = [2.0, 2.0] FROM clipped)
  AND (SELECT list(ST_Area(geom) ORDER BY id) = [2.0, 4.0, 1.0] FROM erased)) THEN 'as expected' ELSE error('the squares should overlap in an area of 4, differ by 12 and join to 28, and the window should clip two parcels to an area of 2 each and drop the third') END AS verdict;
  • The statement builds its own data.
  • It needs the spatial extension.
  • The statement checks its own result and raises an error when it is wrong: “the squares should overlap in an area of 4, differ by 12 and join to 28, and the window should clip two parcels to an area of 2 each and drop the third”.
  • It passed on DuckDB v2.0.0 (Cyanoptera) d54cbbe3df.

What other tools call it

Meridian's classification; an independent blind rating agreed on 95.7% of 324 rows (variant, version 3).

Alteryx Designer (1)
  • Spatial Processread 2026-09-27

    Combine or cut spatial objects: intersection, difference, combine, inverse

Duckle (2)
  • Clip Geometryread 2026-09-25

    two-input overlay keeping the part of each geometry inside a clip layer

  • Erase Geometryread 2026-09-25

    two-input overlay subtracting an erase layer with ST_Difference

Ibis (4)
  • GeoDifferenceread 2026-09-27

    Part of the first geometry the second does not cover

  • GeoIntersectionread 2026-09-27

    Geometry that two geometries have in common

  • GeoUnaryUnionread 2026-09-27

    Aggregate a column of geometries into their union

  • GeoUnionread 2026-09-27

    Union of two geometries

Background

Vector overlay is an operation, or class of operations, in a geographic information system (GIS) for integrating two or more vector spatial data sets.[1] A vector overlay operation takes in layers of vector shapes and outputs a layer of new shapes created from the topological relationships between the inputs.[1] Some overlay operations, especially Intersect and Union, are implemented in all GIS software and used in a wide variety of analytical applications.[1]

When to use it

One of the most common uses of polygon overlay is suitability analysis: finding the region that meets a set of criteria, each of which can be represented by a region.[1] When each criterion is dissolved into a single region, each Boolean operator corresponds to one overlay operator: intersect is AND, union is OR, subtract is AND NOT and exclusive or is XOR.[1]

Unwanted narrow sliver polygons can occur when lines that should coincide, such as a river and a boundary that follows it, are digitised separately with slightly different vertices.[1] A snapping or fuzzy tolerance, a threshold distance within which pairs of lines are collapsed into one, was one of the earliest overlay parameters for avoiding sliver polygons.[1]

In PostGIS, ST_Difference is the only overlay function where input order matters: ST_Difference(A, B) always returns a portion of A.[2] In PostGIS, ST_Intersection returns an empty geometry of an appropriate type when the two geometries have no points in common.[3]

The method

The basic polygon overlay algorithm extracts the boundary lines of both layers, splits lines where they intersect, and builds a polygon from each minimal closed ring of lines.[1] Each polygon the overlay algorithm builds is a least common geographic unit (LCGU), with at most one parent polygon from each input, whose attributes it copies.[1] Overlay is based on areal integration, the geographic principle that different topics can be compared directly by a common location, and on set theory and point-set topology.[1]

In 1975, Thomas Peucker and Nicholas Chrisman of the Harvard Laboratory for Computer Graphics and Spatial Analysis introduced the POLYVRT data model, which represented topological relationships explicitly.[1] Nicholas Chrisman and James Dougenik implemented the LCGU strategy in the WHIRLPOOL program, released in 1979, and its algorithm became part of the core of GIS software for decades.[1]

Compared with the alternatives

Clip keeps the portions of one layer's polygons where they intersect the other layer, so its outline is the same as the intersection's but its interior holds only the first layer's polygons.[1] Subtract keeps only the portions of one layer's polygons that do not overlap the other layer.[1] Intersect and union are commutative and associative, while subtract and clip are neither.[1]

In PostGIS, the aggregate form of ST_Union merges the geometries of a set of rows into one result with no overlaps, operating on rows in the same way as SUM() and AVG().[4] In PostGIS, ST_Collect may sometimes replace ST_Union when the result need not be free of overlaps, and is usually faster because it does no processing on the geometries.[4]

Sources

  1. [1]Vector overlay - Wikipediasecondary source
  2. [2]ST_Differencedocumentation
  3. [3]ST_Intersectiondocumentation
  4. [4]ST_Uniondocumentation