ST_MidPoint function

The ST_MidPoint function takes a curve as an input parameter and returns the point on the curve that is equidistant from both end points of the curve, measured along the curve. The resulting point is represented in the spatial reference system of the specified curve.

If the specified curve is empty, then an empty point is returned. If the specified curve is null, then null is returned.

If the curve contains Z coordinates or M coordinates (measures), the midpoint is determined solely by the values of the X and Y coordinates in the curve. The Z coordinate and measure in the returned point are interpolated.

Syntax

Read syntax diagramSkip visual syntax diagramST_MidPoint(curve)

Parameter

curve
A value of type ST_Curve or one of its subtypes that represents the curve for which the point in the middle is returned.

Return type

db2gse.ST_Point

Example

This example illustrates the use of ST_MidPoint for returning the midpoint of curves.

CREATE TABLE sample_lines (id INTEGER, geometry ST_LineString)

INSERT INTO sample_lines (id, geometry)
  VALUES (1, ST_LineString ('linestring (0 0, 0 10, 0 20, 0 30, 0 40)', 1 ) )

INSERT INTO sample_lines (id, geometry)
  VALUES (2, ST_LineString ('linestring (2 2, 3 5, 3 3, 4 4, 5 5, 6 6)', 1 ) )

INSERT INTO sample_lines (id, geometry)
  VALUES (3, ST_LineString ('linestring (0 10, 0 0, 10 0, 10 10)', 1 ) )

INSERT INTO sample_lines (id, geometry)
  VALUES (4, ST_LineString ('linestring (0 20, 5 20, 10 20, 15 20)', 1 ) )

SELECT id, CAST( ST_AsText( ST_MidPoint(geometry) ) AS VARCHAR(50) ) MID_POINT
  FROM sample_lines
Results:

ID         MID_POINT
---------- ------------------------------------
          1 POINT (0.000000 20.000000)
          2 POINT (3.000000 3.459818)
          3 POINT (5.000000 0.000000)
          4 POINT (7.500000 20.000000)