Opened 3 years ago

Closed 2 years ago

#5072 closed defect (wontfix)

ST_GeomFromTWKB rounding issue with negative xyprecision

Reported by: Aurélien Mino Owned by: pramsey
Priority: medium Milestone: PostGIS 3.3.0
Component: postgis Version: 3.1.x
Keywords: Cc:

Description

Consider the following query:

select 
	ST_AsText(ST_GeomFromTWKB(ST_AsTWKB(inputwkt::geometry, xyprecision, 5, 5, false, false))) as reverted_wkt_from_twkb,
	xyprecision,
	encode(ST_AsTWKB(inputwkt::geometry, xyprecision, 5, 5, false, false), 'hex')
from (select 'POINT (12345678.12345678 -12345678.12345678)'::text as inputwkt) xx
cross join generate_series(-5, -5) as xyprecision

With postgis 3.1.4 or 3.2.0 it returns:

POINT(12299999.999999998 -12299999.999999998)	-5	9100f601f501}}}

With postgis 3.0.4 it returns:

POINT(12300000 -12300000)	-5	9100f601f501

Change History (2)

comment:1 by nicklas, 3 years ago

This looks like a floating point precision issue. It is interesting that it has changed over versions. I see the same when comparing 3.0 and 3.2 that they differs.

I think this is something that has changed in a higher level in the code base. I cannot see any changes in the twkb code that should cause this. The hex-string from creating twkb is identical so it is on the decoding side. At least earlier we have ignored thos floating point differenties since it can depend on a lot of things.

comment:2 by pramsey, 2 years ago

Resolution: wontfix
Status: newclosed

We could round off in the function, but that would be silly. They are effectively the same answer, if you need exact precision, round them off.

Note: See TracTickets for help on using tickets.