[postgis-users] ST_Project with geometries in postgis 3.4

Sarah Hoffmann lonvia at denofr.de
Mon Aug 21 08:04:48 PDT 2023


Hi,

when updating to the recently released 3.4, I run into some test
failures with Nominatim and discovered that the release has a breaking
change which does not seem to be documented in the release notes.

I'm using the ST_Project function to create a bounding box around a
WGS84 point geometry where the box has to have a given size in
meters[1].

The code uses a geometry as input to ST_Project which admittedly was
not allowed per documentation for Postgis < 3.4 but worked just fine:

test=# SELECT ST_AsText(ST_Project('SRID=4326;POINT(0 0)'::geometry, 100000, radians(45.0)));
                 st_astext
--------------------------------------------
 POINT(0.635231029125537 0.639472334729198)
(1 row)

When ST_Project gained native support for geometries in 3.4, the
distance parameter suddenly changed its meaning and is interpreted as
projected units instead of meters, giving rather different results:

test=# SELECT ST_AsText(ST_Project('SRID=4326;POINT(0 0)'::geometry, 100000, radians(45.0)));
                 st_astext
--------------------------------------------
 POINT(70710.67811865476 70710.67811865475)
(1 row)

The code is easily fixed by adding an explicit cast to geography but I
thought I make you aware of the behavioural change in case it was
unintentional.

Also note that the documentation for ST_Project[2] still states that the
distance parameter is in meters. This should be adopted as well for the
new behaviour.

Kind regards

Sarah

[1] https://github.com/osm-search/Nominatim/blob/23eed4ff2fe4a987ff82d816fdedb9f2bbaa5d88/lib-sql/functions/utils.sql#L275
[2] https://postgis.net/docs/en/ST_Project.html


More information about the postgis-users mailing list