PostGIS
Chapter 8. PostGIS Reference
Table of Contents
The functions given below are the ones which a user of PostGIS is likely to need. There are other functions which are required support functions to the PostGIS objects which are not of use to a general user.
|
8.1. PostGIS Geometry/Geography/Box Data Types
Abstract
This section lists the custom PostgreSQL data types installed by PostGIS to represent spatial data.
Each data type describes its type casting behavior. A type cast converts values of one data type into another type. PostgreSQL allows defining casting behavior for custom types, along with the functions used to convert type values. Casts can have automatic behavior, which allows automatic conversion of a function argument to a type supported by the function.
Some casts have explicit behavior, which means the cast must
be specified using the syntax CAST(myval As sometype)
or
myval::sometype
. Explicit casting avoids the issue of ambiguous
casts, which can occur when using an overloaded function which does not
support a given type. For example, a function may accept a box2d or a
box3d, but not a geometry. Since geometry has an automatic cast to both
box types, this produces an "ambiguous function" error. To prevent the
error use an explicit cast to the desired box type.
All data types can be cast to text
, so this does not need to be
specified explicitly.
box2d[.refpurpose]# — The type representing a 2-dimensional bounding box. #
box3d[.refpurpose]# — The type representing a 3-dimensional bounding box. #
geometry[.refpurpose]# — The type representing spatial features with planar coordinate systems.#
geometry_dump[.refpurpose]# — A composite type used to describe the parts of complex geometry.#
geography[.refpurpose]# — The type representing spatial features with geodetic (ellipsoidal) coordinate systems.#
8.2. Table Management Functions
Abstract
These functions assist in defining tables containing geometry columns.
AddGeometryColumn[.refpurpose]# — Adds a geometry column to an existing table.#
DropGeometryColumn[.refpurpose]# — Removes a geometry column from a spatial table.#
DropGeometryTable[.refpurpose]# — Drops a table and all its references in geometry_columns.#
Find_SRID[.refpurpose]# — Returns the SRID defined for a geometry column.#
Populate_Geometry_Columns[.refpurpose]# — Ensures geometry columns are defined with type modifiers or have appropriate spatial constraints.#
UpdateGeometrySRID[.refpurpose]# — Updates the SRID of all features in a geometry column, and the table metadata. #
8.3. Geometry Constructors
ST_Collect[.refpurpose]# — Creates a GeometryCollection or Multi* geometry from a set of geometries.#
ST_LineFromMultiPoint[.refpurpose]# — Creates a LineString from a MultiPoint geometry.#
ST_MakeEnvelope[.refpurpose]# — Creates a rectangular Polygon from minimum and maximum coordinates.#
ST_MakeLine[.refpurpose]# — Creates a LineString from Point, MultiPoint, or LineString geometries.#
ST_MakePoint[.refpurpose]# — Creates a 2D, 3DZ or 4D Point.#
ST_MakePointM[.refpurpose]# — Creates a Point from X, Y and M values.#
ST_MakePolygon[.refpurpose]# — Creates a Polygon from a shell and optional list of holes.#
ST_Point[.refpurpose]# — Creates a Point with X, Y and SRID values.#
ST_PointZ[.refpurpose]# — Creates a Point with X, Y, Z and SRID values.#
ST_PointM[.refpurpose]# — Creates a Point with X, Y, M and SRID values.#
ST_PointZM[.refpurpose]# — Creates a Point with X, Y, Z, M and SRID values.#
ST_Polygon[.refpurpose]# — Creates a Polygon from a LineString with a specified SRID.#
ST_TileEnvelope[.refpurpose]# — Creates a rectangular Polygon in Web Mercator (SRID:3857) using the XYZ tile system.#
ST_HexagonGrid[.refpurpose]# — Returns a set of hexagons and cell indices that completely cover the bounds of the geometry argument.#
ST_Hexagon[.refpurpose]# — Returns a single hexagon, using the provided edge size and cell coordinate within the hexagon grid space.#
ST_SquareGrid[.refpurpose]# — Returns a set of grid squares and cell indices that completely cover the bounds of the geometry argument.#
ST_Square[.refpurpose]# — Returns a single square, using the provided edge size and cell coordinate within the square grid space.#
ST_Letters[.refpurpose]# — Returns the input letters rendered as geometry with a default start position at the origin and default text height of 100.#
8.4. Geometry Accessors
GeometryType[.refpurpose]# — Returns the type of a geometry as text.#
ST_Boundary[.refpurpose]# — Returns the boundary of a geometry.#
ST_BoundingDiagonal[.refpurpose]# — Returns the diagonal of a geometry’s bounding box.#
ST_CoordDim[.refpurpose]# — Return the coordinate dimension of a geometry.#
ST_Dimension[.refpurpose]# — Returns the topological dimension of a geometry. #
ST_Dump[.refpurpose]# — Returns a
set of geometry_dump
rows for the components of a geometry.#
ST_DumpPoints[.refpurpose]# —
Returns a set of geometry_dump
rows for the coordinates in a
geometry.#
ST_DumpSegments[.refpurpose]#
— Returns a set of geometry_dump
rows for the segments in a
geometry.#
ST_DumpRings[.refpurpose]# —
Returns a set of geometry_dump
rows for the exterior and interior
rings of a Polygon.#
ST_EndPoint[.refpurpose]# — Returns the last point of a LineString or CircularLineString.#
ST_Envelope[.refpurpose]# — Returns a geometry representing the bounding box of a geometry.#
ST_ExteriorRing[.refpurpose]# — Returns a LineString representing the exterior ring of a Polygon. #
ST_GeometryN[.refpurpose]# — Return an element of a geometry collection.#
ST_GeometryType[.refpurpose]# — Returns the SQL-MM type of a geometry as text.#
ST_HasArc[.refpurpose]# — Tests if a geometry contains a circular arc#
ST_InteriorRingN[.refpurpose]# — Returns the Nth interior ring (hole) of a Polygon.#
ST_IsClosed[.refpurpose]# — Tests if a LineStrings’s start and end points are coincident. For a PolyhedralSurface tests if it is closed (volumetric). #
ST_IsCollection[.refpurpose]# — Tests if a geometry is a geometry collection type.#
ST_IsEmpty[.refpurpose]# — Tests if a geometry is empty.#
[.refpurpose] — Tests if Polygons have exterior rings oriented counter-clockwise and interior rings oriented clockwise. #
[.refpurpose] — Tests if Polygons have exterior rings oriented clockwise and interior rings oriented counter-clockwise. #
ST_IsRing[.refpurpose]# — Tests if a LineString is closed and simple.#
ST_IsSimple[.refpurpose]# — Tests if a geometry has no points of self-intersection or self-tangency.#
ST_M[.refpurpose]# — Returns the M coordinate of a Point.#
ST_MemSize[.refpurpose]# — Returns the amount of memory space a geometry takes.#
ST_NDims[.refpurpose]# — Returns the coordinate dimension of a geometry.#
ST_NPoints[.refpurpose]# — Returns the number of points (vertices) in a geometry.#
ST_NRings[.refpurpose]# — Returns the number of rings in a polygonal geometry.#
ST_NumGeometries[.refpurpose]# — Returns the number of elements in a geometry collection.#
ST_NumInteriorRings[.refpurpose]# — Returns the number of interior rings (holes) of a Polygon.#
ST_NumInteriorRing[.refpurpose]# — Returns the number of interior rings (holes) of a Polygon. Aias for ST_NumInteriorRings#
ST_NumPatches[.refpurpose]# — Return the number of faces on a Polyhedral Surface. Will return null for non-polyhedral geometries.#
ST_NumPoints[.refpurpose]# — Returns the number of points in a LineString or CircularString.#
ST_PatchN[.refpurpose]# — Returns the Nth geometry (face) of a PolyhedralSurface.#
ST_PointN[.refpurpose]# — Returns the Nth point in the first LineString or circular LineString in a geometry. #
ST_Points[.refpurpose]# — Returns a MultiPoint containing the coordinates of a geometry. #
ST_StartPoint[.refpurpose]# — Returns the first point of a LineString.#
ST_Summary[.refpurpose]# — Returns a text summary of the contents of a geometry. #
ST_X[.refpurpose]# — Returns the X coordinate of a Point.#
ST_Y[.refpurpose]# — Returns the Y coordinate of a Point.#
ST_Z[.refpurpose]# — Returns the Z coordinate of a Point.#
ST_Zmflag[.refpurpose]# — Returns a code indicating the ZM coordinate dimension of a geometry.#
8.5. Geometry Editors
Abstract
These functions create modified geometries by changing type, structure or vertices.
ST_AddPoint[.refpurpose]# — Add a point to a LineString.#
ST_CollectionExtract[.refpurpose]# — Given a geometry collection, returns a multi-geometry containing only elements of a specified type. #
ST_CollectionHomogenize[.refpurpose]# — Returns the simplest representation of a geometry collection. #
ST_CurveToLine[.refpurpose]# — Converts a geometry containing curves to a linear geometry.#
ST_Scroll[.refpurpose]# — Change start point of a closed LineString.#
ST_FlipCoordinates[.refpurpose]# — Returns a version of a geometry with X and Y axis flipped. #
ST_Force2D[.refpurpose]# — Force the geometries into a "2-dimensional mode".#
ST_Force3D[.refpurpose]# — Force the geometries into XYZ mode. This is an alias for ST_Force3DZ.#
ST_Force3DZ[.refpurpose]# — Force the geometries into XYZ mode.#
ST_Force3DM[.refpurpose]# — Force the geometries into XYM mode.#
ST_Force4D[.refpurpose]# — Force the geometries into XYZM mode. #
[.refpurpose] — Orients all exterior rings counter-clockwise and all interior rings clockwise. #
ST_ForceCollection[.refpurpose]# — Convert the geometry into a GEOMETRYCOLLECTION.#
[.refpurpose] — Orients all exterior rings clockwise and all interior rings counter-clockwise. #
ST_ForceSFS[.refpurpose]# — Force the geometries to use SFS 1.1 geometry types only.#
ST_ForceRHR[.refpurpose]# — Force the orientation of the vertices in a polygon to follow the Right-Hand-Rule.#
ST_ForceCurve[.refpurpose]# — Upcast a geometry into its curved type, if applicable.#
ST_LineToCurve[.refpurpose]# — Converts a linear geometry to a curved geometry.#
ST_Multi[.refpurpose]# — Return the geometry as a MULTI* geometry.#
ST_Normalize[.refpurpose]# — Return the geometry in its canonical form.#
[.refentrytitle]# ST_QuantizeCoordinates [.refpurpose] — Sets least significant bits of coordinates to zero #
ST_RemovePoint[.refpurpose]# — Remove a point from a linestring.#
ST_RemoveRepeatedPoints[.refpurpose]# — Returns a version of a geometry with duplicate points removed.#
ST_Reverse[.refpurpose]# — Return the geometry with vertex order reversed.#
ST_Segmentize[.refpurpose]# — Return a modified geometry/geography having no segment longer than the given distance.#
ST_SetPoint[.refpurpose]# — Replace point of a linestring with a given point.#
ST_ShiftLongitude[.refpurpose]# — Shifts the longitude coordinates of a geometry between -180..180 and 0..360.#
ST_WrapX[.refpurpose]# — Wrap a geometry around an X value.#
ST_SnapToGrid[.refpurpose]# — Snap all points of the input geometry to a regular grid. #
ST_Snap[.refpurpose]# — Snap segments and vertices of input geometry to vertices of a reference geometry. #
ST_SwapOrdinates[.refpurpose]# — Returns a version of the given geometry with given ordinate values swapped. #
8.6. Geometry Validation
Abstract
These functions test whether geometries are valid according to the OGC SFS standard. They also provide information about the nature and location of invalidity. There is also a function to create a valid geometry out of an invalid one.
ST_IsValid[.refpurpose]# — Tests if a geometry is well-formed in 2D. #
ST_IsValidDetail[.refpurpose]#
— Returns a valid_detail
row stating if a geometry is valid or if
not a reason and a location.#
ST_IsValidReason[.refpurpose]# — Returns text stating if a geometry is valid, or a reason for invalidity.#
ST_MakeValid[.refpurpose]# — Attempts to make an invalid geometry valid without losing vertices.#
8.7. Spatial Reference System Functions
Abstract
These functions work with the Spatial Reference System of geometries as
defined in the spatial_ref_sys
table.
ST_SetSRID[.refpurpose]# — Set the SRID on a geometry.#
ST_SRID[.refpurpose]# — Returns the spatial reference identifier for a geometry.#
ST_Transform[.refpurpose]# — Return a new geometry with coordinates transformed to a different spatial reference system.#
8.8. Geometry Input
Abstract
These functions create geometry objects from various textual or binary formats.
8.8.1. Well-Known Text (WKT)
ST_BdPolyFromText[.refpurpose]# — Construct a Polygon given an arbitrary collection of closed linestrings as a MultiLineString Well-Known text representation.#
ST_BdMPolyFromText[.refpurpose]# — Construct a MultiPolygon given an arbitrary collection of closed linestrings as a MultiLineString text representation Well-Known text representation.#
ST_GeogFromText[.refpurpose]# — Return a specified geography value from Well-Known Text representation or extended (WKT). #
ST_GeographyFromText[.refpurpose]# — Return a specified geography value from Well-Known Text representation or extended (WKT). #
ST_GeomCollFromText[.refpurpose]# — Makes a collection Geometry from collection WKT with the given SRID. If SRID is not given, it defaults to 0.#
ST_GeomFromEWKT[.refpurpose]# — Return a specified ST_Geometry value from Extended Well-Known Text representation (EWKT).#
ST_GeomFromMARC21[.refpurpose]# — Takes MARC21/XML geographic data as input and returns a PostGIS geometry object. #
ST_GeometryFromText[.refpurpose]# — Return a specified ST_Geometry value from Well-Known Text representation (WKT). This is an alias name for ST_GeomFromText#
ST_GeomFromText[.refpurpose]# — Return a specified ST_Geometry value from Well-Known Text representation (WKT).#
ST_LineFromText[.refpurpose]# — Makes a Geometry from WKT representation with the given SRID. If SRID is not given, it defaults to 0.#
ST_MLineFromText[.refpurpose]# — Return a specified ST_MultiLineString value from WKT representation.#
ST_MPointFromText[.refpurpose]# — Makes a Geometry from WKT with the given SRID. If SRID is not given, it defaults to 0.#
ST_MPolyFromText[.refpurpose]# — Makes a MultiPolygon Geometry from WKT with the given SRID. If SRID is not given, it defaults to 0.#
ST_PointFromText[.refpurpose]# — Makes a point Geometry from WKT with the given SRID. If SRID is not given, it defaults to unknown.#
ST_PolygonFromText[.refpurpose]# — Makes a Geometry from WKT with the given SRID. If SRID is not given, it defaults to 0.#
ST_WKTToSQL[.refpurpose]# — Return a specified ST_Geometry value from Well-Known Text representation (WKT). This is an alias name for ST_GeomFromText#
8.8.2. Well-Known Binary (WKB)
ST_GeogFromWKB[.refpurpose]# — Creates a geography instance from a Well-Known Binary geometry representation (WKB) or extended Well Known Binary (EWKB).#
ST_GeomFromEWKB[.refpurpose]# — Return a specified ST_Geometry value from Extended Well-Known Binary representation (EWKB).#
ST_GeomFromWKB[.refpurpose]# — Creates a geometry instance from a Well-Known Binary geometry representation (WKB) and optional SRID.#
ST_LineFromWKB[.refpurpose]#
— Makes a LINESTRING
from WKB with the given SRID#
ST_LinestringFromWKB[.refpurpose]# — Makes a geometry from WKB with the given SRID.#
ST_PointFromWKB[.refpurpose]# — Makes a geometry from WKB with the given SRID#
ST_WKBToSQL[.refpurpose]# — Return a specified ST_Geometry value from Well-Known Binary representation (WKB). This is an alias name for ST_GeomFromWKB that takes no srid#
8.8.3. Other Formats
ST_Box2dFromGeoHash[.refpurpose]# — Return a BOX2D from a GeoHash string.#
ST_GeomFromGeoHash[.refpurpose]# — Return a geometry from a GeoHash string.#
ST_GeomFromGML[.refpurpose]# — Takes as input GML representation of geometry and outputs a PostGIS geometry object#
ST_GeomFromGeoJSON[.refpurpose]# — Takes as input a geojson representation of a geometry and outputs a PostGIS geometry object#
ST_GeomFromKML[.refpurpose]# — Takes as input KML representation of geometry and outputs a PostGIS geometry object#
ST_GeomFromTWKB[.refpurpose]# — Creates a geometry instance from a TWKB ("Tiny Well-Known Binary") geometry representation.#
ST_GMLToSQL[.refpurpose]# — Return a specified ST_Geometry value from GML representation. This is an alias name for ST_GeomFromGML#
ST_LineFromEncodedPolyline[.refpurpose]# — Creates a LineString from an Encoded Polyline.#
ST_PointFromGeoHash[.refpurpose]# — Return a point from a GeoHash string.#
ST_FromFlatGeobufToTable[.refpurpose]# — Creates a table based on the structure of FlatGeobuf data.#
ST_FromFlatGeobuf[.refpurpose]# — Reads FlatGeobuf data.#
8.9. Geometry Output
Abstract
These functions convert geometry objects into various textual or binary formats.
8.9.2. Well-Known Binary (WKB)
ST_AsBinary[.refpurpose]# — Return the OGC/ISO Well-Known Binary (WKB) representation of the geometry/geography without SRID meta data.#
ST_AsEWKB[.refpurpose]# — Return the Extended Well-Known Binary (EWKB) representation of the geometry with SRID meta data.#
ST_AsHEXEWKB[.refpurpose]# — Returns a Geometry in HEXEWKB format (as text) using either little-endian (NDR) or big-endian (XDR) encoding.#
8.9.3. Other Formats
ST_AsEncodedPolyline[.refpurpose]# — Returns an Encoded Polyline from a LineString geometry.#
ST_AsFlatGeobuf[.refpurpose]# — Return a FlatGeobuf representation of a set of rows.#
ST_AsGeobuf[.refpurpose]# — Return a Geobuf representation of a set of rows.#
ST_AsGeoJSON[.refpurpose]# — Return a geometry as a GeoJSON element.#
ST_AsGML[.refpurpose]# — Return the geometry as a GML version 2 or 3 element.#
ST_AsKML[.refpurpose]# — Return the geometry as a KML element.#
ST_AsLatLonText[.refpurpose]# — Return the Degrees, Minutes, Seconds representation of the given point.#
ST_AsMARC21[.refpurpose]# — Returns geometry as a MARC21/XML record with a geographic datafield (034).#
ST_AsMVTGeom[.refpurpose]# — Transforms a geometry into the coordinate space of a MVT tile.#
ST_AsMVT[.refpurpose]# — Aggregate function returning a MVT representation of a set of rows.#
ST_AsSVG[.refpurpose]# — Returns SVG path data for a geometry.#
ST_AsTWKB[.refpurpose]# — Returns the geometry as TWKB, aka "Tiny Well-Known Binary"#
ST_AsX3D[.refpurpose]# — Returns a Geometry in X3D xml node element format: ISO-IEC-19776-1.2-X3DEncodings-XML#
ST_GeoHash[.refpurpose]# — Return a GeoHash representation of the geometry.#
8.10.1. Bounding Box Operators
&&[.refpurpose]# —
Returns TRUE
if A’s 2D bounding box intersects B’s 2D bounding box.#
&&(geometry,box2df)[.refpurpose]#
— Returns TRUE
if a geometry’s (cached) 2D bounding box intersects a
2D float precision bounding box (BOX2DF).#
&&(box2df,geometry)[.refpurpose]#
— Returns TRUE
if a 2D float precision bounding box (BOX2DF)
intersects a geometry’s (cached) 2D bounding box.#
&&(box2df,box2df)[.refpurpose]#
— Returns TRUE
if two 2D float precision bounding boxes (BOX2DF)
intersect each other.#
&&&[.refpurpose]# —
Returns TRUE
if A’s n-D bounding box intersects B’s n-D bounding
box.#
&&&(geometry,gidx)[.refpurpose]#
— Returns TRUE
if a geometry’s (cached) n-D bounding box intersects
a n-D float precision bounding box (GIDX).#
&&&(gidx,geometry)[.refpurpose]#
— Returns TRUE
if a n-D float precision bounding box (GIDX)
intersects a geometry’s (cached) n-D bounding box.#
&&&(gidx,gidx)[.refpurpose]#
— Returns TRUE
if two n-D float precision bounding boxes (GIDX)
intersect each other.#
&<[.refpurpose]# —
Returns TRUE
if A’s bounding box overlaps or is to the left of B’s.#
&<|[.refpurpose]# —
Returns TRUE
if A’s bounding box overlaps or is below B’s.#
&>[.refpurpose]# —
Returns TRUE
if A' bounding box overlaps or is to the right of B’s.#
<<[.refpurpose]# — Returns
TRUE
if A’s bounding box is strictly to the left of B’s.#
<<|[.refpurpose]# —
Returns TRUE
if A’s bounding box is strictly below B’s.#
=[.refpurpose]# — Returns
TRUE
if the coordinates and coordinate order geometry/geography A
are the same as the coordinates and coordinate order of
geometry/geography B.#
>>[.refpurpose]# —
Returns TRUE
if A’s bounding box is strictly to the right of B’s.#
@[.refpurpose]# —
Returns TRUE
if A’s bounding box is contained by B’s.#
@(geometry,box2df)[.refpurpose]#
— Returns TRUE
if a geometry’s 2D bounding box is contained into a
2D float precision bounding box (BOX2DF).#
@(box2df,geometry)[.refpurpose]#
— Returns TRUE
if a 2D float precision bounding box (BOX2DF) is
contained into a geometry’s 2D bounding box.#
@(box2df,box2df)[.refpurpose]#
— Returns TRUE
if a 2D float precision bounding box (BOX2DF) is
contained into another 2D float precision bounding box.#
|&>[.refpurpose]# —
Returns TRUE
if A’s bounding box overlaps or is above B’s.#
|>>[.refpurpose]# —
Returns TRUE
if A’s bounding box is strictly above B’s.#
~[.refpurpose]# —
Returns TRUE
if A’s bounding box contains B’s.#
~(geometry,box2df)[.refpurpose]#
— Returns TRUE
if a geometry’s 2D bonding box contains a 2D float
precision bounding box (GIDX).#
~(box2df,geometry)[.refpurpose]#
— Returns TRUE
if a 2D float precision bounding box (BOX2DF)
contains a geometry’s 2D bonding box.#
~(box2df,box2df)[.refpurpose]#
— Returns TRUE
if a 2D float precision bounding box (BOX2DF)
contains another 2D float precision bounding box (BOX2DF).#
~=[.refpurpose]# — Returns
TRUE
if A’s bounding box is the same as B’s.#
8.10.2. Distance Operators
<→[.refpurpose]# — Returns the 2D distance between A and B. #
|=|[.refpurpose]# — Returns the distance between A and B trajectories at their closest point of approach. #
<>[.refpurpose] — Returns the 2D distance between A and B bounding boxes. #
<<→>[.refpurpose]# — Returns the n-D distance between the centroids of A and B bounding boxes. #
<<>>[.refpurpose] — Returns the n-D distance between A and B bounding boxes. #
8.11. Spatial Relationships
Abstract
These functions determine spatial relationships between geometries.
8.11.1. Topological Relationships
ST_3DIntersects[.refpurpose]# — Tests if two geometries spatially intersect in 3D - only for points, linestrings, polygons, polyhedral surface (area). #
ST_Contains[.refpurpose]# — Tests if no points of B lie in the exterior of A, and A and B have at least one interior point in common. #
ST_ContainsProperly[.refpurpose]# — Tests if B intersects the interior of A but not the boundary or exterior. #
ST_CoveredBy[.refpurpose]# — Tests if no point in A is outside B#
ST_Covers[.refpurpose]# — Tests if no point in B is outside A#
ST_Crosses[.refpurpose]# — Tests if two geometries have some, but not all, interior points in common.#
ST_Disjoint[.refpurpose]# — Tests if two geometries are disjoint (they have no point in common). #
ST_Equals[.refpurpose]# — Tests if two geometries include the same set of points.#
ST_Intersects[.refpurpose]# — Tests if two geometries intersect (they have at least one point in common). #
ST_LineCrossingDirection[.refpurpose]# — Returns a number indicating the crossing behavior of two LineStrings.#
ST_OrderingEquals[.refpurpose]# — Tests if two geometries represent the same geometry and have points in the same directional order.#
ST_Overlaps[.refpurpose]# — Tests if two geometries intersect and have the same dimension, but are not completely contained by each other.#
ST_Relate[.refpurpose]# — Tests if two geometries have a topological relationship matching an Intersection Matrix pattern, or computes their Intersection Matrix #
ST_RelateMatch[.refpurpose]# — Tests if a DE-9IM Intersection Matrix matches an Intersection Matrix pattern #
ST_Touches[.refpurpose]# — Tests if two geometries have at least one point in common, but their interiors do not intersect.#
ST_Within[.refpurpose]# — Tests if no points of A lie in the exterior of B, and A and B have at least one interior point in common.#
8.11.2. Distance Relationships
ST_3DDWithin[.refpurpose]# — Tests if two 3D geometries are within a given 3D distance#
ST_3DDFullyWithin[.refpurpose]# — Tests if two 3D geometries are entirely within a given 3D distance#
ST_DFullyWithin[.refpurpose]# — Tests if two geometries are entirely within a given distance#
ST_DWithin[.refpurpose]# — Tests if two geometries are within a given distance#
ST_PointInsideCircle[.refpurpose]# — Tests if a point geometry is inside a circle defined by a center and radius.#
8.12. Measurement Functions
Abstract
These functions compute measurements of distance, area and angles. There are also functions to compute geometry values determined by measurements.
ST_Area[.refpurpose]# — Returns the area of a polygonal geometry. #
ST_Azimuth[.refpurpose]# — Returns the north-based azimuth of a line between two points.#
ST_Angle[.refpurpose]# — Returns the angle between two vectors defined by 3 or 4 points, or 2 lines.#
ST_ClosestPoint[.refpurpose]# — Returns the 2D point on g1 that is closest to g2. This is the first point of the shortest line from one geometry to the other.#
ST_3DClosestPoint[.refpurpose]# — Returns the 3D point on g1 that is closest to g2. This is the first point of the 3D shortest line. #
ST_Distance[.refpurpose]# — Returns the distance between two geometry or geography values.#
ST_3DDistance[.refpurpose]# — Returns the 3D cartesian minimum distance (based on spatial ref) between two geometries in projected units. #
ST_DistanceSphere[.refpurpose]# — Returns minimum distance in meters between two lon/lat geometries using a spherical earth model. #
ST_DistanceSpheroid[.refpurpose]# — Returns the minimum distance between two lon/lat geometries using a spheroidal earth model.#
ST_FrechetDistance[.refpurpose]# — Returns the Fréchet distance between two geometries.#
ST_HausdorffDistance[.refpurpose]# — Returns the Hausdorff distance between two geometries. #
ST_Length[.refpurpose]# — Returns the 2D length of a linear geometry.#
ST_Length2D[.refpurpose]# —
Returns the 2D length of a linear geometry. Alias for ST_Length
#
ST_3DLength[.refpurpose]# — Returns the 3D length of a linear geometry.#
ST_LengthSpheroid[.refpurpose]# — Returns the 2D or 3D length/perimeter of a lon/lat geometry on a spheroid.#
ST_LongestLine[.refpurpose]# — Returns the 2D longest line between two geometries. #
ST_3DLongestLine[.refpurpose]# — Returns the 3D longest line between two geometries#
ST_MaxDistance[.refpurpose]# — Returns the 2D largest distance between two geometries in projected units.#
ST_3DMaxDistance[.refpurpose]# — Returns the 3D cartesian maximum distance (based on spatial ref) between two geometries in projected units. #
ST_MinimumClearance[.refpurpose]# — Returns the minimum clearance of a geometry, a measure of a geometry’s robustness.#
ST_MinimumClearanceLine[.refpurpose]# — Returns the two-point LineString spanning a geometry’s minimum clearance.#
ST_Perimeter[.refpurpose]# — Returns the length of the boundary of a polygonal geometry or geography.#
ST_Perimeter2D[.refpurpose]#
— Returns the 2D perimeter of a polygonal geometry. Alias for
ST_Perimeter
.#
ST_3DPerimeter[.refpurpose]# — Returns the 3D perimeter of a polygonal geometry.#
ST_Project[.refpurpose]# — Returns a point projected from a start point by a distance and bearing (azimuth).#
ST_ShortestLine[.refpurpose]# — Returns the 2D shortest line between two geometries#
ST_3DShortestLine[.refpurpose]# — Returns the 3D shortest line between two geometries#
8.13. Overlay Functions
Abstract
These functions compute results arising from the overlay of two geometries. These are also known as point-set theoretic boolean operations. Some related functions are also provided.
ST_ClipByBox2D[.refpurpose]# — Computes the portion of a geometry falling within a rectangle.#
ST_Difference[.refpurpose]# — Computes a geometry representing the part of geometry A that does not intersect geometry B.#
ST_Intersection[.refpurpose]# — Computes a geometry representing the shared portion of geometries A and B. #
ST_MemUnion[.refpurpose]# — Aggregate function which unions geometries in a memory-efficent but slower way#
ST_Node[.refpurpose]# — Nodes a collection of lines. #
ST_Split[.refpurpose]# — Returns a collection of geometries created by splitting a geometry by another geometry.#
ST_Subdivide[.refpurpose]# — Computes a rectilinear subdivision of a geometry.#
ST_SymDifference[.refpurpose]# — Computes a geometry representing the portions of geometries A and B that do not intersect.#
ST_UnaryUnion[.refpurpose]# — Computes the union of the components of a single geometry.#
ST_Union[.refpurpose]# — Computes a geometry representing the point-set union of the input geometries.#
8.14. Geometry Processing
Abstract
These functions compute geometric constructions, or alter geometry size or shape.
ST_Buffer[.refpurpose]# — Computes a geometry covering all points within a given distance from a geometry. #
ST_BuildArea[.refpurpose]# — Creates a polygonal geometry formed by the linework of a geometry.#
ST_Centroid[.refpurpose]# — Returns the geometric center of a geometry.#
ST_ChaikinSmoothing[.refpurpose]# — Returns a smoothed version of a geometry, using the Chaikin algorithm#
ST_ConcaveHull[.refpurpose]# — Computes a possibly concave geometry that encloses all input geometry vertices#
ST_ConvexHull[.refpurpose]# — Computes the convex hull of a geometry.#
ST_DelaunayTriangles[.refpurpose]# — Returns the Delaunay triangulation of the vertices of a geometry. #
ST_FilterByM[.refpurpose]# — Removes vertices based on their M value#
ST_GeneratePoints[.refpurpose]# — Generates random points contained in a Polygon or MultiPolygon.#
[.refpurpose] — Returns the geometric median of a MultiPoint. #
ST_LineMerge[.refpurpose]# — Return the lines formed by sewing together a MultiLineString.#
ST_MaximumInscribedCircle[.refpurpose]# — Computes the largest circle contained within a geometry.#
ST_MinimumBoundingCircle[.refpurpose]# — Returns the smallest circle polygon that contains a geometry.#
ST_MinimumBoundingRadius[.refpurpose]# — Returns the center point and radius of the smallest circle that contains a geometry.#
ST_OrientedEnvelope[.refpurpose]# — Returns a minimum-area rectangle containing a geometry.#
ST_OffsetCurve[.refpurpose]# — Returns an offset line at a given distance and side from an input line. #
ST_PointOnSurface[.refpurpose]# — Computes a point guaranteed to lie in a polygon, or on a geometry.#
ST_Polygonize[.refpurpose]# — Computes a collection of polygons formed from the linework of a set of geometries. #
ST_ReducePrecision[.refpurpose]# — Returns a valid geometry with points rounded to a grid tolerance.#
ST_SharedPaths[.refpurpose]# — Returns a collection containing paths shared by the two input linestrings/multilinestrings.#
ST_Simplify[.refpurpose]# — Returns a simplified version of a geometry, using the Douglas-Peucker algorithm.#
ST_SimplifyPreserveTopology[.refpurpose]# — Returns a simplified and valid version of a geometry, using the Douglas-Peucker algorithm.#
ST_SimplifyPolygonHull[.refpurpose]# — Computes a simplifed topology-preserving outer or inner hull of a polygonal geometry.#
ST_SimplifyVW[.refpurpose]# — Returns a simplified version of a geometry, using the Visvalingam-Whyatt algorithm#
ST_SetEffectiveArea[.refpurpose]# — Sets the effective area for each vertex, using the Visvalingam-Whyatt algorithm. #
ST_TriangulatePolygon[.refpurpose]# — Computes the constrained Delaunay triangulation of polygons#
ST_VoronoiLines[.refpurpose]# — Returns the boundaries of the Voronoi diagram of the vertices of a geometry.#
ST_VoronoiPolygons[.refpurpose]# — Returns the cells of the Voronoi diagram of the vertices of a geometry.#
8.15. Affine Transformations
Abstract
These functions change the position and shape of geometries using affine transformations.
ST_Affine[.refpurpose]# — Apply a 3D affine transformation to a geometry.#
ST_Rotate[.refpurpose]# — Rotates a geometry about an origin point.#
ST_RotateX[.refpurpose]# — Rotates a geometry about the X axis.#
ST_RotateY[.refpurpose]# — Rotates a geometry about the Y axis.#
ST_RotateZ[.refpurpose]# — Rotates a geometry about the Z axis.#
ST_Scale[.refpurpose]# — Scales a geometry by given factors.#
ST_Translate[.refpurpose]# — Translates a geometry by given offsets.#
ST_TransScale[.refpurpose]# — Translates and scales a geometry by given offsets and factors.#
8.16. Clustering Functions
Abstract
These functions implement clustering algorithms for sets of geometries.
ST_ClusterDBSCAN[.refpurpose]# — Window function that returns a cluster id for each input geometry using the DBSCAN algorithm.#
ST_ClusterIntersecting[.refpurpose]# — Aggregate function that clusters the input geometries into connected sets.#
ST_ClusterKMeans[.refpurpose]# — Window function that returns a cluster id for each input geometry using the K-means algorithm.#
ST_ClusterWithin[.refpurpose]# — Aggregate function that clusters the input geometries by separation distance.#
8.17. Bounding Box Functions
Abstract
These functions produce or operate on bounding boxes. They can also provide and accept geometry values, by using automatic or explicit casts.
See also Section 15.7, “PostGIS Box Functions”.
Box2D[.refpurpose]# — Returns a BOX2D representing the 2D extent of a geometry.#
Box3D[.refpurpose]# — Returns a BOX3D representing the 3D extent of a geometry.#
ST_EstimatedExtent[.refpurpose]# — Returns the estimated extent of a spatial table.#
ST_Expand[.refpurpose]# — Returns a bounding box expanded from another bounding box or a geometry.#
ST_Extent[.refpurpose]# — Aggregate function that returns the bounding box of geometries.#
ST_3DExtent[.refpurpose]# — Aggregate function that returns the 3D bounding box of geometries.#
ST_MakeBox2D[.refpurpose]# — Creates a BOX2D defined by two 2D point geometries.#
ST_3DMakeBox[.refpurpose]# — Creates a BOX3D defined by two 3D point geometries.#
ST_XMax[.refpurpose]# — Returns the X maxima of a 2D or 3D bounding box or a geometry.#
ST_XMin[.refpurpose]# — Returns the X minima of a 2D or 3D bounding box or a geometry.#
ST_YMax[.refpurpose]# — Returns the Y maxima of a 2D or 3D bounding box or a geometry.#
ST_YMin[.refpurpose]# — Returns the Y minima of a 2D or 3D bounding box or a geometry.#
ST_ZMax[.refpurpose]# — Returns the Z maxima of a 2D or 3D bounding box or a geometry.#
ST_ZMin[.refpurpose]# — Returns the Z minima of a 2D or 3D bounding box or a geometry.#
8.18. Linear Referencing
ST_LineInterpolatePoint[.refpurpose]# — Returns a point interpolated along a line at a fractional location.#
ST_3DLineInterpolatePoint[.refpurpose]# — Returns a point interpolated along a 3D line at a fractional location.#
ST_LineInterpolatePoints[.refpurpose]# — Returns points interpolated along a line at a fractional interval. #
ST_LineLocatePoint[.refpurpose]# — Returns the fractional location of the closest point on a line to a point.#
ST_LineSubstring[.refpurpose]# — Returns the part of a line between two fractional locations.#
ST_LocateAlong[.refpurpose]# — Returns the point(s) on a geometry that match a measure value.#
ST_LocateBetween[.refpurpose]# — Returns the portions of a geometry that match a measure range.#
ST_LocateBetweenElevations[.refpurpose]# — Returns the portions of a geometry that lie in an elevation (Z) range.#
ST_InterpolatePoint[.refpurpose]# — Returns the interpolated measure of a geometry closest to a point.#
ST_AddMeasure[.refpurpose]# — Interpolates measures along a linear geometry.#
8.19. Trajectory Functions
Abstract
These functions support working with trajectories. A trajectory is a linear geometry with increasing measures (M value) on each coordinate. Spatio-temporal data can be modeled by using relative times (such as the epoch) as the measure values.
ST_IsValidTrajectory[.refpurpose]# — Tests if the geometry is a valid trajectory.#
ST_ClosestPointOfApproach[.refpurpose]# — Returns a measure at the closest point of approach of two trajectories. #
ST_DistanceCPA[.refpurpose]# — Returns the distance between the closest point of approach of two trajectories. #
ST_CPAWithin[.refpurpose]# — Tests if the closest point of approach of two trajectories is within the specified distance. #
8.20. SFCGAL Functions
Abstract
SFCGAL is a C++ wrapper library around CGAL that provides advanced 2D and 3D spatial functions. For robustness, geometry coordinates have an exact rational number representation.
Installation instructions for the library can be found on the SFCGAL
home page (http://www.sfcgal.org). To enable the functions use
create extension postgis_sfcgal
.
postgis_sfcgal_version[.refpurpose]# — Returns the version of SFCGAL in use#
postgis_sfcgal_full_version[.refpurpose]# — Returns the full version of SFCGAL in use including CGAL and Boost versions#
ST_3DArea[.refpurpose]# — Computes area of 3D surface geometries. Will return 0 for solids.#
ST_3DConvexHull[.refpurpose]# — Computes the 3D convex hull of a geometry.#
ST_3DIntersection[.refpurpose]# — Perform 3D intersection#
ST_3DDifference[.refpurpose]# — Perform 3D difference#
ST_3DUnion[.refpurpose]# — Perform 3D union.#
ST_AlphaShape[.refpurpose]# — Computes a possible concave geometry using the CGAL Alpha Shapes algorithm.#
ST_ApproximateMedialAxis[.refpurpose]# — Compute the approximate medial axis of an areal geometry.#
ST_ConstrainedDelaunayTriangles[.refpurpose]# — Return a constrained Delaunay triangulation around the given input geometry. #
ST_Extrude[.refpurpose]# — Extrude a surface to a related volume#
ST_ForceLHR[.refpurpose]# — Force LHR orientation#
ST_IsPlanar[.refpurpose]# — Check if a surface is or not planar#
ST_IsSolid[.refpurpose]# — Test if the geometry is a solid. No validity check is performed.#
ST_MakeSolid[.refpurpose]# — Cast the geometry into a solid. No check is performed. To obtain a valid solid, the input geometry must be a closed Polyhedral Surface or a closed TIN.#
ST_MinkowskiSum[.refpurpose]# — Performs Minkowski sum#
ST_OptimalAlphaShape[.refpurpose]# — Computes a possible concave geometry using the CGAL Alpha Shapes algorithm after have computed the "optimal" alpha value.#
ST_Orientation[.refpurpose]# — Determine surface orientation#
ST_StraightSkeleton[.refpurpose]# — Compute a straight skeleton from a geometry#
ST_Tesselate[.refpurpose]# — Perform surface Tesselation of a polygon or polyhedralsurface and returns as a TIN or collection of TINS#
ST_Volume[.refpurpose]# — Computes the volume of a 3D solid. If applied to surface (even closed) geometries will return 0.#
8.21. Long Transaction Support
Abstract
These functions implement a row locking mechanism to support long transactions. They are provided primarily for implementors of the Web Feature Service specification.
AddAuth[.refpurpose]# — Adds an authorization token to be used in the current transaction.#
CheckAuth[.refpurpose]# — Creates a trigger on a table to prevent/allow updates and deletes of rows based on authorization token.#
DisableLongTransactions[.refpurpose]# — Disables long transaction support.#
EnableLongTransactions[.refpurpose]# — Enables long transaction support.#
LockRow[.refpurpose]# — Sets lock/authorization for a row in a table.#
UnlockRows[.refpurpose]# — Removes all locks held by an authorization token. #
|
8.22. Version Functions
Abstract
These functions report and upgrade PostGIS versions.
PostGIS_Extensions_Upgrade[.refpurpose]# — Packages and upgrades PostGIS extensions (e.g. postgis_raster, postgis_topology, postgis_sfcgal) to latest available version. #
PostGIS_Full_Version[.refpurpose]# — Reports full PostGIS version and build configuration infos.#
PostGIS_GEOS_Version[.refpurpose]# — Returns the version number of the GEOS library.#
PostGIS_Liblwgeom_Version[.refpurpose]# — Returns the version number of the liblwgeom library. This should match the version of PostGIS.#
PostGIS_LibXML_Version[.refpurpose]# — Returns the version number of the libxml2 library.#
PostGIS_Lib_Build_Date[.refpurpose]# — Returns build date of the PostGIS library.#
PostGIS_Lib_Version[.refpurpose]# — Returns the version number of the PostGIS library.#
PostGIS_PROJ_Version[.refpurpose]# — Returns the version number of the PROJ4 library.#
PostGIS_Wagyu_Version[.refpurpose]# — Returns the version number of the internal Wagyu library.#
PostGIS_Scripts_Build_Date[.refpurpose]# — Returns build date of the PostGIS scripts.#
PostGIS_Scripts_Installed[.refpurpose]# — Returns version of the PostGIS scripts installed in this database.#
PostGIS_Scripts_Released[.refpurpose]# — Returns the version number of the postgis.sql script released with the installed PostGIS lib.#
PostGIS_Version[.refpurpose]# — Returns PostGIS version number and compile-time options.#
8.23. Grand Unified Custom Variables (GUCs)
Abstract
This section lists custom PostGIS Grand Unified Custom Variables (GUC). These can be set globally, by database, by session or by transaction. Best set at global or database level.
postgis.backend[.refpurpose]# — The backend to service a function where GEOS and SFCGAL overlap. Options: geos or sfcgal. Defaults to geos.#
postgis.gdal_datapath[.refpurpose]# — A configuration option to assign the value of GDAL’s GDAL_DATA option. If not set, the environmentally set GDAL_DATA variable is used. #
postgis.gdal_enabled_drivers[.refpurpose]# — A configuration option to set the enabled GDAL drivers in the PostGIS environment. Affects the GDAL configuration variable GDAL_SKIP. #
postgis.enable_outdb_rasters[.refpurpose]# — A boolean configuration option to enable access to out-db raster bands. #
postgis.gdal_vsi_options[.refpurpose]# — A string configuration to set options used when working with an out-db raster. #
8.24. Troubleshooting Functions
Abstract
These functions are utilities for troubleshooting and repairing geometry data. They are only needed if the geometry data is corrupted in some way, which should never happen under normal circumstances.
PostGIS_AddBBox[.refpurpose]# — Add bounding box to the geometry.#
PostGIS_DropBBox[.refpurpose]# — Drop the bounding box cache from the geometry.#
PostGIS_HasBBox[.refpurpose]# — Returns TRUE if the bbox of this geometry is cached, FALSE otherwise.#
Chapter 7. Building Applications |
box2d |