#1502 closed defect (fixed)
Unrobustness in distance calculations
Reported by: | nicklas | Owned by: | nicklas |
---|---|---|---|
Priority: | medium | Milestone: | PostGIS 2.0.0 |
Component: | postgis | Version: | 1.5.X |
Keywords: | Cc: |
Description
This one is quite ugly.
SELECT st_dwithin(a,b,0), st_intersects(a,b),st_distance(a,b) from (select 'LINESTRING(-97364 -97364, 9736.4 9736.4)'::geometry a, 'POINT(0 0)'::geometry b ) f;
returns :
f;t;3.086927381169e-11
This is also point-segment problem like #1459
The problem is that the distance is calculated by projecting the point to the segment and then calculating the distance from the projected point to the original point.
The projection of the point to the segment is done by calculating where along the segment from 0 to 1 that the point should be projected. That value, r, doesn't have enough precision when the segment is long and the distance to between the original point is small.
This was not a problem pre 1.5 because then the projected point was never calculated.
Change History (4)
comment:1 by , 13 years ago
comment:2 by , 13 years ago
But than we have to use the point in this case origo to represent the projected point.
comment:4 by , 13 years ago
BTW, I don't think that this issue was present on 32 but linux because of that difference in precision between variables and calculations on that platform.
One solution might be to take the extra waltz if the distance is smaller than, say 1e-5 and do the same, more direct calculation that was done in 1.4.
I will look more into it tomorrow