The functions in this section answer a question about a geometry rather than about a temporal type. Each states how it reads a geometry bounded by circular arcs, since an answer built from the arcs themselves and an answer built from a polygonal approximation of them are not the same answer.
Return the rectangle of minimum area enclosing a geometry
orientedEnvelope(geometry) → geometry
The rectangle is at the angle that makes it smallest, which is not in general the angle of the axes. It is answered as a line when the geometry is contained in one and as a point when the geometry is one. A geometry carrying a circular arc is answered on the arc itself, the rectangle being placed against the circle the arc lies on rather than against the chain of segments approximating it.
SELECT ST_AsText(round(orientedEnvelope(geometry 'Polygon((0 0,3 4,-1 7,-4 3,0 0))'), 6)); -- POLYGON((0 0,3 4,-1 7,-4 3,0 0)) SELECT ST_AsText(round(orientedEnvelope(geometry 'Linestring(0 0,10 0)'), 6)); -- LINESTRING(0 0,10 0) SELECT ST_AsText(round(orientedEnvelope(geometry 'Circularstring(0 0,0.5 0.1,1 0)'), 6)); -- POLYGON((1 0.1,0 0.1,0 0,1 0,1 0.1))
Return the smallest convex geometry enclosing a geometry
convexHull(geometry) → geometry
The result is a polygon whose every corner is a point of the geometry, a line when the geometry is contained in one, and a point when the geometry is one. A geometry carrying a circular arc is answered on the arc itself, so the hull is bounded by the arc and is returned as a curved geometry rather than as a polygon approximating it.
SELECT ST_AsText(round(convexHull(geometry 'Multipoint(0 0,10 0,10 10,0 10,5 5)'), 6)); -- POLYGON((0 0,0 10,10 10,10 0,0 0)) SELECT ST_AsText(round(convexHull(geometry 'Polygon((0 0,10 0,10 10,5 5,0 10,0 0))'), 6)); -- POLYGON((0 0,0 10,10 10,10 0,0 0)) SELECT ST_AsText(round(convexHull(geometry 'Circularstring(5 0,0 5,-5 0)'), 6)); -- CURVEPOLYGON(COMPOUNDCURVE((5 0,-5 0),CIRCULARSTRING(-5 0,0 5,5 0)))
Return true if a geometry has no point at which it crosses or touches itself
isSimple(geometry) → boolean
A point is always simple, a multipoint is simple when it repeats no point, a line is simple when it meets itself only where two of its segments follow one another and, when it closes, at the point where it closes, and an areal geometry is simple when each of its rings is. Two lines of a multiline may additionally meet at a point that ends both. A geometry carrying a circular arc meets itself along an arc rather than at a point, which the segment intersection this rests on does not read, so such a geometry is answered on the chain of segments approximating its arcs.
SELECT isSimple(geometry 'Linestring(0 0,10 10,10 0,0 10)'); -- false SELECT isSimple(geometry 'Linestring(0 0,10 0,10 10,0 0)'); -- true SELECT isSimple(geometry 'Multilinestring((0 0,10 0),(10 0,10 10))'); -- true
Return the geometry holding every point within a distance of a geometry
buffer(geometry,float,options text='') → geometry
The boundary of the result is made of the two offsets of the geometry at the given distance, of the join filling the outer side of each turn, and of the cap closing each end of an open line. A negative distance shrinks an areal geometry and answers an empty geometry for one of any other dimension. The options string carries the styles as space-separated key=value pairs: endcap is one of round, flat or square, join one of round, mitre or bevel, and mitre_limit the ratio at which a mitre join falls back to a bevel.
SELECT ST_AsText(round(buffer(geometry 'Point(0 0)', 1), 6)); -- CURVEPOLYGON(CIRCULARSTRING(-1 0,1 0,-1 0)) SELECT ST_AsText(round(buffer(geometry 'Polygon((0 0,10 0,10 10,0 10,0 0))', -1, 'join=mitre'), 6)); -- CURVEPOLYGON(COMPOUNDCURVE((1 1,9 1),(9 1,9 9),(9 9,1 9),(1 9,1 1))) SELECT ST_AsText(round(buffer(geometry 'Curvepolygon(Circularstring(0 0,2 2,4 0,2 -2, 0 0))', 1), 6)); -- CURVEPOLYGON(COMPOUNDCURVE(CIRCULARSTRING(-1 0,2 3,5 0),CIRCULARSTRING(5 0,2 -3,-1 0)))
Return the region two geometries share
intersection(geometry,geometry) → geometry
The four Boolean operations of this section answer over the (multi)polygons the temporal types whose values are regions carry, and each takes the name of the PostGIS function it answers for without the ST_ prefix, so a query reaches this engine by dropping the prefix and PostGIS by keeping it. They are planar and two-dimensional: a geography, a Z dimension and a geometry that is not a (multi)polygon are refused. An empty result is answered as NULL.
SELECT ST_AsText(intersection(geometry 'Polygon((1 1,1 5,5 5,5 1,1 1))', geometry 'Polygon((3 3,3 7,7 7,7 3,3 3))')); -- POLYGON((5 3,3 3,3 5,5 5,5 3)) SELECT ST_AsText(intersection(geometry 'Polygon((1 1,1 5,5 5,5 1,1 1))', geometry 'MultiPolygon(((2 2,2 4,3 4,3 2,2 2)),((4 2,4 4,6 4,6 2,4 2)))')); -- MULTIPOLYGON(((3 2,2 2,2 4,3 4,3 2)),((5 2,4 2,4 4,5 4,5 2))) SELECT intersection(geometry 'Polygon((1 1,1 2,2 2,2 1,1 1))', geometry 'Polygon((10 10,10 11,11 11,11 10,10 10))') IS NULL; -- true
Return the region two geometries cover together
geoUnion(geometry,geometry) → geometry
UNION is a reserved word of SQL, so this one carries the name of the type it answers over, as setUnion and spanUnion do. Two geometries that do not meet are answered as a multipolygon.
SELECT ST_AsText(geoUnion(geometry 'Polygon((1 1,1 5,5 5,5 1,1 1))', geometry 'Polygon((3 3,3 7,7 7,7 3,3 3))')); -- POLYGON((5 1,1 1,1 5,3 5,3 7,7 7,7 3,5 3,5 1))
Return the region of the first geometry that the second does not cover
difference(geometry,geometry) → geometry
A second geometry lying inside the first leaves a hole rather than dividing it.
SELECT ST_AsText(difference(geometry 'Polygon((1 1,1 5,5 5,5 1,1 1))', geometry 'Polygon((3 3,3 7,7 7,7 3,3 3))')); -- POLYGON((5 1,1 1,1 5,3 5,3 3,5 3,5 1)) SELECT ST_AsText(difference(geometry 'Polygon((1 1,1 5,5 5,5 1,1 1))', geometry 'Polygon((2 2,2 4,4 4,4 2,2 2))')); -- POLYGON((5 1,1 1,1 5,5 5,5 1),(2 4,2 2,4 2,4 4,2 4))
Return the region exactly one of two geometries covers
symDifference(geometry,geometry) → geometry
It is the union of the two geometries less the region they share, so a geometry against itself is answered as NULL.
SELECT ST_AsText(symDifference(geometry 'Polygon((1 1,1 5,5 5,5 1,1 1))', geometry 'Polygon((3 3,3 7,7 7,7 3,3 3))')); -- MULTIPOLYGON(((7 3,5 3,5 5,3 5,3 7,7 7,7 3)),((5 1,1 1,1 5,3 5,3 3,5 3,5 1))) SELECT symDifference(geometry 'Polygon((1 1,1 3,3 3,3 1,1 1))', geometry 'Polygon((1 1,1 3,3 3,3 1,1 1))') IS NULL; -- true