# WL#10416: Ellipsoidal ST_Length

Affects: Server-8.0
—
Status: Complete

ST_Length currently only supports computations in Cartesian spatial reference systems (SRSs). This WL extends ST_Length to detect that its parameter is in a geographic (ellipsoidal) SRS and to compute the length on the ellipsoid.

Projected SRSs and SRID 0 will still return the same result as before. If the SRID refers to a geographic SRS, the result will be different.

- F-1
- ST_Length MUST return NULL if its argument is NULL.
- F-2
- If the argument is not a syntactically well-formed geometry, ST_Length MUST raise ER_GIS_INVALID_DATA during function evaluation.
- F-3
- ST_Length MUST return NULL if its argument is a geometry that is not a linestring or a multilinestring.
- F-4
- ST_Length MUST NOT return NULL if the parameter is a linestring or a multilinestring.
- F-5
- If the argument is in an undefined SRS, ST_Length MUST raise ER_SRS_NOT_FOUND during function evaluation.
- F-6
- If the argument is geometrically invalid, ST_Length MUST either return a length result or raise an error. If a length is returned, the value is undefined, i.e., it may be any number.
- F-7
- If the argument is a valid linestring in a Cartesian SRS, ST_Length MUST return the Cartesian length of the linestring.
- F-8
- If the argument is a valid multilinestring in a Cartesian SRS, ST_Length MUST return the sum of the Cartesian length of the linestrings.
- F-9
- If the argument is a valid linestring in a geographic SRS, ST_Length MUST return the geodetic length of the linestring in that SRS. The result MUST be in meters.
- F-10
- If the argument is a valid multilinestring in a geographic SRS, ST_Length MUST return the sum of the geodetic length of the linestrings in that SRS. The result MUST be in meters.
- F-11
- If a length computation results in +Inf, ST_Length MUST raise ER_DATA_OUT_OF_RANGE during function evaluation.
- F-12
- If the argument is a geometry in a geographic SRS and a longitude value is not in the range (-180,180] (in degrees -- other limits in other units), ST_Length MUST raise ER_LONGITUDE_OUT_OF_RANGE.(*)
- F-13
- If the argument is a geometry in a geographic SRS and a latitude value is not in the range [-90,90] (in degrees -- other limits in other units), ST_Length MUST raise ER_LATITUDE_OUT_OF_RANGE.(*)

(*) The exact limits will deviate slightly because of floating point arithmetics.

- I-1
- No new files.
- I-2
- No new syntax.
- I-3
- No new commands.
- I-4
- No new tools.
- I-5
- The semantics of interface SQL01 are changed: If the linestring is in a geographic SRS, ST_Length will return the geodetic length of the the linestring, or raise an error if the coordinates are out of bounds. Other calculations will remain as they are today.
- I-6
- No new errors or warnings.

- See WL#9347 for an example of how to implement geography support. Follow the same pattern.
- Rename the item from Item_func_glength to Item_func_st_length.
- Make sure resolve_type() sets maybe_null correctly.
- Re-implement val_real() based on the pattern from Item_func_distance::val_real().

Copyright (c) 2000, 2020, Oracle Corporation and/or its affiliates. All rights reserved.