View Ticket
Not logged in
Ticket Hash: 1e70a58b7643ef222091bb364ecd0ccbd98032a2
Title: Precision for EXTENT function
Status: Closed Type: Code_Defect
Severity: Important Priority: Immediate
Subsystem: Resolution: Not_A_Bug
Last Modified: 2015-12-21 07:41:16
Version Found In: 4.3.0
User Comments:
anonymous added on 2015-12-17 11:43:16:

Hello Guys,

I'm using a Spatialite database for a street map (roads are LINE_STRINGS). In my Python(3.4) code I'm executing following sqlite query to get the bounds for all roads:

SELECT ASTEXT(EXTENT(geom)) FROM roads

When I'm testing my code by checking if all roads are in the calculated bounds I'm getting an error because the x value of a point is outside of the bounds:

Error: assert (52.538527999999999 <= 52.538519999999998)

By rounding to the fourth digit or adding an epsilon value as tollerance threshold the error disappears but I don't like this solution. Is it possible that Spatialite rounds values while calculating the bounds so the returned value may not be accurately enough?

Greetings, Thomas Kellermeier


sandro added on 2015-12-21 07:41:16:
The reposted problem is not related to ST_Extent; it's an artifact introduced by an inappropriate usage of ST_AsText().

You should always reasonably expect that the textual representation of any floating point number would be possibly affected by rounding/truncation effects; ST_AsText() is just intended to _print_ values for human readers, but when you do really intend to use floating point values as comparison operands directly handling binary values (as WKB expressions, or by calling the ST_X and ST_Y functions) is the unique approach you can safely adopt in order to get an uncompromised precision.