[postgis-users] two different geometries with the same Astext
strk at refractions.net
strk at refractions.net
Sat Jul 23 14:07:21 PDT 2005
On Mon, Jul 18, 2005 at 12:03:37PM -0400, Stephen Woodbridge wrote:
> Miguel de la Fuente wrote:
> >Hello, I'looking for help with something that already happens to me in
> >the past, comparing two geometries with equals() return false but when
> >I get the AsText() of both it was the same.
> >Right now I'm having a similar problem with within(), when I ask if a
> >geometry1 is within a geometry2 in another table, both
> >multilinestrings, the result is false.
> >I ask the AsText of both and see that the geometry1 is one segment of
> >geometry2, so it is within it.
> >And, if I ask
> >wthin(GeometryFormText(AsText(geometry1)),GeometryFormText(AsText(geometry2)))
> >return true
> >
> >Then, why wthin(geometry1,geometry2) return false ?
> >
> >Can anyone help me??
>
> This sounds like floating point comparisons failing because of numerical
> rounding issues.
>
> strk, Is there an epsilon value that is used to comparing floating point
> values? Is this accessible or settable at runtime?
No general approach to this.
In the specific case the failing short-circuit uses bare < and >
/*
* short-circuit 1: if geom1 bounding box is not completely inside
* geom2 bounding box we can prematurely return FALSE.
* Do the test IFF BOUNDING BOX AVAILABLE.
*/
if ( getbox2d_p(SERIALIZED_FORM(geom1), &box1) &&
getbox2d_p(SERIALIZED_FORM(geom2), &box2) )
{
if ( box1.xmin < box2.xmin ) PG_RETURN_BOOL(FALSE);
if ( box1.xmax > box2.xmax ) PG_RETURN_BOOL(FALSE);
if ( box1.ymin < box2.ymin ) PG_RETURN_BOOL(FALSE);
if ( box1.ymax > box2.ymax ) PG_RETURN_BOOL(FALSE);
}
--strk;
More information about the postgis-users
mailing list