[geos-commits] r2069 - in trunk/source/algorithm: . locate
svn_geos at osgeo.org
svn_geos at osgeo.org
Fri Dec 21 15:47:01 EST 2007
Author: benjubb
Date: 2007-12-21 15:47:01 -0500 (Fri, 21 Dec 2007)
New Revision: 2069
Added:
trunk/source/algorithm/locate/
trunk/source/algorithm/locate/IndexedPointInAreaLocator.cpp
trunk/source/algorithm/locate/PointOnGeometryLocator.cpp
trunk/source/algorithm/locate/SimplePointInAreaLocator.cpp
Log:
Added from JTS 1.9 to support prepared geometry
Added: trunk/source/algorithm/locate/IndexedPointInAreaLocator.cpp
===================================================================
--- trunk/source/algorithm/locate/IndexedPointInAreaLocator.cpp (rev 0)
+++ trunk/source/algorithm/locate/IndexedPointInAreaLocator.cpp 2007-12-21 20:47:01 UTC (rev 2069)
@@ -0,0 +1,146 @@
+/**********************************************************************
+ * $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/locate/IndexedPointInAreaLocator.h>
+#include <geos/geom/Geometry.h>
+#include <geos/geom/Polygon.h>
+#include <geos/geom/MultiPolygon.h>
+#include <geos/geom/LineString.h>
+#include <geos/geom/LineSegment.h>
+#include <geos/geom/CoordinateSequence.h>
+#include <geos/geom/util/LinearComponentExtracter.h>
+#include <geos/index/intervalrtree/SortedPackedIntervalRTree.h>
+#include <geos/util/IllegalArgumentException.h>
+#include <geos/algorithm/RayCrossingCounter.h>
+#include <geos/index/ItemVisitor.h>
+
+#include <algorithm>
+
+namespace geos {
+namespace algorithm {
+namespace locate {
+//
+// private:
+//
+IndexedPointInAreaLocator::IntervalIndexedGeometry::IntervalIndexedGeometry( const geom::Geometry & g)
+{
+ index = new index::intervalrtree::SortedPackedIntervalRTree();
+ init( g);
+}
+
+IndexedPointInAreaLocator::IntervalIndexedGeometry::~IntervalIndexedGeometry( )
+{
+ delete index;
+}
+
+void
+IndexedPointInAreaLocator::IntervalIndexedGeometry::init( const geom::Geometry & g)
+{
+ geom::LineString::ConstVect lines;
+ geom::util::LinearComponentExtracter::getLines( g, lines);
+
+ for ( size_t i = 0, ni = lines.size(); i < ni; i++ )
+ {
+ const geom::LineString * line = lines[ i ];
+ geom::CoordinateSequence * pts = line->getCoordinates();
+
+ addLine( pts);
+
+ delete pts;
+ }
+}
+
+void
+IndexedPointInAreaLocator::IntervalIndexedGeometry::addLine( geom::CoordinateSequence * pts)
+{
+ for ( size_t i = 1, ni = pts->size(); i < ni; i++ )
+ {
+ geom::LineSegment * seg = new geom::LineSegment( (*pts)[ i - 1 ], (*pts)[ i ]);
+
+ double min = std::min( seg->p0.y, seg->p1.y);
+ double max = std::max( seg->p0.y, seg->p1.y);
+
+ index->insert( min, max, seg);
+ }
+}
+
+
+void
+IndexedPointInAreaLocator::buildIndex( const geom::Geometry & g)
+{
+ index = new IndexedPointInAreaLocator::IntervalIndexedGeometry( g);
+}
+
+
+//
+// protected:
+//
+
+//
+// public:
+//
+IndexedPointInAreaLocator::IndexedPointInAreaLocator( const geom::Geometry & g)
+: areaGeom( g)
+{
+ if ( typeid( areaGeom) != typeid( geom::Polygon)
+ && typeid( areaGeom) != typeid( geom::MultiPolygon) )
+ throw new util::IllegalArgumentException("Argument must be Polygonal");
+
+ //areaGeom = g;
+
+ buildIndex( areaGeom);
+}
+
+IndexedPointInAreaLocator::~IndexedPointInAreaLocator()
+{
+ delete index;
+}
+
+int
+IndexedPointInAreaLocator::locate( const geom::Coordinate * /*const*/ p)
+{
+ algorithm::RayCrossingCounter rcc( p);
+
+ IndexedPointInAreaLocator::SegmentVisitor visitor( &rcc);
+
+ index->query( p->y, p->y, &visitor);
+
+ return rcc.getLocation();
+}
+
+void
+IndexedPointInAreaLocator::SegmentVisitor::visitItem( void * item)
+{
+ geom::LineSegment * seg = (geom::LineSegment *)item;
+
+ counter->countSegment( &(*seg)[ 0 ], &(*seg)[ 1 ]);
+}
+
+void
+IndexedPointInAreaLocator::IntervalIndexedGeometry::query( double min, double max, index::ItemVisitor * visitor)
+{
+ index->query( min, max, visitor);
+}
+
+
+} // geos::algorithm::locate
+} // geos::algorithm
+} // geos
+
+/**********************************************************************
+ * $Log$
+ *
+ **********************************************************************/
Property changes on: trunk/source/algorithm/locate/IndexedPointInAreaLocator.cpp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/source/algorithm/locate/PointOnGeometryLocator.cpp
===================================================================
--- trunk/source/algorithm/locate/PointOnGeometryLocator.cpp (rev 0)
+++ trunk/source/algorithm/locate/PointOnGeometryLocator.cpp 2007-12-21 20:47:01 UTC (rev 2069)
@@ -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/algorithm/locate/PointOnGeometryLocator.h>
+
+namespace geos {
+namespace algorithm { // geos::algorithm
+namespace locate { // geos::algorithm::locate
+
+} // geos::algorithm::locate
+} // geos::algorithm
+} // geos
+
+/**********************************************************************
+ * $Log$
+ *
+ **********************************************************************/
Property changes on: trunk/source/algorithm/locate/PointOnGeometryLocator.cpp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/source/algorithm/locate/SimplePointInAreaLocator.cpp
===================================================================
--- trunk/source/algorithm/locate/SimplePointInAreaLocator.cpp (rev 0)
+++ trunk/source/algorithm/locate/SimplePointInAreaLocator.cpp 2007-12-21 20:47:01 UTC (rev 2069)
@@ -0,0 +1,111 @@
+/**********************************************************************
+ * $Id$
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2005-2006 Refractions Research Inc.
+ * 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/CGAlgorithms.h>
+#include <geos/algorithm/locate/SimplePointInAreaLocator.h>
+#include <geos/geom/Geometry.h>
+#include <geos/geom/Polygon.h>
+#include <geos/geom/GeometryCollection.h>
+#include <geos/geom/Location.h>
+#include <geos/geom/CoordinateSequence.h>
+#include <geos/geom/LineString.h>
+
+#include <typeinfo>
+#include <cassert>
+
+using namespace geos::geom;
+
+namespace geos {
+namespace algorithm { // geos.algorithm
+namespace locate { // geos.algorithm
+
+/**
+ * locate is the main location function. It handles both single-element
+ * and multi-element Geometries. The algorithm for multi-element Geometries
+ * is more complex, since it has to take into account the boundaryDetermination rule
+ */
+int
+SimplePointInAreaLocator::locate(const Coordinate& p, const Geometry *geom)
+{
+ if (geom->isEmpty()) return Location::EXTERIOR;
+ if (containsPoint(p,geom))
+ return Location::INTERIOR;
+ return Location::EXTERIOR;
+}
+
+bool
+SimplePointInAreaLocator::containsPoint(const Coordinate& p,const Geometry *geom)
+{
+ if (const Polygon *poly = dynamic_cast<const Polygon*>(geom))
+ {
+ return containsPointInPolygon(p, poly);
+ }
+
+ if (const GeometryCollection *col = dynamic_cast<const GeometryCollection*>(geom))
+ {
+ for (GeometryCollection::const_iterator
+ it=col->begin(), endIt=col->end();
+ it != endIt;
+ ++it)
+ {
+ const Geometry *g2=*it;
+ assert (g2!=geom);
+ if (containsPoint(p,g2)) return true;
+ }
+ }
+ return false;
+}
+
+bool
+SimplePointInAreaLocator::containsPointInPolygon(const Coordinate& p, const Polygon *poly)
+{
+ if (poly->isEmpty()) return false;
+ const LineString *shell=poly->getExteriorRing();
+ const CoordinateSequence *cl;
+ cl = shell->getCoordinatesRO();
+ if (!CGAlgorithms::isPointInRing(p,cl)) {
+ return false;
+ }
+
+ // now test if the point lies in or on the holes
+ for(size_t i=0, n=poly->getNumInteriorRing(); i<n; i++)
+ {
+ const LineString *hole = poly->getInteriorRingN(i);
+ cl = hole->getCoordinatesRO();
+ if (CGAlgorithms::isPointInRing(p,cl)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+} // namespace geos.algorithm.locate
+} // namespace geos.algorithm
+} // namespace geos
+
+/**********************************************************************
+ * $Log$
+ * Revision 1.22 2006/06/12 11:29:23 strk
+ * unsigned int => size_t
+ *
+ * Revision 1.21 2006/03/21 11:12:23 strk
+ * Cleanups: headers inclusion and Log section
+ *
+ * Revision 1.20 2006/03/09 16:46:46 strk
+ * geos::geom namespace definition, first pass at headers split
+ *
+ **********************************************************************/
+
Property changes on: trunk/source/algorithm/locate/SimplePointInAreaLocator.cpp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
More information about the geos-commits
mailing list