# 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'.

&sfs_compliant;

&curve_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

### See Also

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

Do not call with a `GEOMETRYCOLLECTION` as an argument

&sfs_compliant; OGC SPEC s2.1.1.1

&sqlmm_compliant; SQL-MM 3: 5.1.14

&Z_support;

### Examples

    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_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

&sfs_compliant;

&sqlmm_compliant; SQL-MM 3: 5.1.3

&curve_support;

&Z_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_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`.

&sqlmm_compliant; SQL-MM 3: 5.1.2

### Examples

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

### See Also

ST_EndPoint Returns the last point of a `LINESTRING` geometry as a `POINT`.
boolean `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;

### 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_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;

### See Also

,

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_GeometryN Return the 1-based Nth geometry if the geometry is a GEOMETRYCOLLECTION, MULTIPOINT, MULTILINESTRING, MULTICURVE or MULTIPOLYGON. Otherwise, return NULL.
geometry `ST_GeometryN` geometry geomA integer n

### Description

Return the 1-based Nth geometry if the geometry is a GEOMETRYCOLLECTION, MULTIPOINT, MULTILINESTRING, MULTICURVE or MULTIPOLYGON. 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.

&sfs_compliant;

&sqlmm_compliant; SQL-MM 3: 9.1.5

&Z_support;

&curve_support;

### 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);

### See Also

,

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.

&sqlmm_compliant; SQL-MM 3: 5.1.4

### 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

### See Also

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_IsClosed Returns `TRUE` if the `LINESTRING`'s start and end points are coincident.
boolean `ST_IsClosed` geometry g

### Description

Returns `TRUE` if the `LINESTRING`'s start and end points are coincident.

&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;

### 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)

### See Also

ST_IsEmpty Returns true if this Geometry is an empty geometry . If true, then this Geometry represents the empty point set - i.e. GEOMETRYCOLLECTION(EMPTY).
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;

### Examples

    SELECT ST_IsEmpty('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_StartPoint(g)` `~=` `ST_Endpoint(g)`) and (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_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 Returns `true` if the `ST_Geometry` is well formed.
boolean `ST_IsValid` geometry g

### 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.

&sfs_compliant;

&sqlmm_compliant; SQL-MM 3: 5.1.9

### 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_IsValidReason Returns text stating if a geometry is valid or not and if not valid, a reason why.
text `ST_IsValidReason` geometry geomA

### 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.

Availability: 1.4 - requires GEOS >= 3.1.0.

### 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_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_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_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.

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;

### 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_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_NumGeometries If geometry is a GEOMETRYCOLLECTION (or MULTI*) return the number of geometries, otherwise return NULL.
integer `ST_NumGeometries` geometry a_multi_or_geomcollection

### Description

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

&sqlmm_compliant; SQL-MM 3: 9.1.4

### Examples

    --Although ST_NumGeometries will return null when passed a single, you can wrap in ST_Multi to force 1 or more for all geoms
    SELECT ST_NumGeometries(ST_Multi(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_NumInteriorRings Return the number of interior rings of the first polygon in the geometry. This will work with both POLYGON and MULTIPOLYGON types but only looks at the first polygon. Return NULL if there is no polygon in the geometry.
integer `ST_NumInteriorRings` geometry a_polygon

### Description

Return the number of interior rings of the first polygon in the geometry. This will work with both POLYGON and MULTIPOLYGON types but only looks at the first polygon. Return NULL if there is no polygon in the geometry.

&sqlmm_compliant; SQL-MM 3: 8.2.5

### 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 Return the number of interior rings of the first polygon in the geometry. Synonym to ST_NumInteriorRings.
integer `ST_NumInteriorRing` geometry a_polygon

### Description

Return the number of interior rings of the first polygon in the geometry. Synonym to ST_NumInteriorRings. The OpenGIS specs are ambiguous about the exact function naming, so we provide both spellings.

&sqlmm_compliant; SQL-MM 3: 8.2.5

### See Also

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_PointN Return the Nth point in the first linestring or circular linestring in the geometry. Return NULL if there is no linestring in the geometry.
geometry `ST_PointN` geometry a_linestring integer n

### Description

Return the Nth point in the first linestring or circular linestring in the geometry. Return NULL if there is no linestring in the geometry.

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 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;

### 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)

### See Also

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 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

,, ,

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` geometry as a `POINT` or `NULL` if the input parameter is not a `LINESTRING`.

&sqlmm_compliant; SQL-MM 3: 7.1.3

&Z_support;

### 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)

### See Also

,

ST_Summary Returns a text summary of the contents of the `ST_Geometry`.
text `ST_Summary` geometry g

### Description

Returns a text summary of the contents of the geometry.

&Z_support;

### Examples

    SELECT ST_Summary(ST_GeomFromText('LINESTRING(0 0, 1 1)')) As good_line,
    	ST_Summary(ST_GeomFromText('POLYGON((0 0, 1 1, 1 2, 1 1, 0 0))')) As bad_poly
    --results
    	  good_line       |        bad_poly
    ----------------------+-------------------------
    					  |
    Line[B] with 2 points : Polygon[B] with 1 rings
    					  :    ring 0 has 5 points
    					  :

    --3d polygon
    SELECT ST_Summary(ST_GeomFromEWKT('LINESTRING(0 0 1, 1 1 1)')) As good_line,
    	ST_Summary(ST_GeomFromEWKT('POLYGON((0 0 1, 1 1 2, 1 2 3, 1 1 1, 0 0 1))')) As poly

    --results
    	  good_line       |        poly
    ----------------------+-------------------------
    					  |
    Line[ZB] with 2 points : Polygon[ZB] with 1 rings
    					  :    ring 0 has 5 points
    					  :

### See Also

,

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_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_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_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

, ,