Fork me on GitHub

ST_X

Signature

DOUBLE ST_X(GEOMETRY geom);

Description

Returns the x-value of the first coordinate of geom.

Implements the OpenGIS Simple Features Implementation Specification for SQL version 1.2.1.

Examples

SELECT ST_X('MULTIPOINT((4 4), (1 1), (1 0), (0 3)))');
-- Answer: 4.0

SELECT ST_X(
    ST_GeometryN('MULTIPOINT((4 4), (1 1), (1 0), (0 3)))', 2));
-- Answer: 1.0

SELECT ST_X('LINESTRING(2 1, 1 3, 5 2)');
-- Answer: 2.0

SELECT ST_X(ST_PointN('LINESTRING(2 1, 1 3, 5 2)', 3));
-- Answer: 5.0

SELECT ST_X('POLYGON((5 0, 7 0, 7 1, 5 1, 5 0))');
-- Answer: 5.0

SELECT ST_X(
    ST_PointN(
        ST_ExteriorRing('POLYGON((5 0, 7 0, 7 1, 5 1, 5 0))'), 3));
-- Answer: 7.0

SELECT ST_X('MULTIPOLYGON(((0 2, 3 2, 3 6, 0 6, 0 2)),
                          ((5 0, 7 0, 7 1, 5 1, 5 0)))');
-- Answer: 0.0

SELECT ST_X('GEOMETRYCOLLECTION(
               MULTIPOINT((4 4), (1 1), (1 0), (0 3)),
               LINESTRING(2 1, 1 3, 5 2),
               POLYGON((1 2, 4 2, 4 6, 1 6, 1 2)))');
-- Answer: 4.0
See also