From e447ee1d39656698f87e835639ba117fdd6d9e20 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Fri, 15 May 2015 09:23:26 +0000 Subject: [PATCH] Deprecate ST_Length2D_Spheroid, renamed to ST_Length2DSpheroid See #2748 git-svn-id: http://svn.osgeo.org/postgis/trunk@13507 b70326c6-7e19-0410-871a-916f4a2858ee --- doc/reference_measure.xml | 21 ++++++++++++--------- postgis/lwgeom_spheroid.c | 13 ++++--------- postgis/postgis.sql.in | 13 +++++++++++-- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/doc/reference_measure.xml b/doc/reference_measure.xml index 2b80364bb..fac747ba0 100644 --- a/doc/reference_measure.xml +++ b/doc/reference_measure.xml @@ -2940,7 +2940,7 @@ CAST('SPHEROID["GRS_1980",6378137,298.257222101]' As spheroid) As sph_m) as foo - ST_Length2D_Spheroid + ST_Length2DSpheroid Calculates the 2D length of a linestring/multilinestring on an ellipsoid. This is useful if the coordinates of the geometry are in @@ -2950,7 +2950,7 @@ CAST('SPHEROID["GRS_1980",6378137,298.257222101]' As spheroid) As sph_m) as foo - float ST_Length2D_Spheroid + float ST_Length2DSpheroid geometry a_linestring spheroid a_spheroid @@ -2974,19 +2974,22 @@ CAST('SPHEROID["GRS_1980",6378137,298.257222101]' As spheroid) As sph_m) as foo Will return 0 for anything that is not a MULTILINESTRING or LINESTRING This is much like except it will throw away the Z coordinate in calculations. + Availability: 1.2.2 + Changed: 2.2.0 In prior versions this used to be called ST_Length2D_Spheroid + Examples - SELECT ST_Length2D_Spheroid( geometry_column, + SELECT ST_Length2DSpheroid( geometry_column, 'SPHEROID["GRS_1980",6378137,298.257222101]' ) FROM geometry_table; -SELECT ST_Length2D_Spheroid( the_geom, sph_m ) As tot_len, -ST_Length2D_Spheroid(ST_GeometryN(the_geom,1), sph_m) As len_line1, -ST_Length2D_Spheroid(ST_GeometryN(the_geom,2), sph_m) As len_line2 +SELECT ST_Length2DSpheroid( the_geom, sph_m ) As tot_len, +ST_Length2DSpheroid(ST_GeometryN(the_geom,1), sph_m) As len_line1, +ST_Length2DSpheroid(ST_GeometryN(the_geom,2), sph_m) As len_line2 FROM (SELECT ST_GeomFromText('MULTILINESTRING((-118.584 38.374,-118.583 38.5), (-71.05957 42.3589 , -71.061 43))') As the_geom, CAST('SPHEROID["GRS_1980",6378137,298.257222101]' As spheroid) As sph_m) as foo; @@ -2995,9 +2998,9 @@ CAST('SPHEROID["GRS_1980",6378137,298.257222101]' As spheroid) As sph_m) as foo 85204.5207562955 | 13986.8725229309 | 71217.6482333646 --3D Observe same answer -SELECT ST_Length2D_Spheroid( the_geom, sph_m ) As tot_len, -ST_Length2D_Spheroid(ST_GeometryN(the_geom,1), sph_m) As len_line1, -ST_Length2D_Spheroid(ST_GeometryN(the_geom,2), sph_m) As len_line2 +SELECT ST_Length2DSpheroid( the_geom, sph_m ) As tot_len, +ST_Length2DSpheroid(ST_GeometryN(the_geom,1), sph_m) As len_line1, +ST_Length2DSpheroid(ST_GeometryN(the_geom,2), sph_m) As len_line2 FROM (SELECT ST_GeomFromEWKT('MULTILINESTRING((-118.584 38.374 20,-118.583 38.5 30), (-71.05957 42.3589 75, -71.061 43 90))') As the_geom, CAST('SPHEROID["GRS_1980",6378137,298.257222101]' As spheroid) As sph_m) as foo; diff --git a/postgis/lwgeom_spheroid.c b/postgis/lwgeom_spheroid.c index 0a8303304..e3cf21f67 100644 --- a/postgis/lwgeom_spheroid.c +++ b/postgis/lwgeom_spheroid.c @@ -310,26 +310,21 @@ distance_ellipse_calculation(double lat1, double long1, return sphere->b * (A * (sigma - dsigma)); } - /* * Find the "length of a geometry" * length2d_spheroid(point, sphere) = 0 * length2d_spheroid(line, sphere) = length of line * length2d_spheroid(polygon, sphere) = 0 - * -- could make sense to return sum(ring perimeter) + * -- could make sense to return sum(ring perimeter) * uses ellipsoidal math to find the distance * x's are longitude, and y's are latitude - both in decimal degrees */ PG_FUNCTION_INFO_V1(LWGEOM_length2d_ellipsoid); Datum LWGEOM_length2d_ellipsoid(PG_FUNCTION_ARGS) { - GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0); - SPHEROID *sphere = (SPHEROID *) PG_GETARG_POINTER(1); - LWGEOM *lwgeom = lwgeom_from_gserialized(geom); - double dist = lwgeom_length_spheroid(lwgeom, sphere); - lwgeom_free(lwgeom); - PG_FREE_IF_COPY(geom, 0); - PG_RETURN_FLOAT8(dist); + Datum geom2d = DirectFunctionCall1(LWGEOM_force_2d, PG_GETARG_DATUM(0)); + PG_RETURN_DATUM(DirectFunctionCall2(LWGEOM_length_ellipsoid_linestring, + geom2d, PG_GETARG_DATUM(1))); } diff --git a/postgis/postgis.sql.in b/postgis/postgis.sql.in index 862c09638..461757a3a 100644 --- a/postgis/postgis.sql.in +++ b/postgis/postgis.sql.in @@ -1230,13 +1230,22 @@ CREATE OR REPLACE FUNCTION ST_length_spheroid(geometry, spheroid) $$ LANGUAGE 'sql' IMMUTABLE STRICT; --- Availability: 1.2.2 -CREATE OR REPLACE FUNCTION ST_length2d_spheroid(geometry, spheroid) +-- Availability: 2.2.0 +CREATE OR REPLACE FUNCTION ST_Length2DSpheroid(geometry, spheroid) RETURNS FLOAT8 AS 'MODULE_PATHNAME','LWGEOM_length2d_ellipsoid' LANGUAGE 'c' IMMUTABLE STRICT COST 100; +-- Availability: 1.2.2 +-- Deprecation in 2.2.0 +CREATE OR REPLACE FUNCTION ST_length2d_spheroid(geometry, spheroid) + RETURNS FLOAT8 AS + $$ SELECT _postgis_deprecate('ST_Length2D_Spheroid', 'ST_Length2DSpheroid', '2.2.0'); + SELECT ST_Length2DSpheroid($1,$2); + $$ + LANGUAGE 'sql' IMMUTABLE STRICT; + -- Availability: 2.0.0 CREATE OR REPLACE FUNCTION ST_3DPerimeter(geometry) RETURNS FLOAT8 -- 2.40.0