Opened 16 years ago

Closed 16 years ago

Last modified 15 years ago

#171 closed defect (fixed)

Non-Square Rectangle Should Contain Rectangle

Reported by: vivahome2 Owned by:
Priority: critical Milestone: 3.1.0
Component: Core Version: 3.0.0
Severity: Unassigned Keywords:
Cc:

Description

With PostGIS, when I tried something like

ST_Contains(Non-Rectangle-Polygon, Rectangle-Polygon)

It returned false, where Non-Rectangle-Polygon indeed "contained" Rectangle-Polygon

The actual SQL is

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) );

The source code of PostGIS where ST_Contains is defined is (I think)

char GEOSrelateContains(Geometry *g1, Geometry*g2)
{
	try {
		bool result;
		result = g1->contains(g2);
		return result;
	}
	catch (GEOSException *ge)
	{
		NOTICE_MESSAGE(ge->toString().c_str());
		delete ge;
		return 2;
	}

	catch (...)
	{
		return 2;
	}
}

Change History (3)

comment:1 by vivahome2, 16 years ago

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.

comment:2 by benjubb, 16 years ago

Resolution: fixed
Status: newclosed

checked in patch to trunk

comment:3 by pramsey, 15 years ago

Milestone: 3.1.0
Note: See TracTickets for help on using tickets.