Opened 12 months ago
Closed 8 months ago
#5520 closed defect (fixed)
ST_ReducePrecision not rounding coordinates as expected
Reported by: | andre286 | Owned by: | pramsey |
---|---|---|---|
Priority: | high | Milestone: | PostGIS GEOS |
Component: | postgis | Version: | 3.4.x |
Keywords: | Cc: | andre286 |
Description
SELECT st_astext(ST_ReducePrecision( 'LINESTRING(657012.415312 6475619.607621,657028.616 6475595.798,657028.622 6475595.817,657029.229 6475595.029, 657031.971 6475596.084,657035.913 6475590.114,657033.656 6475588.204,657052.066 6475561.165, 657056.317 6475550.033,657066.679 6475523.534,657069.809 6475524.233,657072.182 6475517.718,657069.671 6475516.487, 657075.57 6475500,657082.237 6475481.366,657092.356 6475454.489,657095.282 6475455.589,657097.89 6475448.718,657094.899 6475447.428,657100.462 6475432.085, 657102.713494 6475426.040564,657105.93 6475417.32,657111.59 6475412.5,657116.22 6475408.47,657121.73 6475413.23,657131.18 6475404.07)' ,0.001))
result: LINESTRING(657012.415 6475619.608,657028.616 6475595.798,657028.622 6475595.817,657029.229 6475595.029,657031.971 6475596.084,657035.9130000001 6475590.114,657033.656 6475588.204,657052.066 6475561.165,657056.317 6475550.033,657066.679 6475523.534,657069.809 6475524.233,657072.182 6475517.718,657069.671 6475516.487,657075.5700000001 6475500,657082.237 6475481.366,657092.356 6475454.489,657095.282 6475455.589,657097.89 6475448.718,657094.899 6475447.428,657100.462 6475432.085,657102.713 6475426.041,657105.93 6475417.32,657111.59 6475412.5,657116.22 6475408.47,657121.73 6475413.23,657131.18 6475404.07)
Version: POSTGIS="3.3.3 2355e8e" [EXTENSION] PGSQL="130" GEOS="3.11.1-CAPI-1.17.1" PROJ="9.1.1" LIBXML="2.9.14" LIBJSON="0.16" LIBPROTOBUF="1.4.1" WAGYU="0.5.0 (Internal)"
Change History (7)
comment:1 by , 11 months ago
comment:2 by , 11 months ago
Here is a simpler reproducer:
SELECT ST_AsText(ST_ReducePrecision( 'LINESTRING (657035.913 6475590.114,657075.57 6475500)' ,0.001));
st_astext --------------------------------------------------------------------- LINESTRING(657035.9130000001 6475590.114,657075.5700000001 6475500)
comment:3 by , 11 months ago
The failure to round appropriately is caused by the use of a decimal value as the gridSize (0.001
). This can be reproduced in GEOS using:
bin/geosop -a "LINESTRING (657035.913 6475590.114,657075.57 6475500)" reducePrecision N-0.001 LINESTRING (657035.9130000001 6475590.114, 657075.5700000001 6475500)
GEOS also supports using a scale factor rather than a gridSize, which allows using an integer argument. This produces more accurate rounding:
bin/geosop -a "LINESTRING (657035.913 6475590.114,657075.57 6475500)" reducePrecision 1000 LINESTRING (657035.913 6475590.114, 657075.57 6475500)
Unfortunately this isn't exposed in PostGIS. Perhaps it could be provided as an alternative (say by using the "negative number" trick?)
comment:4 by , 11 months ago
See also #5425 for a similar issue with ST_SnapToGrid
.
Because ST_SnapToGrid
is a PostGIS native function, this will require changes to the PostGIS code. A similar approach to https://github.com/libgeos/geos/pull/956 could be used.
comment:5 by , 11 months ago
See https://github.com/libgeos/geos/pull/956 for a potential fix that does not require any change to PostGIS.
comment:6 by , 11 months ago
Milestone: | PostGIS 3.4.1 → PostGIS GEOS |
---|
comment:7 by , 8 months ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
What is unexpected about that result ? What would you expect ? Use maybe a single point to simplify reading the report ?