[geos-commits] r2063 - in trunk/source/geom: . prep
svn_geos at osgeo.org
svn_geos at osgeo.org
Fri Dec 21 15:40:27 EST 2007
Author: benjubb
Date: 2007-12-21 15:40:27 -0500 (Fri, 21 Dec 2007)
New Revision: 2063
Added:
trunk/source/geom/prep/
trunk/source/geom/prep/AbstractPreparedPolygonContains.cpp
trunk/source/geom/prep/BasicPreparedGeometry.cpp
trunk/source/geom/prep/PreparedGeometry.cpp
trunk/source/geom/prep/PreparedGeometryFactory.cpp
trunk/source/geom/prep/PreparedLineString.cpp
trunk/source/geom/prep/PreparedLineStringIntersects.cpp
trunk/source/geom/prep/PreparedPoint.cpp
trunk/source/geom/prep/PreparedPolygon.cpp
trunk/source/geom/prep/PreparedPolygonContains.cpp
trunk/source/geom/prep/PreparedPolygonContainsProperly.cpp
trunk/source/geom/prep/PreparedPolygonCovers.cpp
trunk/source/geom/prep/PreparedPolygonIntersects.cpp
trunk/source/geom/prep/PreparedPolygonLineIntersection.cpp
trunk/source/geom/prep/PreparedPolygonPredicate.cpp
Log:
Added from JTS 1.9 to support prepared geometry
Added: trunk/source/geom/prep/AbstractPreparedPolygonContains.cpp
===================================================================
--- trunk/source/geom/prep/AbstractPreparedPolygonContains.cpp (rev 0)
+++ trunk/source/geom/prep/AbstractPreparedPolygonContains.cpp 2007-12-21 20:40:27 UTC (rev 2063)
@@ -0,0 +1,192 @@
+/**********************************************************************
+ * $Id:
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2001-2002 Vivid Solutions Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************/
+
+
+#include <geos/geom/prep/AbstractPreparedPolygonContains.h>
+#include <geos/geom/prep/PreparedPolygon.h>
+#include <geos/geom/Geometry.h>
+#include <geos/geom/Polygon.h>
+#include <geos/geom/MultiPolygon.h>
+#include <geos/noding/SegmentString.h>
+#include <geos/noding/SegmentStringUtil.h>
+#include <geos/noding/SegmentIntersectionDetector.h>
+#include <geos/noding/FastSegmentSetIntersectionFinder.h>
+#include <geos/algorithm/LineIntersector.h>
+
+namespace geos {
+namespace geom { // geos::geom
+namespace prep { // geos::geom::prep
+//
+// private:
+//
+bool
+AbstractPreparedPolygonContains::isProperIntersectionImpliesNotContainedSituation( const geom::Geometry * testGeom)
+{
+ // If the test geometry is polygonal we have the A/A situation.
+ // In this case, a proper intersection indicates that
+ // the Epsilon-Neighbourhood Exterior Intersection condition exists.
+ // This condition means that in some small
+ // area around the intersection point, there must exist a situation
+ // where the interior of the test intersects the exterior of the target.
+ // This implies the test is NOT contained in the target.
+ if ( testGeom->getGeometryTypeId() == GeometryTypeId::GEOS_MULTIPOLYGON
+ || testGeom->getGeometryTypeId() == GeometryTypeId::GEOS_POLYGON )
+ return true;
+
+ // A single shell with no holes allows concluding that
+ // a proper intersection implies not contained
+ // (due to the Epsilon-Neighbourhood Exterior Intersection condition)
+ if ( isSingleShell( prepPoly->getGeometry()) )
+ return true;
+
+ return false;
+}
+
+
+bool
+AbstractPreparedPolygonContains::isSingleShell( const geom::Geometry & geom)
+{
+ // handles single-element MultiPolygons, as well as Polygons
+ if ( geom.getNumGeometries() != 1)
+ return false;
+
+ const geom::Polygon * poly = (Polygon *)geom.getGeometryN( 0);
+
+ int numHoles = poly->getNumInteriorRing();
+ return (numHoles == 0);
+}
+
+
+void
+AbstractPreparedPolygonContains::findAndClassifyIntersections( const geom::Geometry * geom)
+{
+ noding::SegmentString::ConstVect lineSegStr;
+ noding::SegmentStringUtil::extractSegmentStrings( geom, lineSegStr);
+
+ algorithm::LineIntersector * li;
+ li = new algorithm::LineIntersector();
+
+ noding::SegmentIntersectionDetector * intDetector;
+ intDetector = new noding::SegmentIntersectionDetector( li);
+
+ intDetector->setFindAllIntersectionTypes( true);
+
+ prepPoly->getIntersectionFinder()->intersects( &lineSegStr, intDetector);
+
+ hasSegmentIntersection = intDetector->hasIntersection();
+ hasProperIntersection = intDetector->hasProperIntersection();
+ hasNonProperIntersection = intDetector->hasNonProperIntersection();
+
+ delete intDetector;
+ delete li;
+ for ( size_t i = 0, ni = lineSegStr.size(); i < ni; i++ )
+ delete lineSegStr[ i ];
+}
+
+
+//
+// protected:
+//
+bool
+AbstractPreparedPolygonContains::eval( const geom::Geometry * geom)
+{
+ // Do point-in-poly tests first, since they are cheaper and may result
+ // in a quick negative result.
+ //
+ // If a point of any test components does not lie in target, result is false
+ bool isAllInTargetArea = isAllTestComponentsInTargetArea( geom);
+ if ( !isAllInTargetArea )
+ return false;
+
+ // If the test geometry consists of only Points,
+ // then it is now sufficient to test if any of those
+ // points lie in the interior of the target geometry.
+ // If so, the test is contained.
+ // If not, all points are on the boundary of the area,
+ // which implies not contained.
+ if ( requireSomePointInInterior && geom->getDimension() == 0 )
+ {
+ bool isAnyInTargetInterior = isAnyTestComponentInTargetInterior( geom);
+ return isAnyInTargetInterior;
+ }
+
+ // Check if there is any intersection between the line segments
+ // in target and test.
+ // In some important cases, finding a proper interesection implies that the
+ // test geometry is NOT contained.
+ // These cases are:
+ // - If the test geometry is polygonal
+ // - If the target geometry is a single polygon with no holes
+ // In both of these cases, a proper intersection implies that there
+ // is some portion of the interior of the test geometry lying outside
+ // the target, which means that the test is not contained.
+ bool properIntersectionImpliesNotContained = isProperIntersectionImpliesNotContainedSituation( geom);
+
+ // find all intersection types which exist
+ findAndClassifyIntersections( geom);
+
+ if ( properIntersectionImpliesNotContained && hasProperIntersection )
+ return false;
+
+ // If all intersections are proper
+ // (i.e. no non-proper intersections occur)
+ // we can conclude that the test geometry is not contained in the target area,
+ // by the Epsilon-Neighbourhood Exterior Intersection condition.
+ // In real-world data this is likely to be by far the most common situation,
+ // since natural data is unlikely to have many exact vertex segment intersections.
+ // Thus this check is very worthwhile, since it avoid having to perform
+ // a full topological check.
+ //
+ // (If non-proper (vertex) intersections ARE found, this may indicate
+ // a situation where two shells touch at a single vertex, which admits
+ // the case where a line could cross between the shells and still be wholely contained in them.
+ if ( hasSegmentIntersection && !hasNonProperIntersection )
+ return false;
+
+ // If there is a segment intersection and the situation is not one
+ // of the ones above, the only choice is to compute the full topological
+ // relationship. This is because contains/covers is very sensitive
+ // to the situation along the boundary of the target.
+ if ( hasSegmentIntersection )
+ return fullTopologicalPredicate( geom);
+
+ // This tests for the case where a ring of the target lies inside
+ // a test polygon - which implies the exterior of the Target
+ // intersects the interior of the Test, and hence the result is false
+ if ( geom->getGeometryTypeId() == GeometryTypeId::GEOS_MULTIPOLYGON
+ || geom->getGeometryTypeId() == GeometryTypeId::GEOS_POLYGON )
+ {
+ // TODO: generalize this to handle GeometryCollections
+ bool isTargetInTestArea = isAnyTargetComponentInTestArea( geom, prepPoly->getRepresentativePoints());
+
+ if ( isTargetInTestArea )
+ return false;
+ }
+
+ return true;
+}
+
+//
+// public:
+//
+
+} // geos::geom::prep
+} // geos::geom
+} // geos
+
+/**********************************************************************
+ * $Log$
+ *
+ **********************************************************************/
Property changes on: trunk/source/geom/prep/AbstractPreparedPolygonContains.cpp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/source/geom/prep/BasicPreparedGeometry.cpp
===================================================================
--- trunk/source/geom/prep/BasicPreparedGeometry.cpp (rev 0)
+++ trunk/source/geom/prep/BasicPreparedGeometry.cpp 2007-12-21 20:40:27 UTC (rev 2063)
@@ -0,0 +1,149 @@
+/**********************************************************************
+ * $Id:
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2001-2002 Vivid Solutions Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************/
+
+
+#include <geos/geom/prep/BasicPreparedGeometry.h>
+#include <geos/geom/Coordinate.h>
+#include <geos/algorithm/PointLocator.h>
+#include <geos/geom/util/ComponentCoordinateExtracter.h>
+
+namespace geos {
+namespace geom { // geos.geom
+namespace prep { // geos.geom.prep
+
+/* *
+ * protected: *
+ * */
+
+void
+BasicPreparedGeometry::setGeometry( const geom::Geometry * geom )
+{
+ baseGeom = geom;
+ geom::util::ComponentCoordinateExtracter::getCoordinates(*baseGeom, representativePts);
+}
+
+bool
+BasicPreparedGeometry::envelopesIntersect( const geom::Geometry* g) const
+{
+ return baseGeom->getEnvelopeInternal()->intersects(g->getEnvelopeInternal());
+}
+
+bool
+BasicPreparedGeometry::envelopeCovers( const geom::Geometry* g) const
+{
+ return baseGeom->getEnvelopeInternal()->covers(g->getEnvelopeInternal());
+}
+
+/*
+ * public:
+ */
+BasicPreparedGeometry::BasicPreparedGeometry( const Geometry * geom)
+{
+ setGeometry( geom);
+}
+
+BasicPreparedGeometry::~BasicPreparedGeometry( )
+{
+}
+
+
+bool
+BasicPreparedGeometry::isAnyTargetComponentInTest( const geom::Geometry * testGeom) const
+{
+ algorithm::PointLocator *locator = new algorithm::PointLocator();
+
+ for (size_t i=0, n=representativePts.size(); i<n; i++)
+ {
+ geom::Coordinate c = *(representativePts[i]);
+ if ( locator->intersects( c, testGeom) )
+ return true;
+ }
+ return false;
+}
+
+bool
+BasicPreparedGeometry::contains(const geom::Geometry * g) const
+{
+ return baseGeom->contains(g);
+}
+
+bool
+BasicPreparedGeometry::containsProperly(const geom::Geometry * g) const
+{
+ return baseGeom->relate(g, "T**FF*FF*");
+}
+
+bool
+BasicPreparedGeometry::coveredBy(const geom::Geometry * g) const
+{
+ return baseGeom->coveredBy(g);
+}
+
+bool
+BasicPreparedGeometry::covers(const geom::Geometry * g) const
+{
+ return baseGeom->covers(g);
+}
+
+bool
+BasicPreparedGeometry::crosses(const geom::Geometry * g) const
+{
+ return baseGeom->crosses(g);
+}
+
+bool
+BasicPreparedGeometry::disjoint(const geom::Geometry * g) const
+{
+ return ! intersects(g);
+}
+
+bool
+BasicPreparedGeometry::intersects(const geom::Geometry * g) const
+{
+ return baseGeom->intersects(g);
+}
+
+bool
+BasicPreparedGeometry::overlaps(const geom::Geometry * g) const
+{
+ return baseGeom->overlaps(g);
+}
+
+bool
+BasicPreparedGeometry::touches(const geom::Geometry * g) const
+{
+ return baseGeom->touches(g);
+}
+
+bool
+BasicPreparedGeometry::within(const geom::Geometry * g) const
+{
+ return baseGeom->within(g);
+}
+
+std::string
+BasicPreparedGeometry::toString()
+{
+ return baseGeom->toString();
+}
+
+} // namespace geos.geom.prep
+} // namespace geos.geom
+} // namespace geos
+
+/**********************************************************************
+ * $Log$
+ *
+ **********************************************************************/
Property changes on: trunk/source/geom/prep/BasicPreparedGeometry.cpp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/source/geom/prep/PreparedGeometry.cpp
===================================================================
--- trunk/source/geom/prep/PreparedGeometry.cpp (rev 0)
+++ trunk/source/geom/prep/PreparedGeometry.cpp 2007-12-21 20:40:27 UTC (rev 2063)
@@ -0,0 +1,30 @@
+/**********************************************************************
+ * $Id:
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2001-2002 Vivid Solutions Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************/
+
+
+#include <geos/geom/prep/PreparedGeometry.h>
+
+namespace geos {
+namespace geom { // geos.geom
+namespace prep { // geos.geom.prep
+
+} // namespace geos.geom.prep
+} // namespace geos.geom
+} // namespace geos
+
+/**********************************************************************
+ * $Log$
+ *
+ **********************************************************************/
Property changes on: trunk/source/geom/prep/PreparedGeometry.cpp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/source/geom/prep/PreparedGeometryFactory.cpp
===================================================================
--- trunk/source/geom/prep/PreparedGeometryFactory.cpp (rev 0)
+++ trunk/source/geom/prep/PreparedGeometryFactory.cpp 2007-12-21 20:40:27 UTC (rev 2063)
@@ -0,0 +1,72 @@
+/**********************************************************************
+ * $Id:
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2001-2002 Vivid Solutions Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************/
+
+
+#include <geos/geom/Point.h>
+#include <geos/geom/MultiPoint.h>
+#include <geos/geom/LineString.h>
+#include <geos/geom/LinearRing.h>
+#include <geos/geom/MultiLineString.h>
+#include <geos/geom/Polygon.h>
+#include <geos/geom/MultiPolygon.h>
+
+#include <geos/geom/prep/PreparedGeometryFactory.h>
+#include <geos/geom/prep/PreparedGeometry.h>
+#include <geos/geom/prep/BasicPreparedGeometry.h>
+#include <geos/geom/prep/PreparedPolygon.h>
+#include <geos/geom/prep/PreparedLineString.h>
+#include <geos/geom/prep/PreparedPoint.h>
+
+namespace geos {
+namespace geom { // geos.geom
+namespace prep { // geos.geom.prep
+
+const PreparedGeometry *
+PreparedGeometryFactory::create( const geom::Geometry * g) const
+{
+ PreparedGeometry * pg;
+
+ switch ( g->getGeometryTypeId() )
+ {
+ case geom::GeometryTypeId::GEOS_MULTIPOINT:
+ case geom::GeometryTypeId::GEOS_POINT:
+ pg = new PreparedPoint( g);
+ break;
+
+ case geom::GeometryTypeId::GEOS_LINEARRING:
+ case geom::GeometryTypeId::GEOS_LINESTRING:
+ case geom::GeometryTypeId::GEOS_MULTILINESTRING:
+ pg = new PreparedLineString( g);
+ break;
+
+ case geom::GeometryTypeId::GEOS_POLYGON:
+ case geom::GeometryTypeId::GEOS_MULTIPOLYGON:
+ pg = new PreparedPolygon( g);
+ break;
+
+ default:
+ pg = new BasicPreparedGeometry( g);
+ }
+ return pg;
+}
+
+} // namespace geos.geom.prep
+} // namespace geos.geom
+} // namespace geos
+
+/**********************************************************************
+ * $Log$
+ *
+ **********************************************************************/
Property changes on: trunk/source/geom/prep/PreparedGeometryFactory.cpp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/source/geom/prep/PreparedLineString.cpp
===================================================================
--- trunk/source/geom/prep/PreparedLineString.cpp (rev 0)
+++ trunk/source/geom/prep/PreparedLineString.cpp 2007-12-21 20:40:27 UTC (rev 2063)
@@ -0,0 +1,61 @@
+/**********************************************************************
+ * $Id:
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2001-2002 Vivid Solutions Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************/
+
+
+#include <geos/geom/prep/PreparedLineString.h>
+#include <geos/geom/prep/PreparedLineStringIntersects.h>
+#include <geos/noding/SegmentStringUtil.h>
+#include <geos/noding/FastSegmentSetIntersectionFinder.h>
+
+namespace geos {
+namespace geom { // geos.geom
+namespace prep { // geos.geom.prep
+
+/*
+ * public:
+ */
+
+noding::FastSegmentSetIntersectionFinder *
+PreparedLineString::getIntersectionFinder()
+{
+ if (! segIntFinder)
+ {
+ noding::SegmentString::ConstVect ss;
+ noding::SegmentStringUtil::extractSegmentStrings( &getGeometry(), ss );
+ segIntFinder = new noding::FastSegmentSetIntersectionFinder( &ss );
+
+ for ( size_t i = 0, ni = ss.size(); i < ni; i++ )
+ delete ss[ i ];
+ }
+
+ return segIntFinder;
+}
+
+bool
+PreparedLineString::intersects(const geom::Geometry * g) const
+{
+ if (! envelopesIntersect(g)) return false;
+
+ return PreparedLineStringIntersects::intersects( *(const_cast<PreparedLineString*>(this)), g);
+}
+
+} // namespace geos.geom.prep
+} // namespace geos.geom
+} // namespace geos
+
+/**********************************************************************
+ * $Log$
+ *
+ **********************************************************************/
Property changes on: trunk/source/geom/prep/PreparedLineString.cpp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/source/geom/prep/PreparedLineStringIntersects.cpp
===================================================================
--- trunk/source/geom/prep/PreparedLineStringIntersects.cpp (rev 0)
+++ trunk/source/geom/prep/PreparedLineStringIntersects.cpp 2007-12-21 20:40:27 UTC (rev 2063)
@@ -0,0 +1,91 @@
+/**********************************************************************
+ * $Id:
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2001-2002 Vivid Solutions Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************/
+
+
+#include <geos/algorithm/PointLocator.h>
+#include <geos/geom/prep/PreparedLineString.h>
+#include <geos/geom/prep/PreparedLineStringIntersects.h>
+#include <geos/geom/util/ComponentCoordinateExtracter.h>
+#include <geos/geom/Coordinate.h>
+#include <geos/noding/SegmentStringUtil.h>
+#include <geos/noding/FastSegmentSetIntersectionFinder.h>
+
+namespace geos {
+namespace geom { // geos.geom
+namespace prep { // geos.geom.prep
+
+ bool PreparedLineStringIntersects::isAnyTestPointInTarget(const geom::Geometry * testGeom) const
+ {
+ /**
+ * This could be optimized by using the segment index on the lineal target.
+ * However, it seems like the L/P case would be pretty rare in practice.
+ */
+ PointLocator * locator = new PointLocator();
+
+ geom::Coordinate::ConstVect coords;
+ ComponentCoordinateExtracter::getCoordinates( *testGeom, coords);
+
+ for (size_t i=0, n=coords.size(); i<n; i++)
+ {
+ geom::Coordinate c = *(coords[i]);
+ if ( locator->intersects( c, &(prepLine.getGeometry()) ))
+ return true;
+ }
+ return false;
+ }
+
+ //bool PreparedLineStringIntersects::intersects( const PreparedLineString * const prep, const geom::Geometry * geom )
+ //{
+ // PreparedLineStringIntersects op = new PreparedLineStringIntersects( prep);
+ // return op.intersects_( geom);
+ //}
+
+ bool PreparedLineStringIntersects::intersects(const geom::Geometry * g) const
+ {
+ // If any segments intersect, obviously intersects = true
+ noding::SegmentString::ConstVect lineSegStr;
+ noding::SegmentStringUtil::extractSegmentStrings( g, lineSegStr);
+ noding::FastSegmentSetIntersectionFinder * fssif = prepLine.getIntersectionFinder();
+ bool segsIntersect = fssif->intersects( &lineSegStr);// prepLine.getIntersectionFinder()->intersects(lineSegStr);
+
+ for ( size_t i = 0, ni = lineSegStr.size(); i < ni; i++ )
+ delete lineSegStr[ i ];
+
+ if ( segsIntersect ) return true;
+
+ // For L/L case we are done
+ if ( g->getDimension() == 1 )
+ return false;
+
+ // For L/A case, need to check for proper inclusion of the target in the test
+ if ( g->getDimension() == 2
+ && prepLine.isAnyTargetComponentInTest(g) )
+ return true;
+
+ // For L/P case, need to check if any points lie on line(s)
+ if ( g->getDimension() == 0 )
+ return isAnyTestPointInTarget(g);
+
+ return false;
+ }
+
+} // namespace geos.geom.prep
+} // namespace geos.geom
+} // namespace geos
+
+/**********************************************************************
+ * $Log$
+ *
+ **********************************************************************/
Property changes on: trunk/source/geom/prep/PreparedLineStringIntersects.cpp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/source/geom/prep/PreparedPoint.cpp
===================================================================
--- trunk/source/geom/prep/PreparedPoint.cpp (rev 0)
+++ trunk/source/geom/prep/PreparedPoint.cpp 2007-12-21 20:40:27 UTC (rev 2063)
@@ -0,0 +1,39 @@
+/**********************************************************************
+ * $Id:
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2001-2002 Vivid Solutions Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************/
+
+
+#include <geos/geom/prep/PreparedPoint.h>
+
+namespace geos {
+namespace geom { // geos.geom
+namespace prep { // geos.geom.prep
+
+bool
+PreparedPoint::intersects( geom::Geometry* g)
+{
+ if (! envelopesIntersect( g)) return false;
+
+ // This avoids computing topology for the test geometry
+ return isAnyTargetComponentInTest( g);
+}
+
+} // namespace geos.geom.prep
+} // namespace geos.geom
+} // namespace geos
+
+/**********************************************************************
+ * $Log$
+ *
+ **********************************************************************/
Property changes on: trunk/source/geom/prep/PreparedPoint.cpp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/source/geom/prep/PreparedPolygon.cpp
===================================================================
--- trunk/source/geom/prep/PreparedPolygon.cpp (rev 0)
+++ trunk/source/geom/prep/PreparedPolygon.cpp 2007-12-21 20:40:27 UTC (rev 2063)
@@ -0,0 +1,145 @@
+/**********************************************************************
+ * $Id:
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2001-2002 Vivid Solutions Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************/
+
+
+#include <geos/geom/Polygon.h>
+
+#include <geos/geom/prep/PreparedPolygon.h>
+#include <geos/geom/prep/PreparedPolygonContains.h>
+#include <geos/geom/prep/PreparedPolygonContainsProperly.h>
+#include <geos/geom/prep/PreparedPolygonCovers.h>
+#include <geos/geom/prep/PreparedPolygonIntersects.h>
+#include <geos/geom/prep/PreparedPolygonLineIntersection.h>
+#include <geos/geom/prep/PreparedPolygonPredicate.h>
+
+#include <geos/noding/FastSegmentSetIntersectionFinder.h>
+#include <geos/noding/SegmentStringUtil.h>
+#include <geos/operation/predicate/RectangleContains.h>
+#include <geos/operation/predicate/RectangleIntersects.h>
+#include <geos/algorithm/locate/PointOnGeometryLocator.h>
+#include <geos/algorithm/locate/IndexedPointInAreaLocator.h>
+
+namespace geos {
+namespace geom { // geos.geom
+namespace prep { // geos.geom.prep
+//
+// public:
+//
+PreparedPolygon::
+PreparedPolygon( const geom::Geometry * geom)
+: BasicPreparedGeometry( geom),
+ segIntFinder( NULL),
+ ptOnGeomLoc( NULL)
+{
+ isRectangle = getGeometry().isRectangle();
+}
+
+PreparedPolygon::
+~PreparedPolygon( )
+{
+ delete segIntFinder;
+ delete ptOnGeomLoc;
+
+ for ( size_t i = 0, ni = segStrings.size(); i < ni; i++ )
+ delete segStrings[ i ];
+}
+
+
+noding::FastSegmentSetIntersectionFinder *
+PreparedPolygon::
+getIntersectionFinder() const
+{
+ if (! segIntFinder)
+ {
+ noding::SegmentStringUtil::extractSegmentStrings( &getGeometry(), segStrings );
+ segIntFinder = new noding::FastSegmentSetIntersectionFinder( &segStrings );
+ }
+ return segIntFinder;
+}
+
+algorithm::locate::PointOnGeometryLocator *
+PreparedPolygon::
+getPointLocator() const
+{
+ if (! ptOnGeomLoc)
+ ptOnGeomLoc = new algorithm::locate::IndexedPointInAreaLocator( getGeometry() );
+
+ return ptOnGeomLoc;
+}
+
+bool
+PreparedPolygon::
+contains( const geom::Geometry * g) const
+{
+ // short-circuit test
+ if ( !envelopeCovers( g) )
+ return false;
+
+ // optimization for rectangles
+ if ( isRectangle )
+ return operation::predicate::RectangleContains::contains( *((geom::Polygon *)&getGeometry()), *g);
+
+ return PreparedPolygonContains::contains( this, g);
+}
+
+bool
+PreparedPolygon::
+containsProperly( const geom::Geometry* g) const
+{
+ // short-circuit test
+ if ( !envelopeCovers( g) )
+ return false;
+
+ return PreparedPolygonContainsProperly::containsProperly( this, g);
+}
+
+bool
+PreparedPolygon::
+covers( const geom::Geometry* g) const
+{
+ // short-circuit test
+ if ( !envelopeCovers( g) )
+ return false;
+
+ // optimization for rectangle arguments
+ if ( isRectangle)
+ return true;
+
+ return PreparedPolygonCovers::covers( this, g);
+}
+
+bool
+PreparedPolygon::
+intersects( const geom::Geometry* g) const
+{
+ // envelope test
+ if ( !envelopesIntersect( g) )
+ return false;
+
+ // optimization for rectangles
+ if ( isRectangle )
+ return operation::predicate::RectangleIntersects::intersects( *((geom::Polygon *)&getGeometry()), *g);
+
+ return PreparedPolygonIntersects::intersects( this, g);
+}
+
+} // namespace geos.geom.prep
+} // namespace geos.geom
+} // namespace geos
+
+/**********************************************************************
+ * $Log$
+ *
+ **********************************************************************/
Property changes on: trunk/source/geom/prep/PreparedPolygon.cpp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/source/geom/prep/PreparedPolygonContains.cpp
===================================================================
--- trunk/source/geom/prep/PreparedPolygonContains.cpp (rev 0)
+++ trunk/source/geom/prep/PreparedPolygonContains.cpp 2007-12-21 20:40:27 UTC (rev 2063)
@@ -0,0 +1,48 @@
+/**********************************************************************
+ * $Id:
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2001-2002 Vivid Solutions Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************/
+
+
+#include <geos/geom/prep/PreparedPolygonContains.h>
+#include <geos/geom/prep/PreparedPolygon.h>
+#include <geos/geom/Geometry.h>
+
+namespace geos {
+namespace geom { // geos.geom
+namespace prep { // geos.geom.prep
+//
+// private:
+//
+
+//
+// protected:
+//
+bool
+PreparedPolygonContains::fullTopologicalPredicate( const geom::Geometry * geom)
+{
+ bool isContained = prepPoly->getGeometry().contains( geom);
+ return isContained;
+}
+
+//
+// public:
+//
+} // namespace geos.geom.prep
+} // namespace geos.geom
+} // namespace geos
+
+/**********************************************************************
+ * $Log$
+ *
+ **********************************************************************/
Property changes on: trunk/source/geom/prep/PreparedPolygonContains.cpp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/source/geom/prep/PreparedPolygonContainsProperly.cpp
===================================================================
--- trunk/source/geom/prep/PreparedPolygonContainsProperly.cpp (rev 0)
+++ trunk/source/geom/prep/PreparedPolygonContainsProperly.cpp 2007-12-21 20:40:27 UTC (rev 2063)
@@ -0,0 +1,81 @@
+/**********************************************************************
+ * $Id:
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2001-2002 Vivid Solutions Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************/
+
+
+#include <geos/geom/Geometry.h>
+#include <geos/geom/Polygon.h>
+#include <geos/geom/MultiPolygon.h>
+#include <geos/geom/prep/PreparedPolygon.h>
+#include <geos/geom/prep/PreparedPolygonContainsProperly.h>
+#include <geos/geom/prep/PreparedPolygonPredicate.h>
+#include <geos/noding/SegmentString.h>
+#include <geos/noding/SegmentStringUtil.h>
+#include <geos/noding/FastSegmentSetIntersectionFinder.h>
+
+namespace geos {
+namespace geom { // geos.geom
+namespace prep { // geos.geom.prep
+//
+// private:
+//
+
+//
+// protected:
+//
+
+//
+// public:
+//
+bool
+PreparedPolygonContainsProperly::containsProperly( const geom::Geometry * geom)
+{
+ // Do point-in-poly tests first, since they are cheaper and may result
+ // in a quick negative result.
+ // If a point of any test components does not lie in target, result is false
+ bool isAllInPrepGeomArea = isAllTestComponentsInTargetInterior( geom);
+ if ( !isAllInPrepGeomArea )
+ return false;
+
+ // If any segments intersect, result is false
+ noding::SegmentString::ConstVect lineSegStr;
+ noding::SegmentStringUtil::extractSegmentStrings( geom, lineSegStr);
+ bool segsIntersect = prepPoly->getIntersectionFinder()->intersects( &lineSegStr);
+
+ for ( size_t i = 0, ni = lineSegStr.size(); i < ni; i++ )
+ delete lineSegStr[ i ];
+
+ if (segsIntersect)
+ return false;
+
+ if ( geom->getGeometryTypeId() == GeometryTypeId::GEOS_MULTIPOLYGON
+ || geom->getGeometryTypeId() == GeometryTypeId::GEOS_POLYGON )
+ {
+ // TODO: generalize this to handle GeometryCollections
+ bool isTargetGeomInTestArea = isAnyTargetComponentInTestArea( geom, prepPoly->getRepresentativePoints());
+ if (isTargetGeomInTestArea)
+ return false;
+ }
+
+ return true;
+}
+
+} // namespace geos.geom.prep
+} // namespace geos.geom
+} // namespace geos
+
+/**********************************************************************
+ * $Log$
+ *
+ **********************************************************************/
Property changes on: trunk/source/geom/prep/PreparedPolygonContainsProperly.cpp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/source/geom/prep/PreparedPolygonCovers.cpp
===================================================================
--- trunk/source/geom/prep/PreparedPolygonCovers.cpp (rev 0)
+++ trunk/source/geom/prep/PreparedPolygonCovers.cpp 2007-12-21 20:40:27 UTC (rev 2063)
@@ -0,0 +1,49 @@
+/**********************************************************************
+ * $Id:
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2001-2002 Vivid Solutions Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************/
+
+
+#include <geos/geom/prep/PreparedPolygonCovers.h>
+#include <geos/geom/prep/PreparedPolygon.h>
+#include <geos/geom/Geometry.h>
+
+namespace geos {
+namespace geom { // geos.geom
+namespace prep { // geos.geom.prep
+//
+// private:
+//
+
+//
+// protected:
+//
+bool
+PreparedPolygonCovers::fullTopologicalPredicate( const geom::Geometry * geom)
+{
+ bool result = prepPoly->getGeometry().covers( geom);
+ return result;
+}
+
+//
+// public:
+//
+
+} // namespace geos.geom.prep
+} // namespace geos.geom
+} // namespace geos
+
+/**********************************************************************
+ * $Log$
+ *
+ **********************************************************************/
Property changes on: trunk/source/geom/prep/PreparedPolygonCovers.cpp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/source/geom/prep/PreparedPolygonIntersects.cpp
===================================================================
--- trunk/source/geom/prep/PreparedPolygonIntersects.cpp (rev 0)
+++ trunk/source/geom/prep/PreparedPolygonIntersects.cpp 2007-12-21 20:40:27 UTC (rev 2063)
@@ -0,0 +1,84 @@
+/**********************************************************************
+ * $Id:
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2001-2002 Vivid Solutions Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************/
+
+
+#include <geos/geom/prep/PreparedPolygonIntersects.h>
+#include <geos/geom/prep/PreparedPolygon.h>
+#include <geos/geom/Geometry.h>
+#include <geos/geom/Polygon.h>
+#include <geos/geom/MultiPolygon.h>
+#include <geos/geom/prep/PreparedPolygonPredicate.h>
+#include <geos/noding/SegmentString.h>
+#include <geos/noding/SegmentStringUtil.h>
+#include <geos/noding/FastSegmentSetIntersectionFinder.h>
+
+namespace geos {
+namespace geom { // geos::geom
+namespace prep { // geos::geom::prep
+//
+// private:
+//
+
+//
+// protected:
+//
+
+//
+// public:
+//
+bool
+PreparedPolygonIntersects::intersects( const geom::Geometry * geom)
+{
+ // Do point-in-poly tests first, since they are cheaper and may result
+ // in a quick positive result.
+ // If a point of any test components lie in target, result is true
+ bool isInPrepGeomArea = isAnyTestComponentInTargetArea( geom);
+ if ( isInPrepGeomArea )
+ return true;
+
+ // If any segments intersect, result is true
+ noding::SegmentString::ConstVect lineSegStr;
+ noding::SegmentStringUtil::extractSegmentStrings( geom, lineSegStr );
+ bool segsIntersect = prepPoly->getIntersectionFinder()->intersects( &lineSegStr);
+
+ for ( size_t i = 0, ni = lineSegStr.size(); i < ni; i++ )
+ delete lineSegStr[ i ];
+ //delete lineSegStr;
+
+ if (segsIntersect)
+ return true;
+
+ // If the test has dimension = 2 as well, it is necessary to
+ // test for proper inclusion of the target.
+ // Since no segments intersect, it is sufficient to test representative points.
+ if ( geom->getDimension() == 2)
+ {
+ // TODO: generalize this to handle GeometryCollections
+ bool isPrepGeomInArea = isAnyTargetComponentInTestArea( geom, prepPoly->getRepresentativePoints());
+ if ( isPrepGeomInArea )
+ return true;
+ }
+
+ return false;
+}
+
+} // geos::geom::prep
+} // geos::geom
+} // geos
+
+/**********************************************************************
+ * $Log$
+ *
+ **********************************************************************/
Property changes on: trunk/source/geom/prep/PreparedPolygonIntersects.cpp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/source/geom/prep/PreparedPolygonLineIntersection.cpp
===================================================================
--- trunk/source/geom/prep/PreparedPolygonLineIntersection.cpp (rev 0)
+++ trunk/source/geom/prep/PreparedPolygonLineIntersection.cpp 2007-12-21 20:40:27 UTC (rev 2063)
@@ -0,0 +1,30 @@
+/**********************************************************************
+ * $Id:
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2001-2002 Vivid Solutions Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************/
+
+
+#include <geos/geom/prep/PreparedPolygonLineIntersection.h>
+
+namespace geos {
+namespace geom { // geos.geom
+namespace prep { // geos.geom.prep
+
+} // namespace geos.geom.prep
+} // namespace geos.geom
+} // namespace geos
+
+/**********************************************************************
+ * $Log$
+ *
+ **********************************************************************/
Property changes on: trunk/source/geom/prep/PreparedPolygonLineIntersection.cpp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/source/geom/prep/PreparedPolygonPredicate.cpp
===================================================================
--- trunk/source/geom/prep/PreparedPolygonPredicate.cpp (rev 0)
+++ trunk/source/geom/prep/PreparedPolygonPredicate.cpp 2007-12-21 20:40:27 UTC (rev 2063)
@@ -0,0 +1,127 @@
+/**********************************************************************
+ * $Id:
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2001-2002 Vivid Solutions Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************/
+
+
+#include <geos/geom/prep/PreparedPolygonPredicate.h>
+#include <geos/geom/prep/PreparedPolygon.h>
+#include <geos/geom/Coordinate.h>
+#include <geos/geom/util/ComponentCoordinateExtracter.h>
+#include <geos/geom/Location.h>
+#include <geos/algorithm/locate/PointOnGeometryLocator.h>
+#include <geos/algorithm/locate/SimplePointInAreaLocator.h>
+
+namespace geos {
+namespace geom { // geos.geom
+namespace prep { // geos.geom.prep
+//
+// private:
+//
+
+//
+// protected:
+//
+bool
+PreparedPolygonPredicate::isAllTestComponentsInTargetArea( const geom::Geometry * testGeom)
+{
+ geom::Coordinate::ConstVect pts;
+ geom::util::ComponentCoordinateExtracter::getCoordinates( *testGeom, pts);
+
+ for ( size_t i = 0, ni = pts.size(); i < ni; i++ )
+ {
+ const geom::Coordinate * pt = pts[ i ];
+ int loc = prepPoly->getPointLocator()->locate( pt );
+ if ( loc == geom::Location::EXTERIOR )
+ return false;
+ }
+ return true;
+}
+
+bool
+PreparedPolygonPredicate::isAllTestComponentsInTargetInterior( const geom::Geometry * testGeom)
+{
+ geom::Coordinate::ConstVect pts;
+ geom::util::ComponentCoordinateExtracter::getCoordinates( *testGeom, pts);
+
+ for ( size_t i = 0, ni = pts.size(); i < ni; i++ )
+ {
+ const geom::Coordinate * pt = pts[ i ];
+ int loc = prepPoly->getPointLocator()->locate( pt );
+ if ( loc != geom::Location::INTERIOR )
+ return false;
+ }
+ return true;
+}
+
+bool
+PreparedPolygonPredicate::isAnyTestComponentInTargetArea( const geom::Geometry * testGeom)
+{
+ geom::Coordinate::ConstVect pts;
+ geom::util::ComponentCoordinateExtracter::getCoordinates( *testGeom, pts);
+
+ for ( size_t i = 0, ni = pts.size(); i < ni; i++ )
+ {
+ const Coordinate * pt = pts[ i ];
+ int loc = prepPoly->getPointLocator()->locate( pt );
+ if ( loc != geom::Location::EXTERIOR )
+ return true;
+ }
+ return false;
+}
+
+bool
+PreparedPolygonPredicate::isAnyTestComponentInTargetInterior( const geom::Geometry * testGeom)
+{
+ geom::Coordinate::ConstVect pts;
+ geom::util::ComponentCoordinateExtracter::getCoordinates( *testGeom, pts);
+
+ for ( size_t i = 0, ni = pts.size(); i < ni; i++ )
+ {
+ const Coordinate * pt = pts[ i ];
+ int loc = prepPoly->getPointLocator()->locate( pt );
+ if ( loc == geom::Location::INTERIOR)
+ return true;
+ }
+ return false;
+}
+
+
+bool
+PreparedPolygonPredicate::isAnyTargetComponentInTestArea( const geom::Geometry * testGeom, const geom::Coordinate::ConstVect * targetRepPts)
+{
+ algorithm::locate::PointOnGeometryLocator * piaLoc;
+ piaLoc = new algorithm::locate::SimplePointInAreaLocator( testGeom);
+
+ for ( size_t i = 0, ni = targetRepPts->size(); i < ni; i++ )
+ {
+ const geom::Coordinate * pt = (*targetRepPts)[ i ];
+ int loc = piaLoc->locate( pt);
+ if ( loc != geom::Location::EXTERIOR )
+ return true;
+ }
+ return false;
+}
+
+//
+// public:
+//
+
+} // namespace geos.geom.prep
+} // namespace geos.geom
+} // namespace geos
+
+/**********************************************************************
+ * $Log$
+ *
+ **********************************************************************/
Property changes on: trunk/source/geom/prep/PreparedPolygonPredicate.cpp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
More information about the geos-commits
mailing list