ST_Contains doesn't work?

View: New views
6 Messages — Rating Filter:   Alert me  

ST_Contains doesn't work?

by kxk-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

SELECT
 ST_Contains(
 GeomFromText('POLYGON((0 0,0 10,10 10,10 0,0 0))', -1),
 GeomFromText('POLYGON((5 5,5 6,6 6,6 5,5 5))', -1) );

returns TRUE


But,

SELECT
 ST_Contains(
 GeomFromText('POLYGON((0 0,0 11,11 10,10 0,0 0))', -1),
 GeomFromText('POLYGON((5 5,5 6,6 6,6 5,5 5))', -1) );

returns FALSE

I thought the above would also return TRUE.


Is this behavior of ST_Contains correct?

[VERSION INFORMATION]
OS: fc6
PostgreSQL: 8.2.4
PostGIS: 1.2
GEOS: 3.0.0
_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: ST_Contains doesn't work?

by Paul Ramsey :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I just confirmed this behavior. true/true on geos 2.2 true/false on  
geos 3.0.
Please file this at http://trac.osgeo.org/geos, it's real, and it's  
not right.

P

On Jan 17, 2008, at 7:35 PM, KXK wrote:

> SELECT
> ST_Contains(
> GeomFromText('POLYGON((0 0,0 10,10 10,10 0,0 0))', -1),
> GeomFromText('POLYGON((5 5,5 6,6 6,6 5,5 5))', -1) );
>
> returns TRUE
>
>
> But,
>
> SELECT
> ST_Contains(
> GeomFromText('POLYGON((0 0,0 11,11 10,10 0,0 0))', -1),
> GeomFromText('POLYGON((5 5,5 6,6 6,6 5,5 5))', -1) );
>
> returns FALSE
>
> I thought the above would also return TRUE.
>
>
> Is this behavior of ST_Contains correct?
>
> [VERSION INFORMATION]
> OS: fc6
> PostgreSQL: 8.2.4
> PostGIS: 1.2
> GEOS: 3.0.0
> _______________________________________________
> postgis-users mailing list
> postgis-users@...
> http://postgis.refractions.net/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: [geos-devel] Re: ST_Contains doesn't work?

by Paul Ramsey :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think this must be arising in the "I'm a box so I can short-circuit  
full computation" code. The error displays with different combinations  
of square and non-square arguments.

On Jan 17, 2008, at 7:55 PM, Paul Ramsey wrote:

> I just confirmed this behavior. true/true on geos 2.2 true/false on  
> geos 3.0.
> Please file this at http://trac.osgeo.org/geos, it's real, and it's  
> not right.
>
> P
>
> On Jan 17, 2008, at 7:35 PM, KXK wrote:
>
>> SELECT
>> ST_Contains(
>> GeomFromText('POLYGON((0 0,0 10,10 10,10 0,0 0))', -1),
>> GeomFromText('POLYGON((5 5,5 6,6 6,6 5,5 5))', -1) );
>>
>> returns TRUE
>>
>>
>> But,
>>
>> SELECT
>> ST_Contains(
>> GeomFromText('POLYGON((0 0,0 11,11 10,10 0,0 0))', -1),
>> GeomFromText('POLYGON((5 5,5 6,6 6,6 5,5 5))', -1) );
>>
>> returns FALSE
>>
>> I thought the above would also return TRUE.
>>
>>
>> Is this behavior of ST_Contains correct?
>>
>> [VERSION INFORMATION]
>> OS: fc6
>> PostgreSQL: 8.2.4
>> PostGIS: 1.2
>> GEOS: 3.0.0
>> _______________________________________________
>> postgis-users mailing list
>> postgis-users@...
>> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
> _______________________________________________
> geos-devel mailing list
> geos-devel@...
> http://lists.osgeo.org/mailman/listinfo/geos-devel

_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: [geos-devel] Re: ST_Contains doesn't work?

by kxk-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Paul


Thanx for a quick reply.

At http://trac.osgeo.org/geos, I issued a ticket whose number is #171.


KXK

2008/1/18, Paul Ramsey <pramsey@...>:

> I think this must be arising in the "I'm a box so I can short-circuit
> full computation" code. The error displays with different combinations
> of square and non-square arguments.
>
> On Jan 17, 2008, at 7:55 PM, Paul Ramsey wrote:
>
> > I just confirmed this behavior. true/true on geos 2.2 true/false on
> > geos 3.0.
> > Please file this at http://trac.osgeo.org/geos, it's real, and it's
> > not right.
> >
> > P
> >
> > On Jan 17, 2008, at 7:35 PM, KXK wrote:
> >
> >> SELECT
> >> ST_Contains(
> >> GeomFromText('POLYGON((0 0,0 10,10 10,10 0,0 0))', -1),
> >> GeomFromText('POLYGON((5 5,5 6,6 6,6 5,5 5))', -1) );
> >>
> >> returns TRUE
> >>
> >>
> >> But,
> >>
> >> SELECT
> >> ST_Contains(
> >> GeomFromText('POLYGON((0 0,0 11,11 10,10 0,0 0))', -1),
> >> GeomFromText('POLYGON((5 5,5 6,6 6,6 5,5 5))', -1) );
> >>
> >> returns FALSE
> >>
> >> I thought the above would also return TRUE.
> >>
> >>
> >> Is this behavior of ST_Contains correct?
> >>
> >> [VERSION INFORMATION]
> >> OS: fc6
> >> PostgreSQL: 8.2.4
> >> PostGIS: 1.2
> >> GEOS: 3.0.0
> >> _______________________________________________
> >> postgis-users mailing list
> >> postgis-users@...
> >> http://postgis.refractions.net/mailman/listinfo/postgis-users
> >
> > _______________________________________________
> > geos-devel mailing list
> > geos-devel@...
> > http://lists.osgeo.org/mailman/listinfo/geos-devel
>
> _______________________________________________
> geos-devel mailing list
> geos-devel@...
> http://lists.osgeo.org/mailman/listinfo/geos-devel
>
_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: [geos-devel] Re: ST_Contains doesn't work?

by kxk-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Paul & Ben J.


I found a quick solution for this "Contains" problem.

These 3 lines below should be deleted to fix this bug.

source/geom/Geomtry.cpp

bool
Geometry::contains(const Geometry *g) const
{
.
.
.
        if (isRectangle()) {
                return predicate::RectangleContains::contains((Polygon&)*this, *g);
        }
// Delete from here
        if (g->isRectangle()) {
                return predicate::RectangleContains::contains((const Polygon&)*g, *this);
        }
// Delete until here
.
.
}



The reason why I thought of deleting these 3 lines was:

The 1st argument should be passed as the 2nd argument,
and the 2nd argument should be passed as the 1st argument,
because it should varify if *this contains *g. Not the other way around.

BUT, predicate::RectangleContains::contains method accepts the 1st
argument only being a rectangle.
So, passing *this as the 1st argument is not acceptable since *this is
not guaranteed as a rectangle; it is just a geometry.


I will put this info to the below site, too.
http://trac.osgeo.org/geos/

What do you think about the solution? I need your feedbacks.


Good Day,

KXK


2008/1/18, KXK <vivahome2@...>:

> Paul
>
>
> Thanx for a quick reply.
>
> At http://trac.osgeo.org/geos, I issued a ticket whose number is #171.
>
>
> KXK
>
> 2008/1/18, Paul Ramsey <pramsey@...>:
> > I think this must be arising in the "I'm a box so I can short-circuit
> > full computation" code. The error displays with different combinations
> > of square and non-square arguments.
> >
> > On Jan 17, 2008, at 7:55 PM, Paul Ramsey wrote:
> >
> > > I just confirmed this behavior. true/true on geos 2.2 true/false on
> > > geos 3.0.
> > > Please file this at http://trac.osgeo.org/geos, it's real, and it's
> > > not right.
> > >
> > > P
> > >
> > > On Jan 17, 2008, at 7:35 PM, KXK wrote:
> > >
> > >> SELECT
> > >> ST_Contains(
> > >> GeomFromText('POLYGON((0 0,0 10,10 10,10 0,0 0))', -1),
> > >> GeomFromText('POLYGON((5 5,5 6,6 6,6 5,5 5))', -1) );
> > >>
> > >> returns TRUE
> > >>
> > >>
> > >> But,
> > >>
> > >> SELECT
> > >> ST_Contains(
> > >> GeomFromText('POLYGON((0 0,0 11,11 10,10 0,0 0))', -1),
> > >> GeomFromText('POLYGON((5 5,5 6,6 6,6 5,5 5))', -1) );
> > >>
> > >> returns FALSE
> > >>
> > >> I thought the above would also return TRUE.
> > >>
> > >>
> > >> Is this behavior of ST_Contains correct?
> > >>
> > >> [VERSION INFORMATION]
> > >> OS: fc6
> > >> PostgreSQL: 8.2.4
> > >> PostGIS: 1.2
> > >> GEOS: 3.0.0
> > >> _______________________________________________
> > >> postgis-users mailing list
> > >> postgis-users@...
> > >> http://postgis.refractions.net/mailman/listinfo/postgis-users
> > >
> > > _______________________________________________
> > > geos-devel mailing list
> > > geos-devel@...
> > > http://lists.osgeo.org/mailman/listinfo/geos-devel
> >
> > _______________________________________________
> > geos-devel mailing list
> > geos-devel@...
> > http://lists.osgeo.org/mailman/listinfo/geos-devel
> >
>
_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: [geos-devel] Re: ST_Contains doesn't work?

by tjordan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Just to clarify, the problem occurs when the first geometry in an ST_Contains operation is not a rectangle and the second parameter is a rectangle.

SELECT
 ST_Contains(
 GeomFromText('POLYGON((0 0,0 10,10 10,10 0,0 0))', -1),
 GeomFromText('POLYGON((5 5,5 6,6 6,6 5,5 5))', -1) );
  # -- both rectangles: returns true

SELECT
 ST_Contains(
 GeomFromText('POLYGON((0 0,0.0000001 10,10 10,10 0,0 0))', -1),
 GeomFromText('POLYGON((5 5,5 6,6 6,6 5,5 5))', -1) );
  # -- non-rectangle and rectangle: returns false

SELECT
 ST_Contains(
 GeomFromText('POLYGON((0 0,0 10,10 10,10 0,0 0))', -1),
 GeomFromText('POLYGON((5 5,5.0000001 6,6 6,6 5,5 5))', -1) );
  # -- rectangle and non-rectangle: returns true

SELECT
 ST_Contains(
 GeomFromText('POLYGON((0 0,0.0000001 10,10 10,10 0,0 0))', -1),
 GeomFromText('POLYGON((5 5,5.0000001 6,6 6,6 5,5 5))', -1) );
  # -- both non-rectangles: returns true



Paul Ramsey wrote:
I think this must be arising in the "I'm a box so I can short-circuit  
full computation" code. The error displays with different combinations  
of square and non-square arguments.

On Jan 17, 2008, at 7:55 PM, Paul Ramsey wrote:

> I just confirmed this behavior. true/true on geos 2.2 true/false on  
> geos 3.0.
> Please file this at http://trac.osgeo.org/geos, it's real, and it's  
> not right.
>
> P
>
> On Jan 17, 2008, at 7:35 PM, KXK wrote:
>
>> SELECT
>> ST_Contains(
>> GeomFromText('POLYGON((0 0,0 10,10 10,10 0,0 0))', -1),
>> GeomFromText('POLYGON((5 5,5 6,6 6,6 5,5 5))', -1) );
>>
>> returns TRUE
>>
>>
>> But,
>>
>> SELECT
>> ST_Contains(
>> GeomFromText('POLYGON((0 0,0 11,11 10,10 0,0 0))', -1),
>> GeomFromText('POLYGON((5 5,5 6,6 6,6 5,5 5))', -1) );
>>
>> returns FALSE
>>
>> I thought the above would also return TRUE.
>>
>>
>> Is this behavior of ST_Contains correct?
>>
>> [VERSION INFORMATION]
>> OS: fc6
>> PostgreSQL: 8.2.4
>> PostGIS: 1.2
>> GEOS: 3.0.0
>> _______________________________________________
>> postgis-users mailing list
>> postgis-users@postgis.refractions.net
>> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
> _______________________________________________
> geos-devel mailing list
> geos-devel@lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/geos-devel

_______________________________________________
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users