From: Regina Obe Date: Sun, 27 Aug 2017 15:17:39 +0000 (+0000) Subject: Allow signed distance for ST_Project (Darafei Praliaskouski) X-Git-Tag: 2.4.0beta1~15 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3aeee83286e2493365e62ab0439c42e6e42ee7ac;p=postgis Allow signed distance for ST_Project (Darafei Praliaskouski) Closes https://github.com/postgis/postgis/pull/138 Closes #3709 git-svn-id: http://svn.osgeo.org/postgis/trunk@15598 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/NEWS b/NEWS index 50d29b5c1..5f36c701a 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,7 @@ PostGIS 2.4.0 - Most aggregates (raster and geometry), and all stable / immutable (raster and geometry) marked as parallel safe - #2249, ST_MakeEmptyCoverage for raster (David Zwarg, ainomieli) + - #3709, Allow signed distance for ST_Project (Darafei Praliaskouski) * Enhancements * diff --git a/doc/reference_measure.xml b/doc/reference_measure.xml index dbeb9566a..dcde1a9e0 100644 --- a/doc/reference_measure.xml +++ b/doc/reference_measure.xml @@ -4344,6 +4344,7 @@ SELECT ST_AsEWKT(ST_PointOnSurface(ST_GeomFromEWKT('LINESTRING(0 5 1, 0 0 1, 0 1 The distance is given in meters. Availability: 2.0.0 + Enhanced: 2.4.0 Allow negative distance and non-normalized azimuth. diff --git a/liblwgeom/lwgeodetic.c b/liblwgeom/lwgeodetic.c index b48a90868..e96b95840 100644 --- a/liblwgeom/lwgeodetic.c +++ b/liblwgeom/lwgeodetic.c @@ -2009,18 +2009,20 @@ LWPOINT* lwgeom_project_spheroid(const LWPOINT *r, const SPHEROID *spheroid, dou double x, y; POINTARRAY *pa; LWPOINT *lwp; - - /* Check the azimuth validity, convert to radians */ - if ( azimuth < -2.0 * M_PI || azimuth > 2.0 * M_PI ) - { - lwerror("Azimuth must be between -2PI and 2PI"); - return NULL; + + /* Normalize distance to be positive*/ + if ( distance < 0.0 ) { + distance = -distance; + azimuth += M_PI; } + + /* Normalize azimuth */ + azimuth -= 2.0 * M_PI * floor(azimuth / (2.0 * M_PI)); /* Check the distance validity */ - if ( distance < 0.0 || distance > (M_PI * spheroid->radius) ) + if ( distance > (M_PI * spheroid->radius) ) { - lwerror("Distance must be between 0 and %g", M_PI * spheroid->radius); + lwerror("Distance must not be greater than %g", M_PI * spheroid->radius); return NULL; } diff --git a/regress/tickets.sql b/regress/tickets.sql index 61582dcfd..fab5d78d8 100644 --- a/regress/tickets.sql +++ b/regress/tickets.sql @@ -1015,5 +1015,8 @@ SELECT '#3627b', ST_Equals(geom, ST_LineFromEncodedPolyline(ST_AsEncodedPolyline -- #3704 SELECT '#3704', ST_AsX3D('LINESTRING EMPTY') = ''; +-- #3709 +select '#3709', ST_SnapToGrid(ST_Project('SRID=4326;POINT(1 1)'::geography, 100000, 20)::geometry, 0.0001) = ST_SnapToGrid(ST_Project('SRID=4326;POINT(1 1)'::geography, -100000, 20+pi())::geometry, 0.0001); + -- Clean up DELETE FROM spatial_ref_sys; diff --git a/regress/tickets_expected b/regress/tickets_expected index cbe200c62..452503060 100644 --- a/regress/tickets_expected +++ b/regress/tickets_expected @@ -302,3 +302,4 @@ ERROR: invalid KML representation #3627a|o}~~|AdshNoSsBgd@eGoBlm@wKhj@~@? #3627b|t #3704|t +#3709|t