[geos-commits] r2360 - in trunk/source: geom headers/geos/geom

svn_geos at osgeo.org svn_geos at osgeo.org
Tue Apr 14 11:25:58 EDT 2009


Author: strk
Date: 2009-04-14 11:25:58 -0400 (Tue, 14 Apr 2009)
New Revision: 2360

Added:
   trunk/source/headers/geos/geom/CoordinateSequenceFilter.h
Modified:
   trunk/source/geom/Geometry.cpp
   trunk/source/geom/GeometryCollection.cpp
   trunk/source/geom/GeometryComponentFilter.cpp
   trunk/source/geom/LineString.cpp
   trunk/source/geom/Point.cpp
   trunk/source/geom/Polygon.cpp
   trunk/source/headers/geos/geom/Geometry.h
   trunk/source/headers/geos/geom/GeometryCollection.h
   trunk/source/headers/geos/geom/LineString.h
   trunk/source/headers/geos/geom/Makefile.am
   trunk/source/headers/geos/geom/Point.h
   trunk/source/headers/geos/geom/Polygon.h
Log:
Add CoordinateSequenceFilter support, fix default GeometryComponentFilter moving the logic to the correct place (a Geometry private class). 


Modified: trunk/source/geom/Geometry.cpp
===================================================================
--- trunk/source/geom/Geometry.cpp	2009-04-14 13:35:21 UTC (rev 2359)
+++ trunk/source/geom/Geometry.cpp	2009-04-14 15:25:58 UTC (rev 2360)
@@ -96,7 +96,7 @@
 	return GEOS_JTS_PORT;
 }
 
-GeometryComponentFilter Geometry::geometryChangedFilter;
+Geometry::GeometryChangedFilter Geometry::geometryChangedFilter;
 
 // REMOVE THIS, use GeometryFactory::getDefaultInstance() directly
 const GeometryFactory* Geometry::INTERNAL_GEOMETRY_FACTORY=GeometryFactory::getDefaultInstance();

Modified: trunk/source/geom/GeometryCollection.cpp
===================================================================
--- trunk/source/geom/GeometryCollection.cpp	2009-04-14 13:35:21 UTC (rev 2359)
+++ trunk/source/geom/GeometryCollection.cpp	2009-04-14 15:25:58 UTC (rev 2360)
@@ -18,6 +18,7 @@
 #include <geos/algorithm/CGAlgorithms.h>
 #include <geos/util/IllegalArgumentException.h>
 #include <geos/geom/CoordinateSequence.h>
+#include <geos/geom/CoordinateSequenceFilter.h>
 #include <geos/geom/CoordinateArraySequenceFactory.h>
 #include <geos/geom/Dimension.h>
 #include <geos/geom/GeometryFilter.h>
@@ -304,6 +305,32 @@
 	}
 }
 
+void
+GeometryCollection::apply_rw(CoordinateSequenceFilter& filter)
+{
+	size_t ngeoms = geometries->size();
+	if (ngeoms == 0 ) return;
+	for (size_t i = 0; i < ngeoms; ++i)
+	{
+		(*geometries)[i]->apply_rw(filter);
+		if (filter.isDone()) break;
+	}
+	if (filter.isGeometryChanged()) geometryChanged();
+}
+
+void
+GeometryCollection::apply_ro(CoordinateSequenceFilter& filter) const
+{
+	size_t ngeoms = geometries->size();
+	if (ngeoms == 0 ) return;
+	for (size_t i = 0; i < ngeoms; ++i)
+	{
+		(*geometries)[i]->apply_ro(filter);
+		if (filter.isDone()) break;
+	}
+	//if (filter.isGeometryChanged()) geometryChanged();
+}
+
 GeometryCollection::~GeometryCollection()
 {
 	for(size_t i=0; i<geometries->size(); ++i)

Modified: trunk/source/geom/GeometryComponentFilter.cpp
===================================================================
--- trunk/source/geom/GeometryComponentFilter.cpp	2009-04-14 13:35:21 UTC (rev 2359)
+++ trunk/source/geom/GeometryComponentFilter.cpp	2009-04-14 15:25:58 UTC (rev 2360)
@@ -23,14 +23,16 @@
 namespace geos {
 namespace geom { // geos::geom
 
-void GeometryComponentFilter::filter_rw(Geometry *geom) {
-	geom->geometryChangedAction();
+void GeometryComponentFilter::filter_rw(Geometry *geom)
+{
+	UNREFERENCED_PARAMETER(geom);
+	assert(0);
 }
 
 void GeometryComponentFilter::filter_ro(const Geometry *geom)
 {
-    UNREFERENCED_PARAMETER(geom);
-	//assert(0);
+	UNREFERENCED_PARAMETER(geom);
+	assert(0);
 }
 
 

Modified: trunk/source/geom/LineString.cpp
===================================================================
--- trunk/source/geom/LineString.cpp	2009-04-14 13:35:21 UTC (rev 2359)
+++ trunk/source/geom/LineString.cpp	2009-04-14 15:25:58 UTC (rev 2360)
@@ -20,6 +20,7 @@
 #include <geos/geom/Coordinate.h>
 #include <geos/geom/CoordinateSequenceFactory.h>
 #include <geos/geom/CoordinateSequence.h>
+#include <geos/geom/CoordinateSequenceFilter.h>
 #include <geos/geom/CoordinateFilter.h>
 #include <geos/geom/Dimension.h>
 #include <geos/geom/GeometryFilter.h>
@@ -382,6 +383,32 @@
 	filter->filter_ro(this);
 }
 
+void
+LineString::apply_rw(CoordinateSequenceFilter& filter)
+{
+	size_t npts=points->size();
+	if (!npts) return;
+	for (size_t i = 0; i<npts; ++i)
+	{
+		filter.filter_rw(*points, i);
+		if (filter.isDone()) break;
+	}
+	if (filter.isGeometryChanged()) geometryChanged();
+}
+
+void
+LineString::apply_ro(CoordinateSequenceFilter& filter) const
+{
+	size_t npts=points->size();
+	if (!npts) return;
+	for (size_t i = 0; i<npts; ++i)
+	{
+		filter.filter_ro(*points, i);
+		if (filter.isDone()) break;
+	}
+	//if (filter.isGeometryChanged()) geometryChanged();
+}
+
 GeometryTypeId
 LineString::getGeometryTypeId() const
 {

Modified: trunk/source/geom/Point.cpp
===================================================================
--- trunk/source/geom/Point.cpp	2009-04-14 13:35:21 UTC (rev 2359)
+++ trunk/source/geom/Point.cpp	2009-04-14 15:25:58 UTC (rev 2360)
@@ -19,6 +19,7 @@
 #include <geos/geom/Coordinate.h>
 #include <geos/geom/Point.h>
 #include <geos/geom/CoordinateSequence.h>
+#include <geos/geom/CoordinateSequenceFilter.h>
 #include <geos/geom/CoordinateFilter.h>
 #include <geos/geom/GeometryFilter.h>
 #include <geos/geom/GeometryComponentFilter.h>
@@ -187,6 +188,22 @@
 	filter->filter_ro(this);
 }
 
+void
+Point::apply_rw(CoordinateSequenceFilter& filter)
+{
+	if (isEmpty()) return;
+	filter.filter_rw(*coordinates, 0);
+	if (filter.isGeometryChanged()) geometryChanged();
+}
+
+void
+Point::apply_ro(CoordinateSequenceFilter& filter) const
+{
+	if (isEmpty()) return;
+	filter.filter_ro(*coordinates, 0);
+	//if (filter.isGeometryChanged()) geometryChanged();
+}
+
 bool
 Point::equalsExact(const Geometry *other, double tolerance) const
 {

Modified: trunk/source/geom/Polygon.cpp
===================================================================
--- trunk/source/geom/Polygon.cpp	2009-04-14 13:35:21 UTC (rev 2359)
+++ trunk/source/geom/Polygon.cpp	2009-04-14 15:25:58 UTC (rev 2360)
@@ -29,6 +29,7 @@
 #include <geos/geom/Envelope.h>
 #include <geos/geom/CoordinateSequenceFactory.h>
 #include <geos/geom/CoordinateSequence.h>
+#include <geos/geom/CoordinateSequenceFilter.h>
 #include <geos/geom/GeometryFilter.h>
 #include <geos/geom/GeometryComponentFilter.h>
 
@@ -409,6 +410,40 @@
 	}
 }
 
+void
+Polygon::apply_rw(CoordinateSequenceFilter& filter)
+{
+	shell->apply_rw(filter);
+
+	if (! filter.isDone())
+	{
+		for (size_t i=0, n=holes->size(); i<n; ++i)
+		{
+			(*holes)[i]->apply_rw(filter);
+			if (filter.isDone())
+			break;
+        	}
+	}
+	if (filter.isGeometryChanged()) geometryChanged();
+}
+
+void
+Polygon::apply_ro(CoordinateSequenceFilter& filter) const
+{
+	shell->apply_ro(filter);
+
+	if (! filter.isDone())
+	{
+		for (size_t i=0, n=holes->size(); i<n; ++i)
+		{
+			(*holes)[i]->apply_ro(filter);
+			if (filter.isDone())
+			break;
+        	}
+	}
+	//if (filter.isGeometryChanged()) geometryChanged();
+}
+
 Polygon::~Polygon()
 {
 	delete shell;

Added: trunk/source/headers/geos/geom/CoordinateSequenceFilter.h
===================================================================
--- trunk/source/headers/geos/geom/CoordinateSequenceFilter.h	                        (rev 0)
+++ trunk/source/headers/geos/geom/CoordinateSequenceFilter.h	2009-04-14 15:25:58 UTC (rev 2360)
@@ -0,0 +1,114 @@
+/**********************************************************************
+ * $Id$
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2009  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: geom/CoordinateSequenceFilter.java rev. 1.3 (JTS-1.9)
+ *
+ **********************************************************************/
+
+#ifndef GEOS_GEOM_COORDINATESEQUENCEFILTER_H
+#define GEOS_GEOM_COORDINATESEQUENCEFILTER_H
+
+#include <geos/inline.h>
+
+#include <cassert>
+
+// Forward declarations
+namespace geos {
+	namespace geom {
+		class CoordinateSequence;
+	}
+}
+
+namespace geos {
+namespace geom { // geos::geom
+
+/**
+ *  Interface for classes which provide operations that
+ *  can be applied to the coordinates in a {@link CoordinateSequence}.
+ *  A CoordinateSequence filter can either record information about each
+ *  coordinate or change the coordinate in some way.
+ *  CoordinateSequence filters can be
+ *  used to implement such things as coordinate transformations, centroid and
+ *  envelope computation, and many other functions.
+ *  For maximum efficiency, the execution of filters can be short-circuited.
+ *  {@link Geometry} classes support the concept of applying a
+ *  <code>CoordinateSequenceFilter</code> to each
+ *  {@link CoordinateSequence}s they contain.
+ *  <p>
+ *  <code>CoordinateSequenceFilter</code> is
+ *  an example of the Gang-of-Four Visitor pattern.
+ *
+ * @see Geometry::apply_ro(CoordinateSequenceFilter)
+ * @see Geometry::apply_rw(CoordinateSequenceFilter)
+ * @author Martin Davis
+ *
+ */
+class CoordinateSequenceFilter {
+
+public:
+
+  virtual ~CoordinateSequenceFilter() {}
+
+  /**
+   * Performs an operation on a coordinate in a {@link CoordinateSequence}.
+   *
+   * @param seq  the <code>CoordinateSequence</code> to which the filter
+   *             is applied
+   * @param i the index of the coordinate to apply the filter to
+   */
+  virtual void filter_rw(CoordinateSequence& /*seq*/, size_t i) const
+  { assert(0); }
+
+  /**
+   * Performs an operation on a coordinate in a {@link CoordinateSequence}.
+   *
+   * @param seq  the <code>CoordinateSequence</code> to which the filter
+   *             is applied
+   * @param i the index of the coordinate to apply the filter to
+   */
+  virtual void filter_ro(const CoordinateSequence& /*seq*/, size_t i) const
+  { assert(0); }
+
+  /**
+   * Reports whether the application of this filter can be terminated.
+   * Once this method returns <tt>false</tt>, it should
+   * continue to return <tt>false</tt> on every subsequent call.
+   *
+   * @return true if the application of this filter can be terminated.
+   */
+  virtual bool isDone() const = 0;
+
+
+  /**
+   * Reports whether the execution of this filter
+   * has modified the coordinates of the geometry.
+   * If so, {@link Geometry#geometryChanged} will be executed
+   * after this filter has finished being executed.
+   * 
+   * Most filters can simply return a constant value reflecting
+   * whether they are able to change the coordinates.
+   *
+   * @return true if this filter has changed the coordinates of the geometry
+   */
+  virtual bool isGeometryChanged() const = 0;
+
+};
+
+} // namespace geos::geom
+} // namespace geos
+
+
+#endif // ndef GEOS_GEOM_COORDINATESEQUENCEFILTER_H
+

Modified: trunk/source/headers/geos/geom/Geometry.h
===================================================================
--- trunk/source/headers/geos/geom/Geometry.h	2009-04-14 13:35:21 UTC (rev 2359)
+++ trunk/source/headers/geos/geom/Geometry.h	2009-04-14 15:25:58 UTC (rev 2360)
@@ -25,6 +25,7 @@
 #include <geos/inline.h>
 #include <geos/geom/Envelope.h>
 #include <geos/geom/Dimension.h> // for Dimension::DimensionType
+#include <geos/geom/GeometryComponentFilter.h> // for inheritance
 
 #include <string>
 #include <iostream>
@@ -37,6 +38,7 @@
 		class Coordinate;
 		class CoordinateFilter;
 		class CoordinateSequence;
+		class CoordinateSequenceFilter;
 		class Envelope;
 		class GeometryComponentFilter;
 		class GeometryFactory;
@@ -579,6 +581,24 @@
 	virtual void apply_rw(GeometryComponentFilter *filter);
 	virtual void apply_ro(GeometryComponentFilter *filter) const;
 
+	/**
+	 *  Performs an operation on the coordinates in this Geometry's
+	 *  CoordinateSequences.s
+	 *  If the filter reports that a coordinate value has been changed,
+	 *  {@link #geometryChanged} will be called automatically.
+	 *
+	 * @param  filter  the filter to apply
+	 */
+	virtual void apply_rw(CoordinateSequenceFilter& filter)=0;
+
+	/**
+	 *  Performs a read-only operation on the coordinates in this
+	 *  Geometry's CoordinateSequences.
+	 *
+	 * @param  filter  the filter to apply
+	 */
+	virtual void apply_ro(CoordinateSequenceFilter& filter) const=0;
+
 	/** \brief
 	 * Apply a fiter to each component of this geometry.
 	 * The filter is expected to provide a .filter(const Geometry*)
@@ -723,8 +743,21 @@
 	Geometry(const GeometryFactory *factory);
 
 private:
+
+
+
 	int getClassSortIndex() const;
-	static GeometryComponentFilter geometryChangedFilter;
+
+	class GeometryChangedFilter : public GeometryComponentFilter
+	{
+	public:
+		void filter_rw(Geometry* geom)
+		{
+			geom->geometryChangedAction();
+		}
+	};
+
+	static GeometryChangedFilter geometryChangedFilter;
 	const GeometryFactory *factory;
 	static const GeometryFactory* INTERNAL_GEOMETRY_FACTORY;
 	void* userData;

Modified: trunk/source/headers/geos/geom/GeometryCollection.h
===================================================================
--- trunk/source/headers/geos/geom/GeometryCollection.h	2009-04-14 13:35:21 UTC (rev 2359)
+++ trunk/source/headers/geos/geom/GeometryCollection.h	2009-04-14 15:25:58 UTC (rev 2360)
@@ -33,6 +33,7 @@
 	namespace geom { // geos::geom
 		class Coordinate;
 		class CoordinateArraySequence;
+		class CoordinateSequenceFilter;
 	}
 }
 
@@ -125,6 +126,10 @@
 
 	virtual void apply_rw(GeometryComponentFilter *filter);
 
+	virtual void apply_rw(CoordinateSequenceFilter& filter);
+
+	virtual void apply_ro(CoordinateSequenceFilter& filter) const;
+
 	virtual void normalize();
 
 	virtual const Coordinate* getCoordinate() const;

Modified: trunk/source/headers/geos/geom/LineString.h
===================================================================
--- trunk/source/headers/geos/geom/LineString.h	2009-04-14 13:35:21 UTC (rev 2359)
+++ trunk/source/headers/geos/geom/LineString.h	2009-04-14 15:25:58 UTC (rev 2360)
@@ -33,6 +33,7 @@
 	namespace geom {
 		class Coordinate;
 		class CoordinateArraySequence;
+		class CoordinateSequenceFilter;
 	}
 }
 
@@ -125,6 +126,10 @@
 
 	virtual void apply_ro(GeometryComponentFilter *filter) const;
 
+	void apply_rw(CoordinateSequenceFilter& filter);
+
+	void apply_ro(CoordinateSequenceFilter& filter) const;
+
 	/** \brief
 	 * Normalizes a LineString. 
 	 *

Modified: trunk/source/headers/geos/geom/Makefile.am
===================================================================
--- trunk/source/headers/geos/geom/Makefile.am	2009-04-14 13:35:21 UTC (rev 2359)
+++ trunk/source/headers/geos/geom/Makefile.am	2009-04-14 15:25:58 UTC (rev 2360)
@@ -22,6 +22,7 @@
 	CoordinateList.h			\
 	CoordinateSequence.h			\
 	CoordinateSequenceFactory.h		\
+	CoordinateSequenceFilter.h		\
 	Dimension.h				\
 	Envelope.h				\
 	Envelope.inl				\

Modified: trunk/source/headers/geos/geom/Point.h
===================================================================
--- trunk/source/headers/geos/geom/Point.h	2009-04-14 13:35:21 UTC (rev 2359)
+++ trunk/source/headers/geos/geom/Point.h	2009-04-14 15:25:58 UTC (rev 2360)
@@ -35,6 +35,7 @@
 		class Coordinate;
 		class CoordinateArraySequence;
 		class CoordinateFilter;
+		class CoordinateSequenceFilter;
 		class GeometryComponentFilter;
 		class GeometryFilter;
 	}
@@ -89,6 +90,8 @@
 	void apply_rw(GeometryFilter *filter);
 	void apply_rw(GeometryComponentFilter *filter);
 	void apply_ro(GeometryComponentFilter *filter) const;
+	void apply_rw(CoordinateSequenceFilter& filter);
+	void apply_ro(CoordinateSequenceFilter& filter) const;
 
 	bool equalsExact(const Geometry *other, double tolerance=0) const;
 	void normalize(void) { };

Modified: trunk/source/headers/geos/geom/Polygon.h
===================================================================
--- trunk/source/headers/geos/geom/Polygon.h	2009-04-14 13:35:21 UTC (rev 2359)
+++ trunk/source/headers/geos/geom/Polygon.h	2009-04-14 15:25:58 UTC (rev 2360)
@@ -37,6 +37,7 @@
 	namespace geom { // geos::geom
 		class Coordinate;
 		class CoordinateArraySequence;
+		class CoordinateSequenceFilter;
 		class LinearRing;
 		class LineString;
 	}
@@ -117,6 +118,8 @@
 	void apply_ro(CoordinateFilter *filter) const;
 	void apply_rw(GeometryFilter *filter);
 	void apply_ro(GeometryFilter *filter) const;
+	void apply_rw(CoordinateSequenceFilter& filter);
+	void apply_ro(CoordinateSequenceFilter& filter) const;
 
 	Geometry* convexHull() const;
 



More information about the geos-commits mailing list