The following are the built-in functions which can be used to construct spatial objects, either from coordinates or from other spatial objects.
They are divided into two sections:
ST_POINT(x: float64, y: float64) -> point
Constructs a 2D point geometry from its coordinates.
Null handling
If any of the arguments is NULL
, the function will also return NULL
.
Examples
SELECT ST_POINT(10, 20);
--> POINT(10 20)
See also
ST_LINE(x1: float64, y1: float64, x2: float64, y2: float64, ...) -> linestring
Constructs a 2D linestring geometry from point coordinates.
Arguments
This function can take arbitrarily many arguments, but at least 4 are required (i.e. coordinates of at least two points). There must be an even number of arguments.
Null handling
If any of the arguments is NULL
, the function will also return NULL
.
Examples
SELECT ST_LINE(10, 20, 10, 30, 20, 40);
--> LINESTRING(10 20,10 30,20 40)
See also
ST_POLYGON(x1: float64, y1: float64, x2: float64, y2: float64, x3: float64, y3: float64, ...) -> polygon
Constructs a 2D polygon geometry from point coordinates.
Arguments
This function can take arbitrarily many arguments, but at least 6 are required (i.e. coordinates of at least three points). There must be an even number of arguments.
Null handling
If any of the arguments is NULL
, the function will also return NULL
.
Notes
The first and last point coordinates need not be the same, i.e. the given coordinates don't need to represent a closed outer polygon shell. If that's the case, the outer shell will be closed automatically by connecting the last and first point.
All polygon
objects assume a counter-clockwise orientation of its outer ring and clockwise orientation for its inner rings. If needed, the point coordinates will be automatically reversed to match the expected orienation.
This function will not perform a full check for whether the given coordinates form a valid polygon (see ST_ISVALID for the definition of validity), because that check is computationally expensive. But this can be checked manually if needed, using the ST_ISVALID function.
Examples
SELECT ST_POLYGON(10, 10, 15, 15, 10, 20);
--> POLYGON((10 10,15 15,10 20,10 10))
See also
ST_MAKEPOINT(x: float64, y: float64) -> point
Alias for the ST_POINT function.
ST_MAKELINE(pt1: point, pt2: point, ...) -> linestring
Constructs a 2D linestring geometry out of points.
Arguments
This function can take arbitrarily many arguments, but at least two are required (i.e. it takes two points to construct a valid line).
Null handling
If any of the arguments is NULL
, the function will also return NULL
.
Examples
SELECT ST_MAKELINE(point '(10 10)', point '(20 20)', point '(30 10)');
--> LINESTRING(10 10,20 20,30 10)
See also
ST_MAKEPOLYGON(shell: linestring, hole1: linestring, ...) -> polygon
Constructs a 2D polygon geometry from its outer shell, and optionally several inner holes.
Arguments
This function can take arbitrarily many arguments, but at least one is required (i.e. the outer shell of the polygon).
Null handling
If any of the arguments is NULL
, the function will also return NULL
.
Error handling
If any of the arguments is not a closed linestring (i.e. doesn't have the same first and last point) or if it has fewer than 4 points, the function will return an error: Invalid polygon ring.
Notes
All arguments must be simple linestrings (i.e. not have any self-intersections), otherwise the result will be an invalid polygon.
All polygon
objects assume a counter-clockwise orientation of its outer ring and clockwise orientation for its inner rings. If needed, the given linestrings will be automatically reversed to match the expected orienation.
This function will not perform a full check for whether the given linestrings form a valid polygon (see ST_ISVALID for the definition of validity), because that check is computationally expensive. But this can be checked manually if needed using the ST_ISVALID function.
Examples
SELECT ST_MAKEPOLYGON(
linestring '(0 0, 20 0, 20 20, 0 20, 0 0)',
linestring '(5 5, 5 10, 10 10, 5 5)');
--> POLYGON((0 0,20 0,20 20,0 20,0 0),(5 5,5 10,10 10,5 5))
See also
ST_GEOGPOINT(lon: float64, lat: float64) -> geogpoint
Constructs a 2D point geography object from latitude/longitude.
Null handling
If any of the arguments is NULL
, the function will also return NULL
.
Examples
SELECT ST_GEOGPOINT(10.25, 20.17);
--> POINT(10.25 20.17)
See also
ST_GEOGLINE(lon1: float64, lat1: float64, ...) -> geoglinestring
Constructs a 2D linestring geography object from point latitudes/longitudes.
Arguments
This function can take arbitrarily many arguments, but at least 4 are required (i.e. (lon, lat)
coordinates of at least two points). There must be an even number of arguments.
Null handling
If any of the arguments is NULL
, the function will also return NULL
.
Examples
SELECT ST_GEOGLINE(10.15, 20.22, 10.87, 30.44, 20.18, 40.63);
--> LINESTRING(10.15 20.22,10.87 30.44,20.18 40.63)
See also
ST_GEOGPOLYGON(lon1: float64, lat1: float64, ...) -> geogpolygon
Constructs a 2D polygon geography object from point latitudes/longitudes.
Arguments
This function can take arbitrarily many arguments, but at least 6 are required (i.e. (lon, lat)
coordinates of at least three points). There must be an even number of arguments.
Null handling
If any of the arguments is NULL
, the function will also return NULL
.
Notes
The first and last point coordinates need not be the same, i.e. the given coordinates don't need to represent a closed outer polygon shell. If that's the case, the outer shell will be closed automatically by connecting the last and first point.
All geogpolygon
objects assume a counter-clockwise orientation of its outer ring and clockwise orientation for its inner rings. If needed, the point coordinates will be automatically reversed to match the expected orienation.
This function will not perform a full check for whether the given coordinates form a valid polygon (see ST_ISVALID for the definition of validity), because that check is computationally expensive. But this can be checked manually if needed, using the ST_ISVALID function.
Examples
SELECT ST_GEOGPOLYGON(15.19, 46.99, 15.75, 46.98, 15.47, 47.35);
--> POLYGON((15.19 46.99,15.75 46.98,15.47 47.35,15.19 46.99))
See also
ST_MAKEGEOGPOINT(x: float64, y: float64) -> geogpoint
Alias for the ST_GEOGPOINT function.
ST_MAKEGEOGLINE(pt1: geogpoint, ...) -> geoglinestring
Constructs a 2D linestring geography out of points.
Arguments
This function can take arbitrarily many arguments, but at least two are required (i.e. it takes two points to construct a valid line).
Null handling
If any of the arguments is NULL
, the function will also return NULL
.
Examples
SELECT ST_MAKEGEOGLINE(ST_GEOGPOINT(16.5, 45.8), ST_GEOGPOINT(17.2, 44.5));
--> LINESTRING(16.5 45.8,17.2 44.5)
See also
ST_MAKEGEOGPOLYGON(shell: geoglinestring, hole1: geoglinestring, ...) -> geogpolygon
Constructs a 2D polygon geography from its outer shell, and optionally several inner holes.
Arguments
This function can take arbitrarily many arguments, but at least one is required (i.e. the outer shell of the polygon).
Null handling
If any of the arguments is NULL
, the function will also return NULL
.
Error handling
If any of the arguments is not a closed linestring (i.e. doesn't have the same first and last point) or if it has fewer than 4 points, the function will return an error: Invalid polygon ring.
Notes
All arguments must be simple linestrings (i.e. not have any self-intersections), otherwise the result will be an invalid polygon.
All geogpolygon
objects assume a counter-clockwise orientation of its outer ring and clockwise orientation for its inner rings. If needed, the given linestrings will be automatically reversed to match the expected orienation.
This function will not perform a full check for whether the given linestrings form a valid polygon (see ST_ISVALID for the definition of validity), because that check is computationally expensive. But this can be checked manually if needed using the ST_ISVALID function.
Examples
SELECT ST_MAKEGEOGPOLYGON(
geoglinestring '(0 0, 20.8 0, 10.4 20.8, 0 0)',
geoglinestring '(5.2 5.2, 10.4 10.4, 15.6 5.2, 5.2 5.2)');
--> POLYGON((0 0,20.8 0,10.4 20.8,0 0),(5.2 5.2,10.4 10.4,15.6 5.2,5.2 5.2))
See also