ST_X

Definition

ST_X takes an ST_Point as an input parameter and returns its x-coordinate. In SQLite, ST_X can also update the x-coordinate of an ST_Point.

Syntax

Oracle and PostgreSQL

sde.st_x (point1 sde.st_point)

SQLite

st_x (point1 geometryblob)
st_x (input_point geometryblob, new_Xvalue double)

Return type

Double precision

The ST_X function can be used with SQLite to update the x-coordinate of a point. In that case, a geometryblob is returned.

Examples

The x_test table is created with two columns: the gid column, which uniquely identifies the row, and the pt1 point column.

The INSERT statements insert two rows. One is a point without a z-coordinate or measure. The other column has both a z-coordinate and measure.

The SELECT query uses the ST_X function to get the x-coordinate of each point feature.

Oracle

CREATE TABLE x_test (
 gid integer unique,
 pt1 sde.st_point
);
INSERT INTO X_TEST VALUES (
 1,
 sde.st_pointfromtext ('point (10.02 20.01)', 4326)
);

INSERT INTO X_TEST VALUES (
 2,
 sde.st_pointfromtext ('point zm(10.1 20.01 5 7)', 4326)
);
SELECT gid, sde.st_x (pt1) "The X coordinate"
 FROM X_TEST;

       GID       The X coordinate

         1            10.02
         2            10.10

PostgreSQL

CREATE TABLE x_test (
 gid integer unique,
 pt1 sde.st_point
);
INSERT INTO x_test VALUES (
 1,
 sde.st_point ('point (10.02 20.01)', 4326)
);

INSERT INTO x_test VALUES (
 2,
 sde.st_point ('point zm(10.1 20.01 5 7)', 4326)
);
SELECT gid, sde.st_x (pt1) 
 AS "The X coordinate"
 FROM x_test;

       gid       The X coordinate

         1            10.02
         2            10.10

SQLite

CREATE TABLE x_test (gid integer);

SELECT AddGeometryColumn(
 NULL,
 'x_test',
 'pt1',
 4326,
 'pointzm',
 'xyzm',
 'null'
);
INSERT INTO x_test VALUES (
 1,
 st_point ('point (10.02 20.01)', 4326)
);

INSERT INTO x_test VALUES (
 2,
 st_point ('point zm(10.1 20.01 5 7)', 4326)
);
SELECT gid, st_x (pt1) 
 AS "The X coordinate"
 FROM x_test;

       gid       The X coordinate

         1            10.02
         2            10.10

The ST_X function can also be used to update the coordinate value of an existing point. In this example, ST_X is used to update the x-coordinate value of the first point in x_test.

UPDATE x_test
 SET pt1=st_x(
  (SELECT pt1 FROM x_test WHERE gid=1),
  10.04
  )
 WHERE gid=1;

Related Topics

6/19/2015