[postgis-users] the_geom = the_geom strange result [solved]

Picavet Vincent Vincent.Picavet at mediapost.fr
Wed Oct 15 10:18:30 PDT 2008


Hi,

> ST_Equals(geometry, geometry)
> 
> Returns 1 (TRUE) if the given Geometries are "spatially 
> equal". Use this for a 'better' answer than '='. 
> equals('LINESTRING(0 0, 10 10)','LINESTRING(0 0, 5 5, 10 
> 10)') is true.

Ok for st_equals, which result is alright.

> Actually  the '=' operator is not overloaded for spatial query.
> 
> Have a look in lwpostgis.sql
> 
> root at olivia:~# grep OPERATOR /usr/local/pgsql/share/lwpostgis.sql
> CREATE OPERATOR < (
> CREATE OPERATOR <= (
> CREATE OPERATOR = (

In fact it is.

And hopefully, since it's heavily used for indexes, which only work
on... bounding boxes !

Looking at the source, it is clear that the = operator on geometries in
postgis means 
<bounding box of left geometry is strictly equal to bounding box of
right geometry>.

This given a precision on float comparison of 1.0E-06.

We had a few <group by the_geom> in our code, which is clearly a problem
for grouping strictly identical geometries. A solution would be to
<group by st_binary(the_geom)>. Is there a more elegant or faster way to
do it ?

Furthermore, could it be possible to mention this in postgis reference
chapter of the documentation ? I only found it in chapter 4.4.1 (using
SQL) grepping through the doc afterwards.

Thanks,
Vincent


> 
> Have a look in lwpostgis.sql
> 
> root at olivia:~# grep OPERATOR /usr/local/pgsql/share/lwpostgis.sql
> CREATE OPERATOR < (
> CREATE OPERATOR <= (
> CREATE OPERATOR = (
> CREATE OPERATOR >= (
> CREATE OPERATOR > (
> CREATE OPERATOR CLASS btree_geometry_ops
>          OPERATOR        1       < ,
>          OPERATOR        2       <= ,
>          OPERATOR        3       = ,
>          OPERATOR        4       >= ,
>          OPERATOR        5       > ,
> CREATE OPERATOR << (
> CREATE OPERATOR &< (
> CREATE OPERATOR <<| (
> CREATE OPERATOR &<| (
> CREATE OPERATOR && (
> CREATE OPERATOR &> (
> CREATE OPERATOR >> (
> CREATE OPERATOR |&> (
> CREATE OPERATOR |>> (
> CREATE OPERATOR ~= (
> CREATE OPERATOR @ (
> CREATE OPERATOR ~ (
> 
> --david;
> 
> 
> 
> 
> Quoting Picavet Vincent <Vincent.Picavet at mediapost.fr>:
> 
> > Hi,
> > Considering two similar geometries, but different, an equality test 
> > with the '=' operator returns true, whereas st_equals returns false.
> > In this case, st_equals behaviour seems right, but I would 
> expect the 
> > equality test with = to return false as well, since the 
> geometries are 
> > actually different.
> > Does someone have an explanation to this result ? Some kind 
> of float 
> > precision related issue ?
> >
> > select st_geometryfromtext(
> > 'LINESTRING(94525.0864578169 2403749.07413185,94521.0361656005
> > 2403752.12944388,94519.5539334096
> > 2403754.3019993,94517.5683187493 2403757.1772215,94512.295369653 
> > 2403767.3398906)'
> > )
> > = st_geometryfromtext(
> > 'LINESTRING(94512.295369653 2403767.3398906,94520.7920704004
> > 2403760.91556806,94524.3349180666
> > 2403757.32391662,94525.0864578169 2403749.07413185)'
> > );
> >
> > select st_equals(st_geometryfromtext('LINESTRING(94525.0864578169
> > 2403749.07413185,94521.0361656005 2403752.12944388,94519.5539334096
> > 2403754.3019993,94517.5683187493 2403757.1772215,94512.295369653
> > 2403767.3398906)')
> > ,st_geometryfromtext('LINESTRING(94512.295369653
> > 2403767.3398906,94520.7920704004 2403760.91556806,94524.3349180666
> > 2403757.32391662,94525.0864578169 2403749.07413185)'));
> >
> > tested with :
> > "POSTGIS="1.3.3" GEOS="3.0.0-CAPI-1.4.1" PROJ="Rel. 4.6.0, 
> 21 Dec 2007"
> > USE_STATS (procs from 1.3.2 need upgrade)"
> > "POSTGIS="1.1.6" GEOS="2.2.3-CAPI-1.1.1" PROJ="Rel. 4.5.0, 
> 22 Oct 2006"
> > USE_STATS (procs from 1.3.2 need upgrade)"
> >
> > Thanks for any explanation,
> > Vincent
> > _______________________________________________
> > postgis-users mailing list
> > postgis-users at postgis.refractions.net
> > http://postgis.refractions.net/mailman/listinfo/postgis-users
> >
> >
> 
> 
> 
> ===================
> Jean David TECHER
> www.davidgis.fr
> 06 60 46 85 05
> 04 99 77 16 87
> ===================
> 
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
> 



More information about the postgis-users mailing list