[postgis-tickets] [SCM] PostGIS branch master updated. 3.3.0alpha1-62-g08dcf2aa5

git at osgeo.org git at osgeo.org
Wed Jun 15 15:36:51 PDT 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".

The branch, master has been updated
       via  08dcf2aa5f2e0bd9ee195183644d4c3ee8cad6c4 (commit)
      from  a8917e5f17035c3f6470a73767bf0d8d820d8451 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 08dcf2aa5f2e0bd9ee195183644d4c3ee8cad6c4
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Wed Jun 15 15:36:40 2022 -0700

    Add ST_DistanceSphere(geom, geom, radius) and
    ST_DistanceSpheroid(geom, geom) for a little
    more convenience and functionality.

diff --git a/doc/reference_measure.xml b/doc/reference_measure.xml
index 47d15b05a..2891504bd 100644
--- a/doc/reference_measure.xml
+++ b/doc/reference_measure.xml
@@ -673,7 +673,8 @@ SELECT ST_3DDistance(poly, mline) As dist3d,
 		  <funcprototype>
 			<funcdef>float <function>ST_DistanceSphere</function></funcdef>
 			<paramdef><type>geometry </type> <parameter>geomlonlatA</parameter></paramdef>
-			<paramdef><type>geometry </type> <parameter>geomlonlatB</parameter></paramdef>
+            <paramdef><type>geometry </type> <parameter>geomlonlatB</parameter></paramdef>
+            <paramdef choice="opt"><type>float8 </type> <parameter>radius=6371008</parameter></paramdef>
 		  </funcprototype>
 		</funcsynopsis>
 	  </refsynopsisdiv>
@@ -732,7 +733,7 @@ FROM
 			<funcdef>float <function>ST_DistanceSpheroid</function></funcdef>
 			<paramdef><type>geometry </type> <parameter>geomlonlatA</parameter></paramdef>
 			<paramdef><type>geometry </type> <parameter>geomlonlatB</parameter></paramdef>
-			<paramdef><type>spheroid </type> <parameter>measurement_spheroid</parameter></paramdef>
+			<paramdef choice="opt"><type>spheroid </type><parameter>measurement_spheroid=WGS84</parameter></paramdef>
 		  </funcprototype>
 		</funcsynopsis>
 	  </refsynopsisdiv>
diff --git a/postgis/lwgeom_spheroid.c b/postgis/lwgeom_spheroid.c
index fd96bc495..61631427b 100644
--- a/postgis/lwgeom_spheroid.c
+++ b/postgis/lwgeom_spheroid.c
@@ -531,17 +531,36 @@ Datum geometry_distance_spheroid(PG_FUNCTION_ARGS)
 PG_FUNCTION_INFO_V1(LWGEOM_distance_ellipsoid);
 Datum LWGEOM_distance_ellipsoid(PG_FUNCTION_ARGS)
 {
+	SPHEROID s;
+
+	/* No spheroid provided */
+	if (PG_NARGS() == 2) {
+		/* Init to WGS84 */
+		spheroid_init(&s, 6378137.0, 6356752.314245179498);
+		PG_RETURN_DATUM(DirectFunctionCall4(geometry_distance_spheroid,
+			PG_GETARG_DATUM(0),
+			PG_GETARG_DATUM(1),
+			PointerGetDatum(&s),
+			BoolGetDatum(true)));
+	}
+
 	PG_RETURN_DATUM(DirectFunctionCall4(geometry_distance_spheroid,
-	                                    PG_GETARG_DATUM(0), PG_GETARG_DATUM(1), PG_GETARG_DATUM(2), BoolGetDatum(true)));
+		PG_GETARG_DATUM(0),
+		PG_GETARG_DATUM(1),
+		PG_GETARG_DATUM(2),
+		BoolGetDatum(true)));
 }
 
 PG_FUNCTION_INFO_V1(LWGEOM_distance_sphere);
 Datum LWGEOM_distance_sphere(PG_FUNCTION_ARGS)
 {
 	SPHEROID s;
-
 	/* Init to WGS84 */
 	spheroid_init(&s, 6378137.0, 6356752.314245179498);
+
+	if (PG_NARGS() == 3) {
+		s.radius = PG_GETARG_FLOAT8(2);
+	}
 	s.a = s.b = s.radius;
 
 	PG_RETURN_DATUM(DirectFunctionCall4(geometry_distance_spheroid,
diff --git a/postgis/postgis.sql.in b/postgis/postgis.sql.in
index 5e1d202ff..49cfcdbdd 100644
--- a/postgis/postgis.sql.in
+++ b/postgis/postgis.sql.in
@@ -1345,11 +1345,18 @@ CREATE OR REPLACE FUNCTION ST_IsPolygonCCW(geometry)
 	_COST_LOW;
 
 -- Availability: 2.0.0
-CREATE OR REPLACE FUNCTION ST_DistanceSpheroid(geom1 geometry, geom2 geometry,spheroid)
+CREATE OR REPLACE FUNCTION ST_DistanceSpheroid(geom1 geometry, geom2 geometry, spheroid)
 	RETURNS FLOAT8
 	AS 'MODULE_PATHNAME','LWGEOM_distance_ellipsoid'
 	LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
-	_COST_MEDIUM; --upped this
+	_COST_MEDIUM;
+
+-- Availability: 3.3.0
+CREATE OR REPLACE FUNCTION ST_DistanceSpheroid(geom1 geometry, geom2 geometry)
+	RETURNS FLOAT8
+	AS 'MODULE_PATHNAME','LWGEOM_distance_ellipsoid'
+	LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
+	_COST_MEDIUM;
 
 -- Minimum distance. 2D only.
 CREATE OR REPLACE FUNCTION ST_Distance(geom1 geometry, geom2 geometry)
@@ -6056,6 +6063,13 @@ CREATE OR REPLACE FUNCTION ST_DistanceSphere(geom1 geometry, geom2 geometry)
 	'select @extschema at .ST_distance( @extschema at .geography($1), @extschema at .geography($2),false)'
 	LANGUAGE 'sql' IMMUTABLE STRICT PARALLEL SAFE;
 
+-- Availability: 3.3.0
+CREATE OR REPLACE FUNCTION ST_DistanceSphere(geom1 geometry, geom2 geometry, radius float8)
+	RETURNS FLOAT8
+	AS 'MODULE_PATHNAME','LWGEOM_distance_sphere'
+	LANGUAGE 'c' IMMUTABLE STRICT
+ 	_COST_HIGH;
+
 ---------------------------------------------------------------
 -- GEOMETRY_COLUMNS view support functions
 ---------------------------------------------------------------

-----------------------------------------------------------------------

Summary of changes:
 doc/reference_measure.xml |  5 +++--
 postgis/lwgeom_spheroid.c | 23 +++++++++++++++++++++--
 postgis/postgis.sql.in    | 18 ++++++++++++++++--
 3 files changed, 40 insertions(+), 6 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list