# Geometry Accessors

GeometryType

Returns the type of the geometry as a string. Eg: 'LINESTRING', 'POLYGON', 'MULTIPOINT', etc.

    			text GeometryType
    			geometry  geomA

### Description

Returns the type of the geometry as a string. Eg: 'LINESTRING', 'POLYGON', 'MULTIPOINT', etc.

OGC SPEC s2.1.1.1 - Returns the name of the instantiable subtype of Geometry of which this Geometry instance is a member. The name of the instantiable subtype of Geometry is returned as a string.

This function also indicates if the geometry is measured, by returning a string of the form 'POINTM'.

Enhanced: 2.0.0 support for Polyhedral surfaces, Triangles and TIN was introduced.

&sfs_compliant;

&curve_support;

&Z_support;

&P_support;

&T_support;

### Examples

    SELECT GeometryType(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
     geometrytype
    --------------
     LINESTRING

    SELECT ST_GeometryType(ST_GeomFromEWKT('POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),
    		((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),
    		((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)),
    		((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)), ((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1)) )'));
    			--result
    			POLYHEDRALSURFACE

    SELECT GeometryType(geom) as result
      FROM
        (SELECT
           ST_GeomFromEWKT('TIN (((
                    0 0 0,
                    0 0 1,
                    0 1 0,
                    0 0 0
                )), ((
                    0 0 0,
                    0 1 0,
                    1 1 0,
                    0 0 0
                ))
                )')  AS geom
        ) AS g;
     result
    --------
     TIN

### See Also

ST_GeometryType

ST_Boundary

Returns the closure of the combinatorial boundary of this Geometry.

    			geometry ST_Boundary

    			geometry  geomA

### Description

Returns the closure of the combinatorial boundary of this Geometry. The combinatorial boundary is defined as described in section 3.12.3.2 of the OGC SPEC. Because the result of this function is a closure, and hence topologically closed, the resulting boundary can be represented using representational geometry primitives as discussed in the OGC SPEC, section 3.12.2.

Performed by the GEOS module

Prior to 2.0.0, this function throws an exception if used with `GEOMETRYCOLLECTION`. From 2.0.0 up it will return NULL instead (unsupported input).

&sfs_compliant; OGC SPEC s2.1.1.1

&sqlmm_compliant; SQL-MM 3: 5.1.14

&Z_support;

Enhanced: 2.1.0 support for Triangle was introduced

### Examples

Linestring with boundary points overlaid
    SELECT ST_Boundary(geom)
    FROM (SELECT 'LINESTRING(100 150,50 60, 70 80, 160 170)'::geometry As geom) As f;
    -- ST_AsText output
    MULTIPOINT(100 150,160 170)
| polygon holes with boundary multilinestring
    SELECT ST_Boundary(geom)
    FROM (SELECT
    'POLYGON (( 10 130, 50 190, 110 190, 140 150, 150 80, 100 10, 20 40, 10 130 ),
    	( 70 40, 100 50, 120 80, 80 110, 50 90, 70 40 ))'::geometry As geom) As f;
    -- ST_AsText output
    MULTILINESTRING((10 130,50 190,110 190,140 150,150 80,100 10,20 40,10 130),
    	(70 40,100 50,120 80,80 110,50 90,70 40))

    SELECT ST_AsText(ST_Boundary(ST_GeomFromText('LINESTRING(1 1,0 0, -1 1)')));
    st_astext
    -----------
    MULTIPOINT(1 1,-1 1)

    SELECT ST_AsText(ST_Boundary(ST_GeomFromText('POLYGON((1 1,0 0, -1 1, 1 1))')));
    st_astext
    ----------
    LINESTRING(1 1,0 0,-1 1,1 1)

    --Using a 3d polygon
    SELECT ST_AsEWKT(ST_Boundary(ST_GeomFromEWKT('POLYGON((1 1 1,0 0 1, -1 1 1, 1 1 1))')));

    st_asewkt
    -----------------------------------
    LINESTRING(1 1 1,0 0 1,-1 1 1,1 1 1)

    --Using a 3d multilinestring
    SELECT ST_AsEWKT(ST_Boundary(ST_GeomFromEWKT('MULTILINESTRING((1 1 1,0 0 0.5, -1 1 1),(1 1 0.5,0 0 0.5, -1 1 0.5, 1 1 0.5) )')));

    st_asewkt
    ----------
    MULTIPOINT(-1 1 1,1 1 0.75)

### See Also

ST_AsText, ST_ExteriorRing, ST_MakePolygon

ST_CoordDim

Return the coordinate dimension of the ST_Geometry value.

    			integer ST_CoordDim
    			geometry  geomA

### Description

Return the coordinate dimension of the ST_Geometry value.

This is the MM compliant alias name for ST_NDims

&sfs_compliant;

&sqlmm_compliant; SQL-MM 3: 5.1.3

&curve_support;

&Z_support;

&P_support;

&T_support;

### Examples

    SELECT ST_CoordDim('CIRCULARSTRING(1 2 3, 1 3 4, 5 6 7, 8 9 10, 11 12 13)');
    			---result--
    				3

    				SELECT ST_CoordDim(ST_Point(1,2));
    			--result--
    				2

### See Also

ST_NDims

ST_Dimension

The inherent dimension of this Geometry object, which must be less than or equal to the coordinate dimension.

    			integer ST_Dimension

    			geometry  g

### Description

The inherent dimension of this Geometry object, which must be less than or equal to the coordinate dimension. OGC SPEC s2.1.1.1 - returns 0 for `POINT`, 1 for `LINESTRING`, 2 for `POLYGON`, and the largest dimension of the components of a `GEOMETRYCOLLECTION`. If the dimension is unknown (empty `GEOMETRYCOLLECTION`) 0 is returned.

&sqlmm_compliant; SQL-MM 3: 5.1.2

Enhanced: 2.0.0 support for Polyhedral surfaces and TINs was introduced. No longer throws an exception if given empty geometry.

Prior to 2.0.0, this function throws an exception if used with empty geometry.

&P_support;

&T_support;

### Examples

    SELECT ST_Dimension('GEOMETRYCOLLECTION(LINESTRING(1 1,0 0),POINT(0 0))');
    ST_Dimension
    -----------
    1

### See Also

ST_NDims

ST_EndPoint

Returns the last point of a `LINESTRING` or `CIRCULARLINESTRING` geometry as a `POINT`.

    			geometry ST_EndPoint

    			geometry  g

### Description

Returns the last point of a `LINESTRING` geometry as a `POINT` or `NULL` if the input parameter is not a `LINESTRING`.

&sqlmm_compliant; SQL-MM 3: 7.1.4

&Z_support;

&curve_support;

Changed: 2.0.0 no longer works with single geometry multilinestrings. In older versions of PostGIS -- a single line multilinestring would work happily with this function and return the start point. In 2.0.0 it just returns NULL like any other multilinestring. The older behavior was an undocumented feature, but people who assumed they had their data stored as LINESTRING may experience these returning NULL in 2.0 now.

### Examples

    postgis=# SELECT ST_AsText(ST_EndPoint('LINESTRING(1 1, 2 2, 3 3)'::geometry));
     st_astext
    ------------
     POINT(3 3)
    (1 row)

    postgis=# SELECT ST_EndPoint('POINT(1 1)'::geometry) IS NULL AS is_null;
      is_null
    ----------
     t
    (1 row)

    --3d endpoint
    SELECT ST_AsEWKT(ST_EndPoint('LINESTRING(1 1 2, 1 2 3, 0 0 5)'));
      st_asewkt
    --------------
     POINT(0 0 5)
    (1 row)

### See Also

ST_PointN, ST_StartPoint

ST_Envelope

Returns a geometry representing the double precision (float8) bounding box of the supplied geometry.

    				geometry ST_Envelope

    				geometry  g1

### Description

Returns the float8 minimum bounding box for the supplied geometry, as a geometry. The polygon is defined by the corner points of the bounding box ((`MINX`, `MINY`), (`MINX`, `MAXY`), (`MAXX`, `MAXY`), (`MAXX`, `MINY`), (`MINX`, `MINY`)). (PostGIS will add a `ZMIN`/`ZMAX` coordinate as well).

Degenerate cases (vertical lines, points) will return a geometry of lower dimension than `POLYGON`, ie. `POINT` or `LINESTRING`.

Availability: 1.5.0 behavior changed to output double precision instead of float4

&sfs_compliant; s2.1.1.1

&sqlmm_compliant; SQL-MM 3: 5.1.15

### Examples

    SELECT ST_AsText(ST_Envelope('POINT(1 3)'::geometry));
     st_astext
    ------------
     POINT(1 3)
    (1 row)

    SELECT ST_AsText(ST_Envelope('LINESTRING(0 0, 1 3)'::geometry));
    		   st_astext
    --------------------------------
     POLYGON((0 0,0 3,1 3,1 0,0 0))
    (1 row)

    SELECT ST_AsText(ST_Envelope('POLYGON((0 0, 0 1, 1.0000001 1, 1.0000001 0, 0 0))'::geometry));
    						  st_astext
    --------------------------------------------------------------
     POLYGON((0 0,0 1,1.00000011920929 1,1.00000011920929 0,0 0))
    (1 row)
    SELECT ST_AsText(ST_Envelope('POLYGON((0 0, 0 1, 1.0000000001 1, 1.0000000001 0, 0 0))'::geometry));
    						  st_astext
    --------------------------------------------------------------
     POLYGON((0 0,0 1,1.00000011920929 1,1.00000011920929 0,0 0))
    (1 row)

    SELECT Box3D(geom), Box2D(geom), ST_AsText(ST_Envelope(geom)) As envelopewkt
    	FROM (SELECT 'POLYGON((0 0, 0 1000012333334.34545678, 1.0000001 1, 1.0000001 0, 0 0))'::geometry As geom) As foo;

Envelope of a point and linestring.

    SELECT ST_AsText(ST_Envelope(
    		ST_Collect(
    			ST_GeomFromText('LINESTRING(55 75,125 150)'),
    				ST_Point(20, 80))
    				)) As wktenv;
    wktenv
    -----------
    POLYGON((20 75,20 150,125 150,125 75,20 75))

### See Also

Box2D, Box3D, ST_OrientedEnvelope

ST_BoundingDiagonal

Returns the diagonal of the supplied geometry's bounding box.

    				geometry ST_BoundingDiagonal

    				geometry  geom
    				boolean  fits=false

### Description

Returns the diagonal of the supplied geometry's bounding box as linestring. If the input geometry is empty, the diagonal line is also empty, otherwise it is a 2-points linestring with minimum values of each dimension in its start point and maximum values in its end point.

The returned linestring geometry always retains SRID and dimensionality (Z and M presence) of the input geometry.

The `fits` parameter specifies if the best fit is needed. If false, the diagonal of a somewhat larger bounding box can be accepted (is faster to obtain for geometries with a lot of vertices). In any case the bounding box of the returned diagonal line always covers the input geometry.

In degenerate cases (a single vertex in input) the returned linestring will be topologically invalid (no interior). This does not make the return semantically invalid.

Availability: 2.2.0

&Z_support;

&M_support;

### Examples

    -- Get the minimum X in a buffer around a point
    SELECT ST_X(ST_StartPoint(ST_BoundingDiagonal(
      ST_Buffer(ST_MakePoint(0,0),10)
    )));
     st_x
    ------
      -10

### See Also

ST_StartPoint, ST_EndPoint, ST_X, ST_Y, ST_Z, ST_M, geometry_overlaps_nd

ST_ExteriorRing

Returns a line string representing the exterior ring of the `POLYGON` geometry. Return NULL if the geometry is not a polygon. Will not work with MULTIPOLYGON

    			geometry ST_ExteriorRing

    			geometry  a_polygon

### Description

Returns a line string representing the exterior ring of the `POLYGON` geometry. Return NULL if the geometry is not a polygon.

Only works with POLYGON geometry types

&sfs_compliant; 2.1.5.1

&sqlmm_compliant; SQL-MM 3: 8.2.3, 8.3.3

&Z_support;

### Examples

    --If you have a table of polygons
    SELECT gid, ST_ExteriorRing(the_geom) AS ering
    FROM sometable;

    --If you have a table of MULTIPOLYGONs
    --and want to return a MULTILINESTRING composed of the exterior rings of each polygon
    SELECT gid, ST_Collect(ST_ExteriorRing(the_geom)) AS erings
    	FROM (SELECT gid, (ST_Dump(the_geom)).geom As the_geom
    			FROM sometable) As foo
    GROUP BY gid;

    --3d Example
    SELECT ST_AsEWKT(
    	ST_ExteriorRing(
    	ST_GeomFromEWKT('POLYGON((0 0 1, 1 1 1, 1 2 1, 1 1 1, 0 0 1))')
    	)
    );

    st_asewkt
    ---------
    LINESTRING(0 0 1,1 1 1,1 2 1,1 1 1,0 0 1)

### See Also

ST_InteriorRingN, ST_Boundary, ST_NumInteriorRings

ST_GeometryN

Return the 1-based Nth geometry if the geometry is a GEOMETRYCOLLECTION, (MULTI)POINT, (MULTI)LINESTRING, MULTICURVE or (MULTI)POLYGON, POLYHEDRALSURFACE Otherwise, return NULL.

    			geometry ST_GeometryN
    			geometry  geomA
    			integer  n

### Description

Return the 1-based Nth geometry if the geometry is a GEOMETRYCOLLECTION, (MULTI)POINT, (MULTI)LINESTRING, MULTICURVE or (MULTI)POLYGON, POLYHEDRALSURFACE Otherwise, return NULL

Index is 1-based as for OGC specs since version 0.8.0. Previous versions implemented this as 0-based instead.

If you want to extract all geometries, of a geometry, ST_Dump is more efficient and will also work for singular geoms.

Enhanced: 2.0.0 support for Polyhedral surfaces, Triangles and TIN was introduced.

Changed: 2.0.0 Prior versions would return NULL for singular geometries. This was changed to return the geometry for ST_GeometryN(..,1) case.

&sfs_compliant;

&sqlmm_compliant; SQL-MM 3: 9.1.5

&Z_support;

&curve_support;

&P_support;

&T_support;

### Standard Examples

    --Extracting a subset of points from a 3d multipoint
    SELECT n, ST_AsEWKT(ST_GeometryN(the_geom, n)) As geomewkt
    FROM (
    VALUES (ST_GeomFromEWKT('MULTIPOINT(1 2 7, 3 4 7, 5 6 7, 8 9 10)') ),
    ( ST_GeomFromEWKT('MULTICURVE(CIRCULARSTRING(2.5 2.5,4.5 2.5, 3.5 3.5), (10 11, 12 11))') )
    	)As foo(the_geom)
    	CROSS JOIN generate_series(1,100) n
    WHERE n <= ST_NumGeometries(the_geom);

     n |               geomewkt
    ---+-----------------------------------------
     1 | POINT(1 2 7)
     2 | POINT(3 4 7)
     3 | POINT(5 6 7)
     4 | POINT(8 9 10)
     1 | CIRCULARSTRING(2.5 2.5,4.5 2.5,3.5 3.5)
     2 | LINESTRING(10 11,12 11)

    --Extracting all geometries (useful when you want to assign an id)
    SELECT gid, n, ST_GeometryN(the_geom, n)
    FROM sometable CROSS JOIN generate_series(1,100) n
    WHERE n <= ST_NumGeometries(the_geom);

### Polyhedral Surfaces, TIN and Triangle Examples

    -- Polyhedral surface example
    -- Break a Polyhedral surface into its faces
    SELECT ST_AsEWKT(ST_GeometryN(p_geom,3)) As geom_ewkt
      FROM (SELECT ST_GeomFromEWKT('POLYHEDRALSURFACE(
    ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),
    ((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),
    ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),
    ((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)),
    ((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)),
    ((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1))
    )')  AS p_geom )  AS a;

                    geom_ewkt
    ------------------------------------------
     POLYGON((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0))

    -- TIN --
    SELECT ST_AsEWKT(ST_GeometryN(geom,2)) as wkt
      FROM
        (SELECT
           ST_GeomFromEWKT('TIN (((
                    0 0 0,
                    0 0 1,
                    0 1 0,
                    0 0 0
                )), ((
                    0 0 0,
                    0 1 0,
                    1 1 0,
                    0 0 0
                ))
                )')  AS geom
        ) AS g;
    -- result --
                     wkt
    -------------------------------------
     TRIANGLE((0 0 0,0 1 0,1 1 0,0 0 0))

### See Also

ST_Dump, ST_NumGeometries

ST_GeometryType

Return the geometry type of the ST_Geometry value.

    			text ST_GeometryType
    			geometry  g1

### Description

Returns the type of the geometry as a string. EG: 'ST_Linestring', 'ST_Polygon','ST_MultiPolygon' etc. This function differs from GeometryType(geometry) in the case of the string and ST in front that is returned, as well as the fact that it will not indicate whether the geometry is measured.

Enhanced: 2.0.0 support for Polyhedral surfaces was introduced.

&sqlmm_compliant; SQL-MM 3: 5.1.4

&Z_support;

&P_support;

### Examples

    SELECT ST_GeometryType(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
    			--result
    			ST_LineString

    SELECT ST_GeometryType(ST_GeomFromEWKT('POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),
    		((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),
    		((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)),
    		((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)), ((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1)) )'));
    			--result
    			ST_PolyhedralSurface

    SELECT ST_GeometryType(ST_GeomFromEWKT('POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),
    		((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),
    		((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)),
    		((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)), ((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1)) )'));
    			--result
    			ST_PolyhedralSurface

    SELECT ST_GeometryType(geom) as result
      FROM
        (SELECT
           ST_GeomFromEWKT('TIN (((
                    0 0 0,
                    0 0 1,
                    0 1 0,
                    0 0 0
                )), ((
                    0 0 0,
                    0 1 0,
                    1 1 0,
                    0 0 0
                ))
                )')  AS geom
        ) AS g;
     result
    --------
     ST_Tin

### See Also

GeometryType

ST_InteriorRingN

Return the Nth interior linestring ring of the polygon geometry. Return NULL if the geometry is not a polygon or the given N is out of range.

    			geometry ST_InteriorRingN
    			geometry  a_polygon
    			integer  n

### Description

Return the Nth interior linestring ring of the polygon geometry. Return NULL if the geometry is not a polygon or the given N is out of range. index starts at 1.

This will not work for MULTIPOLYGONs. Use in conjunction with ST_Dump for MULTIPOLYGONS

&sfs_compliant;

&sqlmm_compliant; SQL-MM 3: 8.2.6, 8.3.5

&Z_support;

### Examples

    SELECT ST_AsText(ST_InteriorRingN(the_geom, 1)) As the_geom
    FROM (SELECT ST_BuildArea(
    		ST_Collect(ST_Buffer(ST_Point(1,2), 20,3),
    			ST_Buffer(ST_Point(1, 2), 10,3))) As the_geom
    		)  as foo

### See Also

ST_ExteriorRing ST_BuildArea, ST_Collect, ST_Dump, ST_NumInteriorRing, ST_NumInteriorRings

ST_IsPolygonCCW

Returns true if all exterior rings are oriented counter-clockwise and all interior rings are oriented clockwise.

    						boolean
    						ST_IsPolygonCCW

    						geometry
    						geom

### Description

Returns true if all polygonal components of the input geometry use a counter-clockwise orientation for their exterior ring, and a clockwise direction for all interior rings.

Returns true if the geometry has no polygonal components.

Closed linestrings are not considered polygonal components, so you would still get a true return by passing a single closed linestring no matter its orientation.

If a polygonal geometry does not use reversed orientation for interior rings (i.e., if one or more interior rings are oriented in the same direction as an exterior ring) then both ST_IsPolygonCW and ST_IsPolygonCCW will return false.

&Z_support;

&M_support;

### See Also

ST_ForcePolygonCW, ST_ForcePolygonCCW, ST_IsPolygonCW

ST_IsPolygonCW

Returns true if all exterior rings are oriented clockwise and all interior rings are oriented counter-clockwise.

    						boolean
    						ST_IsPolygonCW

    						geometry
    						geom

### Description

Returns true if all polygonal components of the input geometry use a clockwise orientation for their exterior ring, and a counter-clockwise direction for all interior rings.

Returns true if the geometry has no polygonal components.

Closed linestrings are not considered polygonal components, so you would still get a true return by passing a single closed linestring no matter its orientation.

If a polygonal geometry does not use reversed orientation for interior rings (i.e., if one or more interior rings are oriented in the same direction as an exterior ring) then both ST_IsPolygonCW and ST_IsPolygonCCW will return false.

&Z_support;

&M_support;

### See Also

ST_ForcePolygonCW, ST_ForcePolygonCCW, ST_IsPolygonCW

ST_IsClosed

Returns `TRUE` if the `LINESTRING`'s start and end points are coincident. For Polyhedral surface is closed (volumetric).

    			boolean ST_IsClosed

    			geometry  g

### Description

Returns `TRUE` if the `LINESTRING`'s start and end points are coincident. For Polyhedral Surfaces, it tells you if the surface is areal (open) or volumetric (closed).

&sfs_compliant;

&sqlmm_compliant; SQL-MM 3: 7.1.5, 9.3.3

SQL-MM defines the result of `ST_IsClosed(`NULL`)` to be 0, while PostGIS returns `NULL`.

&Z_support;

&curve_support;

Enhanced: 2.0.0 support for Polyhedral surfaces was introduced.

&P_support;

### Line String and Point Examples

    postgis=# SELECT ST_IsClosed('LINESTRING(0 0, 1 1)'::geometry);
     st_isclosed
    -------------
     f
    (1 row)

    postgis=# SELECT ST_IsClosed('LINESTRING(0 0, 0 1, 1 1, 0 0)'::geometry);
     st_isclosed
    -------------
     t
    (1 row)

    postgis=# SELECT ST_IsClosed('MULTILINESTRING((0 0, 0 1, 1 1, 0 0),(0 0, 1 1))'::geometry);
     st_isclosed
    -------------
     f
    (1 row)

    postgis=# SELECT ST_IsClosed('POINT(0 0)'::geometry);
     st_isclosed
    -------------
     t
    (1 row)

    postgis=# SELECT ST_IsClosed('MULTIPOINT((0 0), (1 1))'::geometry);
     st_isclosed
    -------------
     t
    (1 row)

### Polyhedral Surface Examples

    		-- A cube --
    		SELECT ST_IsClosed(ST_GeomFromEWKT('POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),
    		((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),
    		((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)),
    		((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)), ((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1)) )'));

     st_isclosed
    -------------
     t

     -- Same as cube but missing a side --
     SELECT ST_IsClosed(ST_GeomFromEWKT('POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),
    		((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),
    		((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)),
    		((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)) )'));

     st_isclosed
    -------------
     f

### See Also

ST_IsRing

ST_IsCollection

Returns `TRUE` if the argument is a collection (`MULTI*`, `GEOMETRYCOLLECTION`, ...)

    			boolean ST_IsCollection
    			geometry  g

### Description

Returns `TRUE` if the geometry type of the argument is either:

- GEOMETRYCOLLECTION

- MULTI{POINT,POLYGON,LINESTRING,CURVE,SURFACE}

- COMPOUNDCURVE

This function analyzes the type of the geometry. This means that it will return `TRUE` on collections that are empty or that contain a single element.

&Z_support;

&curve_support;

### Examples

    postgis=# SELECT ST_IsCollection('LINESTRING(0 0, 1 1)'::geometry);
     st_iscollection
    -------------
     f
    (1 row)

    postgis=# SELECT ST_IsCollection('MULTIPOINT EMPTY'::geometry);
     st_iscollection
    -------------
     t
    (1 row)

    postgis=# SELECT ST_IsCollection('MULTIPOINT((0 0))'::geometry);
     st_iscollection
    -------------
     t
    (1 row)

    postgis=# SELECT ST_IsCollection('MULTIPOINT((0 0), (42 42))'::geometry);
     st_iscollection
    -------------
     t
    (1 row)

    postgis=# SELECT ST_IsCollection('GEOMETRYCOLLECTION(POINT(0 0))'::geometry);
     st_iscollection
    -------------
     t
    (1 row)

### See Also

ST_NumGeometries

ST_IsEmpty

Returns true if this Geometry is an empty geometrycollection, polygon, point etc.

    			boolean ST_IsEmpty
    			geometry  geomA

### Description

Returns true if this Geometry is an empty geometry. If true, then this Geometry represents an empty geometry collection, polygon, point etc.

SQL-MM defines the result of ST_IsEmpty(NULL) to be 0, while PostGIS returns NULL.

&sfs_compliant; s2.1.1.1

&sqlmm_compliant; SQL-MM 3: 5.1.7

&curve_support;

Changed: 2.0.0 In prior versions of PostGIS ST_GeomFromText('GEOMETRYCOLLECTION(EMPTY)') was allowed. This is now illegal in PostGIS 2.0.0 to better conform with SQL/MM standards

### Examples

    SELECT ST_IsEmpty(ST_GeomFromText('GEOMETRYCOLLECTION EMPTY'));
     st_isempty
    ------------
     t
    (1 row)

     SELECT ST_IsEmpty(ST_GeomFromText('POLYGON EMPTY'));
     st_isempty
    ------------
     t
    (1 row)

    SELECT ST_IsEmpty(ST_GeomFromText('POLYGON((1 2, 3 4, 5 6, 1 2))'));

     st_isempty
    ------------
     f
    (1 row)

     SELECT ST_IsEmpty(ST_GeomFromText('POLYGON((1 2, 3 4, 5 6, 1 2))')) = false;
     ?column?
    ----------
     t
    (1 row)

     SELECT ST_IsEmpty(ST_GeomFromText('CIRCULARSTRING EMPTY'));
      st_isempty
    ------------
     t
    (1 row)

ST_IsRing

Returns `TRUE` if this `LINESTRING` is both closed and simple.

    		  boolean ST_IsRing

    		  geometry  g

### Description

Returns `TRUE` if this `LINESTRING` is both ST_IsClosed (`ST_StartPoint(`g`)` `~=` `ST_Endpoint(`g`)`) and ST_IsSimple (does not self intersect).

&sfs_compliant; 2.1.5.1

&sqlmm_compliant; SQL-MM 3: 7.1.6

SQL-MM defines the result of `ST_IsRing(`NULL`)` to be 0, while PostGIS returns `NULL`.

### Examples

    SELECT ST_IsRing(the_geom), ST_IsClosed(the_geom), ST_IsSimple(the_geom)
    FROM (SELECT 'LINESTRING(0 0, 0 1, 1 1, 1 0, 0 0)'::geometry AS the_geom) AS foo;
     st_isring | st_isclosed | st_issimple
    -----------+-------------+-------------
     t         | t           | t
    (1 row)

    SELECT ST_IsRing(the_geom), ST_IsClosed(the_geom), ST_IsSimple(the_geom)
    FROM (SELECT 'LINESTRING(0 0, 0 1, 1 0, 1 1, 0 0)'::geometry AS the_geom) AS foo;
     st_isring | st_isclosed | st_issimple
    -----------+-------------+-------------
     f         | t           | f
    (1 row)

### See Also

ST_IsClosed, ST_IsSimple, ST_StartPoint, ST_EndPoint

ST_IsSimple

Returns (TRUE) if this Geometry has no anomalous geometric points, such as self intersection or self tangency.

    			boolean ST_IsSimple
    			geometry  geomA

### Description

Returns true if this Geometry has no anomalous geometric points, such as self intersection or self tangency. For more information on the OGC's definition of geometry simplicity and validity, refer to "Ensuring OpenGIS compliancy of geometries"

SQL-MM defines the result of ST_IsSimple(NULL) to be 0, while PostGIS returns NULL.

&sfs_compliant; s2.1.1.1

&sqlmm_compliant; SQL-MM 3: 5.1.8

&Z_support;

### Examples

     SELECT ST_IsSimple(ST_GeomFromText('POLYGON((1 2, 3 4, 5 6, 1 2))'));
     st_issimple
    -------------
     t
    (1 row)

     SELECT ST_IsSimple(ST_GeomFromText('LINESTRING(1 1,2 2,2 3.5,1 3,1 2,2 1)'));
     st_issimple
    -------------
     f
    (1 row)

### See Also

ST_IsValid

ST_IsValid

Returns `true` if the `ST_Geometry` is well formed.

    			boolean ST_IsValid

    			geometry  g

    			boolean ST_IsValid

    			geometry  g
    			integer  flags

### Description

Test if an ST_Geometry value is well formed. For geometries that are invalid, the PostgreSQL NOTICE will provide details of why it is not valid. For more information on the OGC's definition of geometry simplicity and validity, refer to "Ensuring OpenGIS compliancy of geometries"

SQL-MM defines the result of ST_IsValid(NULL) to be 0, while PostGIS returns NULL.

The version accepting flags is available starting with 2.0.0 and requires GEOS >= 3.3.0. Such version does not print a NOTICE explaining the invalidity. Allowed `flags` are documented in ST_IsValidDetail.

&sfs_compliant;

&sqlmm_compliant; SQL-MM 3: 5.1.9

Neither OGC-SFS nor SQL-MM specifications include a flag argument for ST_IsValid. The flag is a PostGIS extension.

### Examples

    SELECT ST_IsValid(ST_GeomFromText('LINESTRING(0 0, 1 1)')) As good_line,
    	ST_IsValid(ST_GeomFromText('POLYGON((0 0, 1 1, 1 2, 1 1, 0 0))')) As bad_poly
    --results
    NOTICE:  Self-intersection at or near point 0 0
     good_line | bad_poly
    -----------+----------
     t         | f

### See Also

ST_IsSimple, ST_IsValidReason, ST_IsValidDetail, ST_Summary

ST_IsValidReason

Returns text stating if a geometry is valid or not and if not valid, a reason why.

    			text ST_IsValidReason
    			geometry  geomA

    			text ST_IsValidReason
    			geometry  geomA
    			integer  flags

### Description

Returns text stating if a geometry is valid or not an if not valid, a reason why.

Useful in combination with ST_IsValid to generate a detailed report of invalid geometries and reasons.

Allowed `flags` are documented in ST_IsValidDetail.

Availability: 1.4 - requires GEOS >= 3.1.0.

Availability: 2.0 - requires GEOS >= 3.3.0 for the version taking flags.

### Examples

    --First 3 Rejects from a successful quintuplet experiment
    SELECT gid, ST_IsValidReason(the_geom) as validity_info
    FROM
    (SELECT ST_MakePolygon(ST_ExteriorRing(e.buff), ST_Accum(f.line)) As the_geom, gid
    FROM (SELECT ST_Buffer(ST_MakePoint(x1*10,y1), z1) As buff, x1*10 + y1*100 + z1*1000 As gid
    	FROM generate_series(-4,6) x1
    	CROSS JOIN generate_series(2,5) y1
    	CROSS JOIN generate_series(1,8) z1
    	WHERE x1 > y1*0.5 AND z1 < x1*y1) As e
    	INNER JOIN (SELECT ST_Translate(ST_ExteriorRing(ST_Buffer(ST_MakePoint(x1*10,y1), z1)),y1*1, z1*2) As line
    	FROM generate_series(-3,6) x1
    	CROSS JOIN generate_series(2,5) y1
    	CROSS JOIN generate_series(1,10) z1
    	WHERE x1 > y1*0.75 AND z1 < x1*y1) As f
    ON (ST_Area(e.buff) > 78 AND ST_Contains(e.buff, f.line))
    GROUP BY gid, e.buff) As quintuplet_experiment
    WHERE ST_IsValid(the_geom) = false
    ORDER BY gid
    LIMIT 3;

     gid  |      validity_info
    ------+--------------------------
     5330 | Self-intersection [32 5]
     5340 | Self-intersection [42 5]
     5350 | Self-intersection [52 5]

     --simple example
    SELECT ST_IsValidReason('LINESTRING(220227 150406,2220227 150407,222020 150410)');

     st_isvalidreason
    ------------------
     Valid Geometry

### See Also

ST_IsValid, ST_Summary

ST_IsValidDetail

Returns a valid_detail (valid,reason,location) row stating if a geometry is valid or not and if not valid, a reason why and a location where.

    			valid_detail ST_IsValidDetail
    			geometry  geom

    			valid_detail ST_IsValidDetail
    			geometry  geom
    			integer  flags

### Description

Returns a valid_detail row, formed by a boolean (valid) stating if a geometry is valid, a varchar (reason) stating a reason why it is invalid and a geometry (location) pointing out where it is invalid.

Useful to substitute and improve the combination of ST_IsValid and ST_IsValidReason to generate a detailed report of invalid geometries.

The 'flags' argument is a bitfield. It can have the following values:

- 1: Consider self-intersecting rings forming holes as valid. This is also know as "the ESRI flag". Note that this is against the OGC model.

Availability: 2.0.0 - requires GEOS >= 3.3.0.

### Examples

    --First 3 Rejects from a successful quintuplet experiment
    SELECT gid, reason(ST_IsValidDetail(the_geom)), ST_AsText(location(ST_IsValidDetail(the_geom))) as location
    FROM
    (SELECT ST_MakePolygon(ST_ExteriorRing(e.buff), ST_Accum(f.line)) As the_geom, gid
    FROM (SELECT ST_Buffer(ST_MakePoint(x1*10,y1), z1) As buff, x1*10 + y1*100 + z1*1000 As gid
    	FROM generate_series(-4,6) x1
    	CROSS JOIN generate_series(2,5) y1
    	CROSS JOIN generate_series(1,8) z1
    	WHERE x1 > y1*0.5 AND z1 < x1*y1) As e
    	INNER JOIN (SELECT ST_Translate(ST_ExteriorRing(ST_Buffer(ST_MakePoint(x1*10,y1), z1)),y1*1, z1*2) As line
    	FROM generate_series(-3,6) x1
    	CROSS JOIN generate_series(2,5) y1
    	CROSS JOIN generate_series(1,10) z1
    	WHERE x1 > y1*0.75 AND z1 < x1*y1) As f
    ON (ST_Area(e.buff) > 78 AND ST_Contains(e.buff, f.line))
    GROUP BY gid, e.buff) As quintuplet_experiment
    WHERE ST_IsValid(the_geom) = false
    ORDER BY gid
    LIMIT 3;

     gid  |      reason       |  location
    ------+-------------------+-------------
     5330 | Self-intersection | POINT(32 5)
     5340 | Self-intersection | POINT(42 5)
     5350 | Self-intersection | POINT(52 5)

     --simple example
    SELECT * FROM ST_IsValidDetail('LINESTRING(220227 150406,2220227 150407,222020 150410)');

     valid | reason | location
    -------+--------+----------
     t     |        |

### See Also

ST_IsValid, ST_IsValidReason

ST_M

Return the M coordinate of the point, or NULL if not available. Input must be a point.

    			float ST_M
    			geometry  a_point

### Description

Return the M coordinate of the point, or NULL if not available. Input must be a point.

This is not (yet) part of the OGC spec, but is listed here to complete the point coordinate extractor function list.

&sfs_compliant;

&sqlmm_compliant;

&Z_support;

### Examples

    SELECT ST_M(ST_GeomFromEWKT('POINT(1 2 3 4)'));
     st_m
    ------
    	4
    (1 row)

### See Also

ST_GeomFromEWKT, ST_X, ST_Y, ST_Z

ST_NDims

Returns coordinate dimension of the geometry as a small int. Values are: 2,3 or 4.

    			integer ST_NDims
    			geometry  g1

### Description

Returns the coordinate dimension of the geometry. PostGIS supports 2 - (x,y) , 3 - (x,y,z) or 2D with measure - x,y,m, and 4 - 3D with measure space x,y,z,m

&Z_support;

### Examples

    SELECT ST_NDims(ST_GeomFromText('POINT(1 1)')) As d2point,
    	ST_NDims(ST_GeomFromEWKT('POINT(1 1 2)')) As d3point,
    	ST_NDims(ST_GeomFromEWKT('POINTM(1 1 0.5)')) As d2pointm;

    	 d2point | d3point | d2pointm
    ---------+---------+----------
    	   2 |       3 |        3

### See Also

ST_CoordDim, ST_Dimension, ST_GeomFromEWKT

ST_NPoints

Return the number of points (vertexes) in a geometry.

    			integer ST_NPoints
    			geometry  g1

### Description

Return the number of points in a geometry. Works for all geometries.

Enhanced: 2.0.0 support for Polyhedral surfaces was introduced.

Prior to 1.3.4, this function crashes if used with geometries that contain CURVES. This is fixed in 1.3.4+

&Z_support;

&curve_support;

&P_support;

### Examples

    SELECT ST_NPoints(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
    --result
    4

    --Polygon in 3D space
    SELECT ST_NPoints(ST_GeomFromEWKT('LINESTRING(77.29 29.07 1,77.42 29.26 0,77.27 29.31 -1,77.29 29.07 3)'))
    --result
    4

### See Also

ST_NumPoints

ST_NRings

If the geometry is a polygon or multi-polygon returns the number of rings.

    			integer ST_NRings
    			geometry  geomA

### Description

If the geometry is a polygon or multi-polygon returns the number of rings. Unlike NumInteriorRings, it counts the outer rings as well.

&Z_support;

&curve_support;

### Examples

    SELECT ST_NRings(the_geom) As Nrings, ST_NumInteriorRings(the_geom) As ninterrings
    					FROM (SELECT ST_GeomFromText('POLYGON((1 2, 3 4, 5 6, 1 2))') As the_geom) As foo;
    	 nrings | ninterrings
    --------+-------------
    	  1 |           0
    (1 row)

### See Also

ST_NumInteriorRings

ST_NumGeometries

If geometry is a GEOMETRYCOLLECTION (or MULTI*) return the number of geometries, for single geometries will return 1, otherwise return NULL.

    			integer ST_NumGeometries
    			geometry  geom

### Description

Returns the number of Geometries. If geometry is a GEOMETRYCOLLECTION (or MULTI*) return the number of geometries, for single geometries will return 1, otherwise return NULL.

Enhanced: 2.0.0 support for Polyhedral surfaces, Triangles and TIN was introduced.

Changed: 2.0.0 In prior versions this would return NULL if the geometry was not a collection/MULTI type. 2.0.0+ now returns 1 for single geometries e.g POLYGON, LINESTRING, POINT.

&sqlmm_compliant; SQL-MM 3: 9.1.4

&Z_support;

&P_support;

&T_support;

### Examples

    --Prior versions would have returned NULL for this -- in 2.0.0 this returns 1
    SELECT ST_NumGeometries(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
    --result
    1

    --Geometry Collection Example - multis count as one geom in a collection
    SELECT ST_NumGeometries(ST_GeomFromEWKT('GEOMETRYCOLLECTION(MULTIPOINT(-2 3 , -2 2),
    LINESTRING(5 5 ,10 10),
    POLYGON((-7 4.2,-7.1 5,-7.1 4.3,-7 4.2)))'));
    --result
    3

### See Also

ST_GeometryN, ST_Multi

ST_NumInteriorRings

Return the number of interior rings of a polygon geometry.

    			integer ST_NumInteriorRings
    			geometry  a_polygon

### Description

Return the number of interior rings of a polygon geometry. Return NULL if the geometry is not a polygon.

&sqlmm_compliant; SQL-MM 3: 8.2.5

Changed: 2.0.0 - in prior versions it would allow passing a MULTIPOLYGON, returning the number of interior rings of first POLYGON.

### Examples

    --If you have a regular polygon
    SELECT gid, field1, field2, ST_NumInteriorRings(the_geom) AS numholes
    FROM sometable;

    --If you have multipolygons
    --And you want to know the total number of interior rings in the MULTIPOLYGON
    SELECT gid, field1, field2, SUM(ST_NumInteriorRings(the_geom)) AS numholes
    FROM (SELECT gid, field1, field2, (ST_Dump(the_geom)).geom As the_geom
    	FROM sometable) As foo
    GROUP BY gid, field1,field2;

### See Also

ST_NumInteriorRing

ST_NumInteriorRing

Return the number of interior rings of a polygon in the geometry. Synonym for ST_NumInteriorRings.

    			integer ST_NumInteriorRing
    			geometry  a_polygon

### See Also

ST_NumInteriorRings

ST_NumPatches

Return the number of faces on a Polyhedral Surface. Will return null for non-polyhedral geometries.

    			integer ST_NumPatches
    			geometry  g1

### Description

Return the number of faces on a Polyhedral Surface. Will return null for non-polyhedral geometries. This is an alias for ST_NumGeometries to support MM naming. Faster to use ST_NumGeometries if you don't care about MM convention.

Availability: 2.0.0

&Z_support;

&sfs_compliant;

&sqlmm_compliant; SQL-MM 3: ?

&P_support;

### Examples

    SELECT ST_NumPatches(ST_GeomFromEWKT('POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),
    		((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),
    		((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)),
    		((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)), ((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1)) )'));
    		--result
    		6

### See Also

ST_GeomFromEWKT, ST_NumGeometries

ST_NumPoints

Return the number of points in an ST_LineString or ST_CircularString value.

    			integer ST_NumPoints
    			geometry  g1

### Description

Return the number of points in an ST_LineString or ST_CircularString value. Prior to 1.4 only works with Linestrings as the specs state. From 1.4 forward this is an alias for ST_NPoints which returns number of vertexes for not just line strings. Consider using ST_NPoints instead which is multi-purpose and works with many geometry types.

&sfs_compliant;

&sqlmm_compliant; SQL-MM 3: 7.2.4

### Examples

    SELECT ST_NumPoints(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
    		--result
    		4

### See Also

ST_NPoints

ST_PatchN

Return the 1-based Nth geometry (face) if the geometry is a POLYHEDRALSURFACE, POLYHEDRALSURFACEM. Otherwise, return NULL.

    			geometry ST_PatchN
    			geometry  geomA
    			integer  n

### Description

>Return the 1-based Nth geometry (face) if the geometry is a POLYHEDRALSURFACE, POLYHEDRALSURFACEM. Otherwise, return NULL. This returns the same answer as ST_GeometryN for Polyhedral Surfaces. Using ST_GemoetryN is faster.

Index is 1-based.

If you want to extract all geometries, of a geometry, ST_Dump is more efficient.

Availability: 2.0.0

&sqlmm_compliant; SQL-MM 3: ?

&Z_support;

&P_support;

### Examples

    --Extract the 2nd face of the polyhedral surface
    SELECT ST_AsEWKT(ST_PatchN(geom, 2)) As geomewkt
    FROM (
    VALUES (ST_GeomFromEWKT('POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),
    	((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),
    	((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)),
    	((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)), ((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1)) )')) ) As foo(geom);

                  geomewkt
    ---+-----------------------------------------
     POLYGON((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0))

### See Also

ST_AsEWKT, ST_GeomFromEWKT, ST_Dump, ST_GeometryN, ST_NumGeometries

ST_PointN

Return the Nth point in the first LineString or circular LineString in the geometry. Negative values are counted backwards from the end of the LineString. Returns NULL if there is no linestring in the geometry.

    			geometry ST_PointN
    			geometry  a_linestring
    			integer  n

### Description

Return the Nth point in a single linestring or circular linestring in the geometry. Negative values are counted backwards from the end of the LineString, so that -1 is the last point. Returns NULL if there is no linestring in the geometry.

Index is 1-based as for OGC specs since version 0.8.0. Backward indexing (negative index) is not in OGC Previous versions implemented this as 0-based instead.

If you want to get the nth point of each line string in a multilinestring, use in conjunction with ST_Dump

&sfs_compliant;

&sqlmm_compliant; SQL-MM 3: 7.2.5, 7.3.5

&Z_support;

&curve_support;

Changed: 2.0.0 no longer works with single geometry multilinestrings. In older versions of PostGIS -- a single line multilinestring would work happily with this function and return the start point. In 2.0.0 it just returns NULL like any other multilinestring.

Changed: 2.3.0 : negative indexing available (-1 is last point)

### Examples

    -- Extract all POINTs from a LINESTRING
    SELECT ST_AsText(
       ST_PointN(
    	  column1,
    	  generate_series(1, ST_NPoints(column1))
       ))
    FROM ( VALUES ('LINESTRING(0 0, 1 1, 2 2)'::geometry) ) AS foo;

     st_astext
    ------------
     POINT(0 0)
     POINT(1 1)
     POINT(2 2)
    (3 rows)

    --Example circular string
    SELECT ST_AsText(ST_PointN(ST_GeomFromText('CIRCULARSTRING(1 2, 3 2, 1 2)'),2));

    st_astext
    ----------
    POINT(3 2)

    SELECT st_astext(f)
    FROM ST_GeometryFromtext('LINESTRING(0 0 0, 1 1 1, 2 2 2)') as g
    	,ST_PointN(g, -2) AS f -- 1 based index

    st_astext
    ----------
    "POINT Z (1 1 1)"

### See Also

ST_NPoints

ST_Points

Returns a MultiPoint containing all of the coordinates of a geometry.

    					geometry ST_Points

    						geometry
    						geom

### Description

Returns a MultiPoint containing all of the coordinates of a geometry. Does not remove points that are duplicated in the input geometry, including start and end points of ring geometries. (If this behavior is undesired, duplicates may be removed using ST_RemoveRepeatedPoints).

M and Z ordinates will be preserved if present.

&curve_support;

&Z_support;

Availability: 2.3.0

### Examples

    SELECT ST_AsText(ST_Points('POLYGON Z ((30 10 4,10 30 5,40 40 6, 30 10))'));

    --result
    MULTIPOINT Z (30 10 4,10 30 5,40 40 6, 30 10 4)

### See Also

ST_RemoveRepeatedPoints

ST_SRID

Returns the spatial reference identifier for the ST_Geometry as defined in spatial_ref_sys table.

    			integer ST_SRID
    			geometry  g1

### Description

Returns the spatial reference identifier for the ST_Geometry as defined in spatial_ref_sys table. spatial_ref_sys

spatial_ref_sys table is a table that catalogs all spatial reference systems known to PostGIS and is used for transformations from one spatial reference system to another. So verifying you have the right spatial reference system identifier is important if you plan to ever transform your geometries.

&sfs_compliant; s2.1.1.1

&sqlmm_compliant; SQL-MM 3: 5.1.5

&curve_support;

### Examples

    SELECT ST_SRID(ST_GeomFromText('POINT(-71.1043 42.315)',4326));
    		--result
    		4326

### See Also

spatial_ref_sys, ST_GeomFromText, ST_SetSRID, ST_Transform

ST_StartPoint

Returns the first point of a `LINESTRING` geometry as a `POINT`.

    		  geometry ST_StartPoint

    		  geometry  geomA

### Description

Returns the first point of a `LINESTRING` or `CIRCULARLINESTRING` geometry as a `POINT` or `NULL` if the input parameter is not a `LINESTRING` or `CIRCULARLINESTRING`.

&sqlmm_compliant; SQL-MM 3: 7.1.3

&Z_support;

&curve_support;

Changed: 2.0.0 no longer works with single geometry multilinestrings. In older versions of PostGIS -- a single line multilinestring would work happily with this function and return the start point. In 2.0.0 it just returns NULL like any other multilinestring. The older behavior was an undocumented feature, but people who assumed they had their data stored as LINESTRING may experience these returning NULL in 2.0 now.

### Examples

    SELECT ST_AsText(ST_StartPoint('LINESTRING(0 1, 0 2)'::geometry));
     st_astext
    ------------
     POINT(0 1)
    (1 row)

    SELECT ST_StartPoint('POINT(0 1)'::geometry) IS NULL AS is_null;
      is_null
    ----------
     t
    (1 row)

    --3d line
    SELECT ST_AsEWKT(ST_StartPoint('LINESTRING(0 1 1, 0 2 2)'::geometry));
     st_asewkt
    ------------
     POINT(0 1 1)
    (1 row)

    -- circular linestring --
    SELECT ST_AsText(ST_StartPoint('CIRCULARSTRING(5 2,-3 1.999999, -2 1, -4 2, 5 2)'::geometry));
     st_astext
    ------------
     POINT(5 2)

### See Also

ST_EndPoint, ST_PointN

ST_Summary

Returns a text summary of the contents of the geometry.

    			text ST_Summary
    			geometry  g

    			text ST_Summary
    			geography  g

### Description

Returns a text summary of the contents of the geometry.

Flags shown square brackets after the geometry type have the following meaning:

- M: has M ordinate

- Z: has Z ordinate

- B: has a cached bounding box

- G: is geodetic (geography)

- S: has spatial reference system

&curve_support;

&P_support;

&T_support;

Availability: 1.2.2

Enhanced: 2.0.0 added support for geography

Enhanced: 2.1.0 S flag to denote if has a known spatial reference system

Enhanced: 2.2.0 Added support for TIN and Curves

### Examples

    =# SELECT ST_Summary(ST_GeomFromText('LINESTRING(0 0, 1 1)')) as geom,
            ST_Summary(ST_GeogFromText('POLYGON((0 0, 1 1, 1 2, 1 1, 0 0))')) geog;
                geom             |          geog
    -----------------------------+--------------------------
     LineString[B] with 2 points | Polygon[BGS] with 1 rings
                                 | ring 0 has 5 points
                                 :
    (1 row)

    =# SELECT ST_Summary(ST_GeogFromText('LINESTRING(0 0 1, 1 1 1)')) As geog_line,
            ST_Summary(ST_GeomFromText('SRID=4326;POLYGON((0 0 1, 1 1 2, 1 2 3, 1 1 1, 0 0 1))')) As geom_poly;
    ;
               geog_line             |        geom_poly
    -------------------------------- +--------------------------
     LineString[ZBGS] with 2 points | Polygon[ZBS] with 1 rings
                                    :    ring 0 has 5 points
                                    :
    (1 row)

### See Also

PostGIS_DropBBox, PostGIS_AddBBox, ST_Force_3DM, ST_Force_3DZ, ST_Force2D, geography

ST_IsValid, ST_IsValid, ST_IsValidReason, ST_IsValidDetail

ST_X

Return the X coordinate of the point, or NULL if not available. Input must be a point.

    			float ST_X
    			geometry  a_point

### Description

Return the X coordinate of the point, or NULL if not available. Input must be a point.

If you want to get the max min x values of any geometry look at ST_XMin, ST_XMax functions.

&sqlmm_compliant; SQL-MM 3: 6.1.3

&Z_support;

### Examples

    SELECT ST_X(ST_GeomFromEWKT('POINT(1 2 3 4)'));
     st_x
    ------
    	1
    (1 row)

    SELECT ST_Y(ST_Centroid(ST_GeomFromEWKT('LINESTRING(1 2 3 4, 1 1 1 1)')));
     st_y
    ------
      1.5
    (1 row)

### See Also

ST_Centroid, ST_GeomFromEWKT, ST_M, ST_XMax, ST_XMin, ST_Y, ST_Z

ST_XMax

Returns X maxima of a bounding box 2d or 3d or a geometry.

    			float ST_XMax
    			box3d  aGeomorBox2DorBox3D

### Description

Returns X maxima of a bounding box 2d or 3d or a geometry.

Although this function is only defined for box3d, it will work for box2d and geometry because of the auto-casting behavior defined for geometries and box2d. However you can not feed it a geometry or box2d text representation, since that will not auto-cast.

&Z_support;

&curve_support;

### Examples

    SELECT ST_XMax('BOX3D(1 2 3, 4 5 6)');
    st_xmax
    -------
    4

    SELECT ST_XMax(ST_GeomFromText('LINESTRING(1 3 4, 5 6 7)'));
    st_xmax
    -------
    5

    SELECT ST_XMax(CAST('BOX(-3 2, 3 4)' As box2d));
    st_xmax
    -------
    3
    --Observe THIS DOES NOT WORK because it will try to autocast the string representation to a BOX3D
    SELECT ST_XMax('LINESTRING(1 3, 5 6)');

    --ERROR:  BOX3D parser - doesn't start with BOX3D(

    SELECT ST_XMax(ST_GeomFromEWKT('CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)'));
    st_xmax
    --------
    220288.248780547

### See Also

ST_XMin, ST_YMax, ST_YMin, ST_ZMax, ST_ZMin

ST_XMin

Returns X minima of a bounding box 2d or 3d or a geometry.

    			float ST_XMin
    			box3d  aGeomorBox2DorBox3D

### Description

Returns X minima of a bounding box 2d or 3d or a geometry.

Although this function is only defined for box3d, it will work for box2d and geometry because of the auto-casting behavior defined for geometries and box2d. However you can not feed it a geometry or box2d text representation, since that will not auto-cast.

&Z_support;

&curve_support;

### Examples

    SELECT ST_XMin('BOX3D(1 2 3, 4 5 6)');
    st_xmin
    -------
    1

    SELECT ST_XMin(ST_GeomFromText('LINESTRING(1 3 4, 5 6 7)'));
    st_xmin
    -------
    1

    SELECT ST_XMin(CAST('BOX(-3 2, 3 4)' As box2d));
    st_xmin
    -------
    -3
    --Observe THIS DOES NOT WORK because it will try to autocast the string representation to a BOX3D
    SELECT ST_XMin('LINESTRING(1 3, 5 6)');

    --ERROR:  BOX3D parser - doesn't start with BOX3D(

    SELECT ST_XMin(ST_GeomFromEWKT('CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)'));
    st_xmin
    --------
    220186.995121892

### See Also

ST_XMax, ST_YMax, ST_YMin, ST_ZMax, ST_ZMin

ST_Y

Return the Y coordinate of the point, or NULL if not available. Input must be a point.

    			float ST_Y
    			geometry  a_point

### Description

Return the Y coordinate of the point, or NULL if not available. Input must be a point.

&sfs_compliant;

&sqlmm_compliant; SQL-MM 3: 6.1.4

&Z_support;

### Examples

    SELECT ST_Y(ST_GeomFromEWKT('POINT(1 2 3 4)'));
     st_y
    ------
    	2
    (1 row)

    SELECT ST_Y(ST_Centroid(ST_GeomFromEWKT('LINESTRING(1 2 3 4, 1 1 1 1)')));
     st_y
    ------
      1.5
    (1 row)

### See Also

ST_Centroid, ST_GeomFromEWKT, ST_M, ST_X, ST_YMax, ST_YMin, ST_Z

ST_YMax

Returns Y maxima of a bounding box 2d or 3d or a geometry.

    			float ST_YMax
    			box3d  aGeomorBox2DorBox3D

### Description

Returns Y maxima of a bounding box 2d or 3d or a geometry.

Although this function is only defined for box3d, it will work for box2d and geometry because of the auto-casting behavior defined for geometries and box2d. However you can not feed it a geometry or box2d text representation, since that will not auto-cast.

&Z_support;

&curve_support;

### Examples

    SELECT ST_YMax('BOX3D(1 2 3, 4 5 6)');
    st_ymax
    -------
    5

    SELECT ST_YMax(ST_GeomFromText('LINESTRING(1 3 4, 5 6 7)'));
    st_ymax
    -------
    6

    SELECT ST_YMax(CAST('BOX(-3 2, 3 4)' As box2d));
    st_ymax
    -------
    4
    --Observe THIS DOES NOT WORK because it will try to autocast the string representation to a BOX3D
    SELECT ST_YMax('LINESTRING(1 3, 5 6)');

    --ERROR:  BOX3D parser - doesn't start with BOX3D(

    SELECT ST_YMax(ST_GeomFromEWKT('CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)'));
    st_ymax
    --------
    150506.126829327

### See Also

ST_XMin, ST_XMax, ST_YMin, ST_ZMax, ST_ZMin

ST_YMin

Returns Y minima of a bounding box 2d or 3d or a geometry.

    			float ST_YMin
    			box3d  aGeomorBox2DorBox3D

### Description

Returns Y minima of a bounding box 2d or 3d or a geometry.

Although this function is only defined for box3d, it will work for box2d and geometry because of the auto-casting behavior defined for geometries and box2d. However you can not feed it a geometry or box2d text representation, since that will not auto-cast.

&Z_support;

&curve_support;

### Examples

    SELECT ST_YMin('BOX3D(1 2 3, 4 5 6)');
    st_ymin
    -------
    2

    SELECT ST_YMin(ST_GeomFromText('LINESTRING(1 3 4, 5 6 7)'));
    st_ymin
    -------
    3

    SELECT ST_YMin(CAST('BOX(-3 2, 3 4)' As box2d));
    st_ymin
    -------
    2
    --Observe THIS DOES NOT WORK because it will try to autocast the string representation to a BOX3D
    SELECT ST_YMin('LINESTRING(1 3, 5 6)');

    --ERROR:  BOX3D parser - doesn't start with BOX3D(

    SELECT ST_YMin(ST_GeomFromEWKT('CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)'));
    st_ymin
    --------
    150406

### See Also

ST_GeomFromEWKT, ST_XMin, ST_XMax, ST_YMax, ST_ZMax, ST_ZMin

ST_Z

Return the Z coordinate of the point, or NULL if not available. Input must be a point.

    			float ST_Z
    			geometry  a_point

### Description

Return the Z coordinate of the point, or NULL if not available. Input must be a point.

&sqlmm_compliant;

&Z_support;

### Examples

    SELECT ST_Z(ST_GeomFromEWKT('POINT(1 2 3 4)'));
     st_z
    ------
    	3
    (1 row)

### See Also

ST_GeomFromEWKT, ST_M, ST_X, ST_Y, ST_ZMax, ST_ZMin

ST_ZMax

Returns Z minima of a bounding box 2d or 3d or a geometry.

    			float ST_ZMax
    			box3d  aGeomorBox2DorBox3D

### Description

Returns Z maxima of a bounding box 2d or 3d or a geometry.

Although this function is only defined for box3d, it will work for box2d and geometry because of the auto-casting behavior defined for geometries and box2d. However you can not feed it a geometry or box2d text representation, since that will not auto-cast.

&Z_support;

&curve_support;

### Examples

    SELECT ST_ZMax('BOX3D(1 2 3, 4 5 6)');
    st_zmax
    -------
    6

    SELECT ST_ZMax(ST_GeomFromEWKT('LINESTRING(1 3 4, 5 6 7)'));
    st_zmax
    -------
    7

    SELECT ST_ZMax('BOX3D(-3 2 1, 3 4 1)' );
    st_zmax
    -------
    1
    --Observe THIS DOES NOT WORK because it will try to autocast the string representation to a BOX3D
    SELECT ST_ZMax('LINESTRING(1 3 4, 5 6 7)');

    --ERROR:  BOX3D parser - doesn't start with BOX3D(

    SELECT ST_ZMax(ST_GeomFromEWKT('CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)'));
    st_zmax
    --------
    3

### See Also

ST_GeomFromEWKT, ST_XMin, ST_XMax, ST_YMax, ST_YMin, ST_ZMax

ST_Zmflag

Returns ZM (dimension semantic) flag of the geometries as a small int. Values are: 0=2d, 1=3dm, 2=3dz, 3=4d.

    			smallint ST_Zmflag
    			geometry  geomA

### Description

Returns ZM (dimension semantic) flag of the geometries as a small int. Values are: 0=2d, 1=3dm, 2=3dz, 3=4d.

&Z_support;

&curve_support;

### Examples

    SELECT ST_Zmflag(ST_GeomFromEWKT('LINESTRING(1 2, 3 4)'));
     st_zmflag
    -----------
    		 0

    SELECT ST_Zmflag(ST_GeomFromEWKT('LINESTRINGM(1 2 3, 3 4 3)'));
     st_zmflag
    -----------
    		 1

    SELECT ST_Zmflag(ST_GeomFromEWKT('CIRCULARSTRING(1 2 3, 3 4 3, 5 6 3)'));
     st_zmflag
    -----------
    		 2
    SELECT ST_Zmflag(ST_GeomFromEWKT('POINT(1 2 3 4)'));
     st_zmflag
    -----------
    		 3

### See Also

ST_CoordDim, ST_NDims, ST_Dimension

ST_ZMin

Returns Z minima of a bounding box 2d or 3d or a geometry.

    			float ST_ZMin
    			box3d  aGeomorBox2DorBox3D

### Description

Returns Z minima of a bounding box 2d or 3d or a geometry.

Although this function is only defined for box3d, it will work for box2d and geometry because of the auto-casting behavior defined for geometries and box2d. However you can not feed it a geometry or box2d text representation, since that will not auto-cast.

&Z_support;

&curve_support;

### Examples

    SELECT ST_ZMin('BOX3D(1 2 3, 4 5 6)');
    st_zmin
    -------
    3

    SELECT ST_ZMin(ST_GeomFromEWKT('LINESTRING(1 3 4, 5 6 7)'));
    st_zmin
    -------
    4

    SELECT ST_ZMin('BOX3D(-3 2 1, 3 4 1)' );
    st_zmin
    -------
    1
    --Observe THIS DOES NOT WORK because it will try to autocast the string representation to a BOX3D
    SELECT ST_ZMin('LINESTRING(1 3 4, 5 6 7)');

    --ERROR:  BOX3D parser - doesn't start with BOX3D(

    SELECT ST_ZMin(ST_GeomFromEWKT('CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)'));
    st_zmin
    --------
    1

### See Also

ST_GeomFromEWKT, ST_GeomFromText, ST_XMin, ST_XMax, ST_YMax, ST_YMin, ST_ZMax