Intro to SAP HANA Spatial: Z and M coordinates

Intro to SAP HANA Spatial: Z and M coordinates

Geometries can optionally have Z (3rd dimension) and M (measure) values associated with each point in addition to X and Y coordinates

You will learn

You will learn the basics of multidimensional coordinate systems that introduce Z (3rd dimension) and M (measure) coordinates to geometries’ points.

Details

Step 1: Introducing Z and M coordinates

All geometries have at least two coordinate dimensions: the X and Y defining 2D coordinates of each point. For geographic spatial reference systems, these are the latitude and longitude of a point.

Geometries can optionally have Z and / or M values associated with each point in the geometry. The Z value introduces the third dimension coordinate. The Z value usually is used to indicate the height, or elevation. The measure value M can be used to record additional non-coordinate values at various points within a geometry. The M value is most often used in geometries with the linear reference system, e.g. where M stores a distance value from a defined starting point.

To find the number of coordinates stored within each point of a geometry use the ST_CoordDim method. The following values may be returned:2 - The geometry contains only two coordinates (X and Y)3 - The geometry contains one additional coordinate (either Z or M) for each point4 - The geometry contains two additional coordinates (both Z and M) for each point

Methods similar to retrieving X and Y are used to retrieve the value of either Z or M of geometries:- ST_Z() and ST_M() - only for points,- ST_Zmin(), ST_Zmax(), ST_Mmin(), ST_Mmax() - for all geometries.

As mentioned above these additional coordinate Z and M values are used to store and retrieve additional information, but are not considered during spatial computations or set operations.

For example the result of the line string calculation from one of the previous tutorials will still be 5, and not 13 if Z value of the string’s end point is 12. As a fun fact: (5, 12, 13) is another example of the Pythagorean triple, same as (3, 4, 5).

SELECT NEW ST_LineString('LineString Z(0 0 0, 4 3 12)').ST_Length() as StringLength FROM dummy;
-- Result is still 5, same as in the following
-- SELECT NEW ST_LineString('LineString (0 0, 4 3)').ST_Length() FROM dummy;

Another modified example from a previous tutorial.

SELECT NEW ST_Point ('POINT Z(1 1 100)').ST_Within(NEW ST_Point('POINT Z(0 0 0.5)').ST_Buffer(2)) as WITHIN FROM dummy;
-- Result is True as point (1,1) is still within a buffer around the point (0,0) even though they have different "height" location defined by Z

The method ST_Buffer() applied to a point with 3 dimensions flattens a calculated geometry, making it 2 dimensional: X and Y only. And the method ST_Within does not take Z dimension into consideration.

SELECT NEW ST_Point('POINT Z(0 0 0.5)').ST_Buffer(2).ST_CoordDim() from DUMMY;
-- Result is 2 (coordinates dimensions of an output polygon)