ST_MaxX function

The ST_MaxX function takes a geometry as an input parameter and returns its maximum X coordinate.

If the given geometry is null or is empty, then null is returned.

This function can also be called as a method.

Syntax

Read syntax diagramSkip visual syntax diagramdb2gse.ST_MaxX(geometry)

Parameter

geometry
A value of type ST_Geometry or one of its subtypes for which the maximum X coordinate is returned.

Return type

DOUBLE

Examples

Example 1
This example illustrats the use of the ST_MaxX function. Three polygons are created and inserted into the SAMPLE_POLYS table. The third example illustrates how you can use all of the functions that return the maximum and minimum coordinate values to assess the spatial range of the geometries that are stored in a particular spatial column.

SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse
CREATE TABLE sample_polys (id INTEGER, geometry ST_Polygon)

INSERT INTO sample_polys
  VALUES (1, ST_Polygon('polygon zm ((110 120 20 3,
                                      110 140 22 3,
                                      120 130 26 4,
                                      110 120 20 3))', 0) )

INSERT INTO sample_polys
  VALUES (2, ST_Polygon('polygon zm ((0 0 40 7,
                                      0 4 35 9,
                                      5 4 32 12,
                                      5 0 31 5,
                                      0 0 40 7))', 0) )

INSERT INTO sample_polys
  VALUES (3, ST_Polygon('polygon zm ((12 13 10 16,
                                      8 4 10 12,
                                      9 4 12 11,
                                      12 13 10 16))', 0) )
Example 2
This example finds the maximum X coordinate of each polygon in SAMPLE_POLYS.

SELECT id, CAST ( ST_MaxX(geometry) AS INTEGER) MAX_X_COORD
  FROM sample_polys
Results:

ID          MAX_X_COORD
----------- ------------
          1          120
          2            5
          3           12
Example 3
This example finds the maximum X coordinate that exists for all polygons in the GEOMETRY column.

SELECT CAST ( MAX ( ST_MaxX(geometry) ) AS INTEGER) OVERALL_MAX_X
  FROM sample_polys
Results:

OVERALL_MAX_X
--------------
           120
Example 4
This example finds the spatial extent (overall minimum to overall maximum) of all the polygons in the SAMPLE_POLYS table. This calculation is typically used to compare the actual spatial extent of the geometries to the spatial extent of the spatial reference system associated with the data to determine if the data has room to grow.

SELECT CAST ( MIN (ST_MinX (geometry)) AS INTEGER) MIN_X,
       CAST ( MIN (ST_MinY (geometry)) AS INTEGER) MIN_Y,
       CAST ( MIN (ST_MinZ (geometry)) AS INTEGER) MIN_Z,
       CAST ( MIN (ST_MinM (geometry)) AS INTEGER) MIN_M,
       CAST ( MAX (ST_MaxX (geometry)) AS INTEGER) MAX_X,
       CAST ( MAX (ST_MaxY (geometry)) AS INTEGER) MAX_Y,
       CAST ( MAX (ST_MaxZ (geometry)) AS INTEGER) MAX_Z,
       CAST ( MAX (ST_MaxmM(geometry)) AS INTEGER) MAX_M,
  FROM sample_polys
Results:

MIN_X    MIN_Y    MIN_Z    MIN_M    MAX_X    MAX_Y    MAX_Z    MAX_M
-------- -------- -------- -------- -------- -------- -------- --------
       0        0       10        3      120      140       40       16