Measurement functions

Updated at:

This topic describes the measurement functions in spatiotemporal functions.

Engine and versions

Important

Your Lindorm SQL must be version 2.6.8 or later. For more information about how to view the version of Lindorm SQL, see SQL version guide.

Function list

The following table describes the measurement functions that Lindorm Ganos supports.

Function

Description

ST_Area

Returns the area of the specified polygon Geometry object.

ST_Distance

Returns the Euclidean distance between two Geometry objects on a 2D plane.

ST_DistanceSphere

Returns the shortest distance between two Geometry objects on a sphere.

ST_IsValid

Checks whether the specified Geometry object is valid.

ST_Length

Returns the length of the specified Geometry object in a 2D space.

ST_LengthSphere

Returns the spherical length of the specified Geometry object.

ST_Area

Returns the area of the specified polygon Geometry object.

Syntax

BigDecimal ST_Area(geometry g)

Parameters

Parameter

Description

g

The specified Geometry object.

Note
  • The Geometry object supports the Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection types.

  • For a Geometry object, the 2D Cartesian area is calculated based on the unit that is specified by the Spatial Reference System Identifier (SRID). Lindorm Ganos SQL uses SRID 4326, and the unit is degrees.

  • If the specified Polygon forms multiple closed shapes, the function returns the absolute value of the difference between the areas of the clockwise and counter-clockwise shapes.

  • If the Geometry object is not a Polygon, the function returns 0.

Examples

  • Example 1: The specified Geometry object is a Polygon.

    SELECT ST_Area(ST_GeomFromText('POLYGON((2 2, 2 8, 8 8, 8 2, 2 2))')) AS area;

    Returned result:

    +------+
    | area |
    +------+
    | 36.0 |
    +------+
  • Example 2: The specified Geometry object is a LINESTRING.

    SELECT ST_Area(ST_GeomFromText('LINESTRING(1 3,5 6)')) AS area;

    Result:

    +------+
    | area |
    +------+
    | 0.0  |
    +------+

ST_Distance

Returns the Euclidean distance between two Geometry objects on a 2D plane. The unit is degrees.

Syntax

BigDecimal ST_Distance(geometry geomA, geometry geomB)

Parameters

Parameter

Description

geomA

The first specified Geometry object.

geomB

The second specified Geometry object.

Note
  • The Geometry object supports the Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection types.

  • If one of the Geometry objects is EMPTY, the function returns 0.

Examples

  • Example 1

    SELECT ST_Distance(ST_GeomFromText('POINT(-72.1235 42.3521)'),ST_GeomFromText('LINESTRING(-72.1260 42.45, -72.123 42.1546)')) AS d;

    Returned result:

    +-----------------------+
    |           d           |
    +-----------------------+
    | 0.0015056772638228177 |
    +-----------------------+
  • Example 2

    SELECT ST_Distance(ST_GeomFromText('POINT(-72.1235 42.3521)'),ST_GeomFromText('LINESTRING EMPTY')) AS d;

    Returned result:

    +---+
    | d |
    +---+
    |0.0|
    +---+

ST_DistanceSphere

Returns the shortest distance between two Geometry objects on a sphere. The unit is meters.

Syntax

BigDecimal ST_DistanceSphere(geometry geomA, geometry geomB)

Parameters

Parameter

Description

geomA

The first specified Geometry object.

geomB

The second specified Geometry object.

Note
  • The Geometry object supports the Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection types.

  • If one of the Geometry objects is EMPTY, the function returns 0.

  • If one of the Geometry objects is a Polygon or LineString, the calculation result may have an error in the centimeter range.

Examples

  • Example 1

    SELECT ST_DistanceSphere(ST_GeomFromText('POINT(-72.1235 42.3521)'),ST_GeomFromText('LINESTRING(-72.1260 42.45, -72.123 42.1546)')) AS d;

    Returned result:

    +--------------------+
    |         d          |
    +--------------------+
    | 124.53287523764577 |
    +--------------------+
  • Example 2

    SELECT ST_DistanceSphere(ST_GeomFromText('POINT(-72.1235 42.3521)'),ST_GeomFromText('LINESTRING EMPTY')) AS d;

    Returned result:

    +---+
    | d |
    +---+
    |0.0|
    +---+

ST_IsValid

Checks whether the specified Geometry object is valid. A Geometry object is invalid in cases such as a self-intersecting Polygon object or overlapping Polygon objects within a MultiPolygon object.

Syntax

boolean ST_IsValid(geometry g)

Parameters

Parameter

Description

g

The specified Geometry object.

Example

The pre-setup table creation statement:

CREATE TABLE mapdata (id INT, geom GEOMETRY, PRIMARY KEY(id));

Check whether the geometry object with ID 110000 is valid.

SELECT ST_IsValid(geom) FROM mapdata WHERE id=110000;

Returned result:

+------------------+
| st_isvalid(geom) |
+------------------+
| true             |
+------------------+

A return value of true indicates that the geometry object is valid. A return value of false indicates that the geometry object is invalid.

ST_Length

Returns the length of the specified Geometry object in a 2D space. The unit is degrees.

Syntax

BigDecimal ST_Length(geometry g)

Parameters

Parameter

Description

g

The specified Geometry object.

Note
  • If the Geometry object is a LineString, the function returns the length of the LineString in the Cartesian coordinate system.

  • If the Geometry object is a Polygon, the function returns 0.

Examples

  • Example 1

    SELECT ST_Length(ST_GeomFromText('LINESTRING(1 3,5 6)')) AS length;

    Returned result:

    +--------+
    | length |
    +--------+
    | 5.0    |
    +--------+
  • Example 2

    SELECT ST_Length(ST_GeomFromText('POLYGON((2 2, 2 8, 8 8, 8 2, 2 2))')) AS length;

    Returned result:

    +--------+
    | length |
    +--------+
    | 0.0    |
    +--------+

ST_LengthSphere

Returns the spherical length of the specified Geometry object. The unit is meters.

Syntax

BigDecimal ST_LengthSphere(geometry g)

Parameters

Parameter

Description

g

The specified Geometry object.

Note
  • If the Geometry object is a LineString, the function returns the length of the LineString on a sphere.

  • If the Geometry object is a Polygon, the function returns 0.

Examples

  • Example 1

    SELECT ST_LengthSphere(ST_GeomFromText('LINESTRING(1 3,5 6)')) AS length;

    Returned result:

    +------------------+
    |      length      |
    +------------------+
    | 554137.283806292 |
    +------------------+
  • Example 2

    SELECT ST_LengthSphere(ST_GeomFromText('POLYGON((2 2, 2 8, 8 8, 8 2, 2 2))')) AS length;

    Returned result:

    +--------+
    | length |
    +--------+
    | 0.0    |
    +--------+