[geos-commits] r3187 - in trunk: include/geos/operation/union src/operation/union

svn_geos at osgeo.org svn_geos at osgeo.org
Mon Feb 7 10:41:33 EST 2011


Author: strk
Date: 2011-02-07 07:41:32 -0800 (Mon, 07 Feb 2011)
New Revision: 3187

Added:
   trunk/include/geos/operation/union/PointGeometryUnion.h
   trunk/src/operation/union/PointGeometryUnion.cpp
Modified:
   trunk/include/geos/operation/union/Makefile.am
   trunk/src/operation/union/Makefile.am
Log:
PointGeometryUnion port

Modified: trunk/include/geos/operation/union/Makefile.am
===================================================================
--- trunk/include/geos/operation/union/Makefile.am	2011-02-07 15:39:36 UTC (rev 3186)
+++ trunk/include/geos/operation/union/Makefile.am	2011-02-07 15:41:32 UTC (rev 3187)
@@ -9,4 +9,5 @@
 geosdir = $(includedir)/geos/operation/union
 
 geos_HEADERS = \
-    CascadedPolygonUnion.h
+    CascadedPolygonUnion.h \
+    PointGeometryUnion.h

Added: trunk/include/geos/operation/union/PointGeometryUnion.h
===================================================================
--- trunk/include/geos/operation/union/PointGeometryUnion.h	                        (rev 0)
+++ trunk/include/geos/operation/union/PointGeometryUnion.h	2011-02-07 15:41:32 UTC (rev 3187)
@@ -0,0 +1,72 @@
+/**********************************************************************
+ * $Id$
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2011 Sandro Santilli <strk at keybit.net
+ *
+ * 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.
+ *
+ **********************************************************************
+ *
+ * Last port: operation/union/PointGeometryUnion.java r320 (JTS-1.12)
+ *
+ **********************************************************************/
+
+#ifndef GEOS_OP_UNION_POINTGEOMETRYUNION_H
+#define GEOS_OP_UNION_POINTGEOMETRYUNION_H
+#include <geos/export.h>
+
+#include <vector>
+#include <algorithm>
+
+// Forward declarations
+namespace geos {
+    namespace geom {
+        class GeometryFactory;
+        class Geometry;
+        class Puntal;
+    }
+}
+
+namespace geos {
+namespace operation { // geos::operation
+namespace geounion {  // geos::operation::geounion
+
+/**
+ * \brief 
+ * Computes the union of a {@link Puntal} geometry with
+ * another arbitrary {@link Geometry}.
+ *
+ * Does not copy any component geometries.
+ *
+ */
+class GEOS_DLL PointGeometryUnion 
+{
+public:
+
+  static std::auto_ptr<geom::Geometry> Union(
+      const geom::Puntal& pointGeom,
+      const geom::Geometry& otherGeom);
+
+
+  PointGeometryUnion(const geom::Puntal& pointGeom,
+                     const geom::Geometry& otherGeom);
+
+  std::auto_ptr<geom::Geometry> Union() const;
+
+private:
+  const geom::Geometry& pointGeom;
+  const geom::Geometry& otherGeom;
+  const geom::GeometryFactory* geomFact;
+};
+
+} // namespace geos::operation::union
+} // namespace geos::operation
+} // namespace geos
+
+#endif

Modified: trunk/src/operation/union/Makefile.am
===================================================================
--- trunk/src/operation/union/Makefile.am	2011-02-07 15:39:36 UTC (rev 3186)
+++ trunk/src/operation/union/Makefile.am	2011-02-07 15:41:32 UTC (rev 3187)
@@ -9,6 +9,7 @@
 INCLUDES = -I$(top_srcdir)/include 
 
 libopunion_la_SOURCES = \
-    CascadedPolygonUnion.cpp 
+    CascadedPolygonUnion.cpp \
+    PointGeometryUnion.cpp 
 
 libopunion_la_LIBADD = 

Added: trunk/src/operation/union/PointGeometryUnion.cpp
===================================================================
--- trunk/src/operation/union/PointGeometryUnion.cpp	                        (rev 0)
+++ trunk/src/operation/union/PointGeometryUnion.cpp	2011-02-07 15:41:32 UTC (rev 3187)
@@ -0,0 +1,102 @@
+/**********************************************************************
+ * $Id$
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2011 Sandro Santilli <strk at keybit.net
+ *
+ * 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.
+ *
+ **********************************************************************
+ *
+ * Last port: operation/union/PointGeometryUnion.java r320 (JTS-1.12)
+ *
+ **********************************************************************/
+
+#include <memory> // for auto_ptr
+#include <algorithm> // for copy
+#include <geos/operation/union/PointGeometryUnion.h> 
+#include <geos/geom/Coordinate.h> 
+#include <geos/geom/Puntal.h> 
+#include <geos/geom/Point.h>
+#include <geos/geom/MultiPoint.h>
+#include <geos/geom/Geometry.h>
+#include <geos/geom/Location.h>
+#include <geos/geom/GeometryFactory.h>
+#include <geos/geom/util/GeometryCombiner.h>
+#include <geos/algorithm/PointLocator.h>
+
+namespace geos {
+namespace operation { // geos::operation
+namespace geounion {  // geos::operation::geounion
+
+/* public */
+std::auto_ptr<geom::Geometry>
+PointGeometryUnion::Union() const
+{
+  using namespace geom;
+  using algorithm::PointLocator;
+  using geom::util::GeometryCombiner;
+
+  PointLocator locater;
+  // use a set to eliminate duplicates, as required for union
+  std::set<Coordinate> exteriorCoords;
+
+  for (std::size_t i=0, n=pointGeom.getNumGeometries(); i<n; ++i) {
+      assert(dynamic_cast<const Point*>(pointGeom.getGeometryN(i)));
+      const Point& point = *(static_cast<const Point*>(pointGeom.getGeometryN(i)));
+      const Coordinate* coord = point.getCoordinate();
+      int loc = locater.locate(*coord, &otherGeom);
+      if (loc == Location::EXTERIOR)
+              exteriorCoords.insert(*coord);
+  }
+
+  // if no points are in exterior, return the other geom
+  if (exteriorCoords.empty())
+          return std::auto_ptr<Geometry>(otherGeom.clone());
+
+  // make a puntal geometry of appropriate size
+  std::auto_ptr<Geometry> ptComp;
+
+  if (exteriorCoords.size() == 1) {
+    ptComp.reset( geomFact->createPoint(*(exteriorCoords.begin())) );
+  }
+  else
+  {
+    std::vector<Coordinate> coords;
+    std::copy(exteriorCoords.begin(), exteriorCoords.end(), coords.begin());
+    ptComp.reset( geomFact->createMultiPoint(coords) );
+  }
+
+  // add point component to the other geometry
+  return std::auto_ptr<Geometry> (
+    GeometryCombiner::combine(ptComp.get(), &otherGeom)
+  );
+}
+
+/* public  static */
+std::auto_ptr<geom::Geometry>
+PointGeometryUnion::Union(const geom::Puntal& pointGeom,
+      const geom::Geometry& otherGeom)
+{
+  PointGeometryUnion unioner(pointGeom, otherGeom);
+  return unioner.Union();
+}
+
+/* public */
+PointGeometryUnion::PointGeometryUnion(const geom::Puntal& pointGeom_,
+                     const geom::Geometry& otherGeom_)
+  :
+  pointGeom ( pointGeom_ ),
+  otherGeom ( otherGeom_ )
+{
+  geomFact = otherGeom.getFactory();
+}
+
+} // namespace geos::operation::union
+} // namespace geos::operation
+} // namespace geos



More information about the geos-commits mailing list