[geos-commits] [SCM] GEOS branch master updated. 2337c07b0c5146ef0c9a7cd5868fce2fd4c216e9

git at osgeo.org git at osgeo.org
Thu Dec 6 11:53:26 PST 2018


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".

The branch, master has been updated
       via  2337c07b0c5146ef0c9a7cd5868fce2fd4c216e9 (commit)
       via  5d0561939274c5f34cb938e6200427af935c0b20 (commit)
      from  69d08be94284cba13455689cb84a5e1704bc54b5 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 2337c07b0c5146ef0c9a7cd5868fce2fd4c216e9
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Thu Dec 6 11:51:14 2018 -0800

    Complete Densifier port and add in integration XML tests

diff --git a/src/geom/util/Densifier.cpp b/src/geom/util/Densifier.cpp
index 6d66668..832e3f4 100644
--- a/src/geom/util/Densifier.cpp
+++ b/src/geom/util/Densifier.cpp
@@ -111,7 +111,7 @@ Densifier::densifyPoints(const Coordinate::Vect pts, double distanceTolerance, c
 	{
 		seg.p0 = pts[i];
 		seg.p1 = pts[i+1];
-		coordList.insert(it++, seg.p0, false);
+		coordList.insert(coordList.end(), seg.p0, false);
 		double len = seg.getLength();
 		int densifiedSegCount = (int) (len / distanceTolerance) + 1;
 		if (densifiedSegCount > 1)
@@ -123,11 +123,11 @@ Densifier::densifyPoints(const Coordinate::Vect pts, double distanceTolerance, c
 				Coordinate p;
 				seg.pointAlong(segFract, p);
 				precModel->makePrecise(p);
-				coordList.insert(it++, p, false);
+				coordList.insert(coordList.end(), p, false);
 			}
 		}
 	}
-	coordList.insert(it++, pts[pts.size()-1], false);
+	coordList.insert(coordList.end(), pts[pts.size()-1], false);
 	return coordList.toCoordinateArray();
 }
 
diff --git a/tests/xmltester/CMakeLists.txt b/tests/xmltester/CMakeLists.txt
index 2de1ffd..a1c1435 100644
--- a/tests/xmltester/CMakeLists.txt
+++ b/tests/xmltester/CMakeLists.txt
@@ -68,6 +68,7 @@ if(GEOS_ENABLE_TESTS)
     ${XMLTESTS_DIR}/general/TestCentroid.xml
     ${XMLTESTS_DIR}/general/TestConvexHull-big.xml
     ${XMLTESTS_DIR}/general/TestConvexHull.xml
+    ${XMLTESTS_DIR}/general/TestDensify.xml
     ${XMLTESTS_DIR}/general/TestDistance.xml
     ${XMLTESTS_DIR}/general/TestEqualsExact.xml
     ${XMLTESTS_DIR}/general/TestFunctionAA.xml
diff --git a/tests/xmltester/Makefile.am b/tests/xmltester/Makefile.am
index a882f1e..ace4c84 100644
--- a/tests/xmltester/Makefile.am
+++ b/tests/xmltester/Makefile.am
@@ -37,6 +37,7 @@ SAFE_XMLTESTS= \
 	$(srcdir)/tests/general/TestConvexHull-big.xml \
 	$(srcdir)/tests/general/TestConvexHull.xml \
 	$(srcdir)/tests/general/TestDistance.xml \
+	$(srcdir)/tests/general/TestDensify.xml \
 	$(srcdir)/tests/general/TestEqualsExact.xml \
 	$(srcdir)/tests/general/TestFunctionAA.xml \
 	$(srcdir)/tests/general/TestFunctionAAPrec.xml \
diff --git a/tests/xmltester/XMLTester.cpp b/tests/xmltester/XMLTester.cpp
index 60733c0..3bf734a 100644
--- a/tests/xmltester/XMLTester.cpp
+++ b/tests/xmltester/XMLTester.cpp
@@ -35,6 +35,7 @@
 #include <geos/geom/prep/PreparedGeometry.h>
 #include <geos/geom/prep/PreparedGeometryFactory.h>
 #include <geos/geom/BinaryOp.h>
+#include <geos/geom/util/Densifier.h>
 #include <geos/operation/overlay/OverlayOp.h>
 #include <geos/operation/overlay/snap/GeometrySnapper.h>
 #include <geos/operation/buffer/BufferBuilder.h>
@@ -851,6 +852,29 @@ XMLTester::parseTest(const tinyxml2::XMLNode* node)
                 success &= int(testValid(gRealRes.get(), "result"));
         }
 
+        else if (opName=="densify")
+        {
+            geom::Geometry *p_gT = gA;
+
+            GeomPtr gRes(parseGeometry(opRes, "expected"));
+            // gRes->normalize();
+
+            geom::util::Densifier den(p_gT);
+            double distanceTolerance = std::atof(opArg2.c_str());
+            den.setDistanceTolerance(distanceTolerance);
+            GeomPtr gRealRes = den.getResultGeometry();
+
+            // gRealRes->normalize();
+
+            if (gRes->compareTo(gRealRes.get())==0)
+                success=1;
+
+            actual_result=printGeom(gRealRes.get());
+            expected_result=printGeom(gRes.get());
+
+        }
+
+
         else if (opName=="union")
         {
             GeomPtr gRes(parseGeometry(opRes, "expected"));
diff --git a/tests/xmltester/tests/general/TestDensify.xml b/tests/xmltester/tests/general/TestDensify.xml
new file mode 100644
index 0000000..3a8fdfc
--- /dev/null
+++ b/tests/xmltester/tests/general/TestDensify.xml
@@ -0,0 +1,57 @@
+<run>
+  <precisionModel type="FLOATING" />
+
+<case>
+  <desc>P - single point</desc>
+  <a>    POINT (10 10) </a>
+<test><op name="densify" arg1='A'  arg2='10.0'>  POINT (10 10)	</op></test>
+</case>
+
+<case>
+  <desc>mP - multi point</desc>
+  <a>    MULTIPOINT ((10 10), (20 10)) </a>
+<test><op name="densify" arg1='A'  arg2='10.0'>  MULTIPOINT ((10 10), (20 10))	</op></test>
+</case>
+
+<case>
+  <desc>L - single segment</desc>
+  <a>    LINESTRING(10 10, 100 10)  </a>
+<test><op name="densify" arg1='A'  arg2='10.0'>    
+	LINESTRING (10 10, 19 10, 28 10, 37 10, 46 10, 55 10, 64 10, 73 10, 82 10, 91 10, 100 10)   
+	</op></test>
+</case>
+
+<case>
+  <desc>mL - multiple lines</desc>
+  <a>    MULTILINESTRING ((10 10, 30 30, 50 10, 70 30), (10 50, 40 50, 70 50))  </a>
+<test><op name="densify" arg1='A'  arg2='8.0'>    
+	MULTILINESTRING ((10 10, 15 15, 20 20, 25 25, 30 30, 35 25, 40 20, 45 15, 50 10, 55 15, 60 20, 65 25, 70 30), 
+  (10 50, 17.5 50, 25 50, 32.5 50, 40 50, 47.5 50, 55 50, 62.5 50, 70 50))   
+	</op></test>
+</case>
+
+
+<case>
+  <desc>A - polygon with hole</desc>
+  <a>    POLYGON ((0 0, 0 70, 70 70, 70 0, 0 0), (10 10, 10 60, 60 60, 10 10))  </a>
+<test><op name="densify" arg1='A'  arg2='10.0'>    
+POLYGON ((0 0, 0 8.75, 0 17.5, 0 26.25, 0 35, 0 43.75, 0 52.5, 0 61.25, 0 70, 8.75 70, 17.5 70, 26.25 70, 35 70, 43.75 70, 52.5 70, 61.25 70, 70 70, 70 61.25, 70 52.5, 70 43.75, 70 35, 70 26.25, 70 17.5, 70 8.75, 70 0, 61.25 0, 52.5 0, 43.75 0, 35 0, 26.25 0, 17.5 0, 8.75 0, 0 0), 
+  (10 10, 16.25 16.25, 22.5 22.5, 28.75 28.75, 35 35, 41.25 41.25, 47.5 47.5, 53.75 53.75, 60 60, 51.66666666666667 60, 43.333333333333336 60, 35 60, 26.666666666666668 60, 18.333333333333336 60, 10 60, 10 51.66666666666667, 10 43.333333333333336, 10 35, 10 26.666666666666668, 10 18.333333333333336, 10 10))
+  	</op></test>
+</case>
+
+<case>
+  <desc>mA - multipolygon</desc>
+  <a>    MULTIPOLYGON (((0 0, 0 70, 70 70, 70 0, 0 0), 
+  (10 10, 10 60, 60 60, 10 10)), 
+  ((80 110, 80 70, 120 70, 120 110, 80 110)))  </a>
+<test><op name="densify" arg1='A'  arg2='10.0'>    
+MULTIPOLYGON (((80 110, 88 110, 96 110, 104 110, 112 110, 120 110, 120 102, 120 94, 120 86, 120 78, 120 70, 112 70, 104 70, 96 70, 88 70, 80 70, 80 78, 80 86, 80 94, 80 102, 80 110)), 
+  ((0 0, 0 8.75, 0 17.5, 0 26.25, 0 35, 0 43.75, 0 52.5, 0 61.25, 0 70, 8.75 70, 17.5 70, 26.25 70, 35 70, 43.75 70, 52.5 70, 61.25 70, 70 70, 70 61.25, 70 52.5, 70 43.75, 70 35, 70 26.25, 70 17.5, 70 8.75, 70 0, 61.25 0, 52.5 0, 43.75 0, 35 0, 26.25 0, 17.5 0, 8.75 0, 0 0), 
+    (10 10, 16.25 16.25, 22.5 22.5, 28.75 28.75, 35 35, 41.25 41.25, 47.5 47.5, 53.75 53.75, 60 60, 51.66666666666667 60, 43.333333333333336 60, 35 60, 26.666666666666668 60, 18.333333333333336 60, 10 60, 10 51.66666666666667, 10 43.333333333333336, 10 35, 10 26.666666666666668, 10 18.333333333333336, 10 10)))      	</op></test>
+</case>
+
+
+
+
+</run>

commit 5d0561939274c5f34cb938e6200427af935c0b20
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Tue Dec 4 15:47:28 2018 -0800

    Clean build of Densifier code only, tests still TBD

diff --git a/include/geos/geom/util/Densifier.h b/include/geos/geom/util/Densifier.h
new file mode 100644
index 0000000..d93cc3b
--- /dev/null
+++ b/include/geos/geom/util/Densifier.h
@@ -0,0 +1,91 @@
+/**********************************************************************
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.osgeo.org
+ *
+ * Copyright (C) 2010 Sandro Santilli <strk at kbt.io>
+ * Copyright (C) 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.
+ *
+ **********************************************************************
+ *
+ * Last port: operation/polygonize/Polygonizer.java rev. 1.6 (JTS-1.10)
+ *
+ **********************************************************************/
+
+#ifndef GEOS_DENSIFIER_H
+#define GEOS_DENSIFIER_H
+
+#include <geos/export.h>
+#include <geos/geom/Geometry.h>
+#include <geos/geom/util/GeometryTransformer.h>
+#include <geos/geom/util/Densifier.h>
+#include <geos/util/Interrupt.h>
+
+#include <vector>
+
+#ifdef _MSC_VER
+#pragma warning(push)
+/* warning C4251: needs to have dll-interface to be used by */
+/* clients of class */
+#pragma warning(disable: 4251)
+#endif
+
+
+namespace geos {
+namespace geom {
+namespace util {
+
+/**
+ * Densifies a {@link Geometry} by inserting extra vertices along the line segments
+ * contained in the geometry.
+ * All segments in the created densified geometry will be no longer than
+ * than the given distance tolerance.
+ * Densified polygonal geometries are guaranteed to be topologically correct.
+ * The coordinates created during densification respect the input geometry's
+ * {@link PrecisionModel}.
+ * <p>
+ * <b>Note:</b> At some future point this class will
+ * offer a variety of densification strategies.
+ *
+ * @author Martin Davis
+ */
+class GEOS_DLL Densifier {
+public:
+	Densifier(const Geometry *inputGeom);
+
+	Geometry::Ptr densify(const Geometry *geom, double distanceTolerance);
+	void setDistanceTolerance(double distanceTolerance);
+	Geometry::Ptr getResultGeometry() const;
+
+private:
+	double distanceTolerance;
+	const Geometry *inputGeom;
+	static std::unique_ptr<Coordinate::Vect> densifyPoints(const Coordinate::Vect pts, double distanceTolerance, const PrecisionModel *precModel);
+
+	class GEOS_DLL DensifyTransformer: public GeometryTransformer {
+	public:
+		DensifyTransformer(double distanceTolerance);
+		double distanceTolerance;
+		CoordinateSequence::Ptr transformCoordinates(const CoordinateSequence *coords, const Geometry *parent);
+		Geometry::Ptr transformPolygon(const Polygon *geom, const Geometry *parent);
+		Geometry::Ptr transformMultiPolygon(const MultiPolygon *geom, const Geometry *parent);
+		Geometry *createValidArea(const Geometry *roughAreaGeom);
+	};
+
+}; // Densifier
+
+} // namespace geos.geom.util
+} // namespace geos.geom
+} // namespace geos
+
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
+#endif // GEOS_DENSIFIER_H
diff --git a/include/geos/geom/util/Makefile.am b/include/geos/geom/util/Makefile.am
index 847283d..32cdd32 100644
--- a/include/geos/geom/util/Makefile.am
+++ b/include/geos/geom/util/Makefile.am
@@ -1,9 +1,9 @@
 #
-# This file is part of project GEOS (http://trac.osgeo.org/geos/) 
+# This file is part of project GEOS (http://trac.osgeo.org/geos/)
 #
-#SUBDIRS = 
+#SUBDIRS =
 
-#EXTRA_DIST = 
+#EXTRA_DIST =
 
 geosdir = $(includedir)/geos/geom/util
 
@@ -19,4 +19,5 @@ geos_HEADERS = \
     PointExtracter.h \
     PolygonExtracter.h \
     ShortCircuitedGeometryVisitor.h \
-    SineStarFactory.h
+    SineStarFactory.h \
+    Densifier.h
diff --git a/src/geom/util/Densifier.cpp b/src/geom/util/Densifier.cpp
new file mode 100644
index 0000000..6d66668
--- /dev/null
+++ b/src/geom/util/Densifier.cpp
@@ -0,0 +1,168 @@
+/**********************************************************************
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.osgeo.org
+ *
+ * Copyright (C) 2010 Sandro Santilli <strk at kbt.io>
+ * 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.
+ *
+ **********************************************************************
+ *
+ * Last port: operation/polygonize/Polygonizer.java rev. 1.6 (JTS-1.10)
+ *
+ **********************************************************************/
+
+#include <geos/geom/util/Densifier.h>
+#include <geos/geom/CoordinateSequenceFactory.h>
+#include <geos/geom/CoordinateList.h>
+#include <geos/geom/Geometry.h>
+#include <geos/geom/GeometryFactory.h>
+#include <geos/geom/MultiPoint.h>
+#include <geos/geom/MultiPolygon.h>
+#include <geos/geom/MultiLineString.h>
+#include <geos/geom/CoordinateSequence.h>
+#include <geos/geom/CoordinateSequenceFactory.h>
+#include <geos/geom/PrecisionModel.h>
+#include <geos/geom/Polygon.h>
+#include <geos/geom/Point.h>
+#include <geos/geom/LineString.h>
+#include <geos/geom/LinearRing.h>
+#include <geos/geom/LineSegment.h>
+#include <geos/geom/GeometryCollection.h>
+#include <geos/util/Interrupt.h>
+#include <geos/util/IllegalArgumentException.h>
+
+#include <vector>
+
+using namespace geos::geom;
+using namespace geos::geom::util;
+
+namespace geos {
+namespace geom { // geos.geom
+namespace util { // geos.geom.util
+
+/* geom::util::Densifier::DensifyTransformer */
+Densifier::DensifyTransformer::DensifyTransformer(double distanceTolerance):
+	distanceTolerance(distanceTolerance)
+{}
+
+CoordinateSequence::Ptr
+Densifier::DensifyTransformer::transformCoordinates(const CoordinateSequence *coords, const Geometry *parent)
+{
+	Coordinate::Vect emptyPts;
+	Coordinate::Vect inputPts;
+	coords->toVector(inputPts);
+	std::unique_ptr<Coordinate::Vect> newPts = Densifier::densifyPoints(inputPts, distanceTolerance, parent->getPrecisionModel());
+	if (const LineString* ls=dynamic_cast<const LineString*>(parent))
+	{
+		if (ls->getNumPoints() <= 1)
+			newPts->clear();
+	}
+	CoordinateSequence::Ptr csp(factory->getCoordinateSequenceFactory()->create(newPts.release()));
+	return csp;
+}
+
+Geometry::Ptr
+Densifier::DensifyTransformer::transformPolygon(const Polygon *geom, const Geometry *parent)
+{
+	Geometry::Ptr roughGeom = GeometryTransformer::transformPolygon(geom, parent);
+	// don't try and correct if the parent is going to do this
+	if (const MultiPolygon* mp=dynamic_cast<const MultiPolygon*>(parent) )
+	{
+		return roughGeom;
+	}
+	Geometry::Ptr validGeom(createValidArea(roughGeom.get()));
+	return validGeom;
+}
+
+Geometry::Ptr
+Densifier::DensifyTransformer::transformMultiPolygon(const MultiPolygon *geom, const Geometry *parent)
+{
+	Geometry::Ptr roughGeom = GeometryTransformer::transformMultiPolygon(geom, parent);
+	Geometry::Ptr validGeom(createValidArea(roughGeom.get()));
+	return validGeom;
+}
+
+Geometry *
+Densifier::DensifyTransformer::createValidArea(const Geometry *roughAreaGeom)
+{
+	return roughAreaGeom->buffer(0.0);
+}
+
+/* util::Densifier */
+
+Densifier::Densifier(const Geometry *geom):
+	inputGeom(geom)
+{}
+
+std::unique_ptr<Coordinate::Vect>
+Densifier::densifyPoints(const Coordinate::Vect pts, double distanceTolerance, const PrecisionModel *precModel)
+{
+	geom::LineSegment seg;
+	geom::CoordinateList coordList;
+	geom::CoordinateList::iterator it = coordList.begin();
+	for (int i = 0; i < pts.size()-1; i++)
+	{
+		seg.p0 = pts[i];
+		seg.p1 = pts[i+1];
+		coordList.insert(it++, seg.p0, false);
+		double len = seg.getLength();
+		int densifiedSegCount = (int) (len / distanceTolerance) + 1;
+		if (densifiedSegCount > 1)
+		{
+			double densifiedSegLen = len / densifiedSegCount;
+			for (int j = 1; j < densifiedSegCount; j++)
+			{
+				double segFract = (j * densifiedSegLen) / len;
+				Coordinate p;
+				seg.pointAlong(segFract, p);
+				precModel->makePrecise(p);
+				coordList.insert(it++, p, false);
+			}
+		}
+	}
+	coordList.insert(it++, pts[pts.size()-1], false);
+	return coordList.toCoordinateArray();
+}
+
+/**
+ * Densifies a geometry using a given distance tolerance,
+ * and respecting the input geometry's {@link PrecisionModel}.
+ *
+ * @param geom the geometry to densify
+ * @param distanceTolerance the distance tolerance to densify
+ * @return the densified geometry
+ */
+Geometry::Ptr
+Densifier::densify(const Geometry *geom, double distanceTolerance)
+{
+	util::Densifier densifier(geom);
+	densifier.setDistanceTolerance(distanceTolerance);
+	return densifier.getResultGeometry();
+}
+
+void
+Densifier::setDistanceTolerance(double tol)
+{
+	if (tol <= 0.0)
+		throw geos::util::IllegalArgumentException("Tolerance must be positive");
+	distanceTolerance = tol;
+}
+
+Geometry::Ptr
+Densifier::getResultGeometry() const
+{
+	DensifyTransformer dt(distanceTolerance);
+	return dt.transform(inputGeom);
+}
+
+
+} // namespace geos.geom.util
+} // namespace geos.geom
+} // namespace geos
diff --git a/src/geom/util/Makefile.am b/src/geom/util/Makefile.am
index 54c854a..f05171a 100644
--- a/src/geom/util/Makefile.am
+++ b/src/geom/util/Makefile.am
@@ -1,9 +1,9 @@
 #
-# This file is part of project GEOS (http://trac.osgeo.org/geos/) 
+# This file is part of project GEOS (http://trac.osgeo.org/geos/)
 #
 noinst_LTLIBRARIES = libgeomutil.la
 
-AM_CPPFLAGS = -I$(top_srcdir)/include 
+AM_CPPFLAGS = -I$(top_srcdir)/include
 
 libgeomutil_la_SOURCES = \
     ComponentCoordinateExtracter.cpp \
@@ -15,4 +15,5 @@ libgeomutil_la_SOURCES = \
     GeometryCombiner.cpp \
     LinearComponentExtracter.cpp \
     PointExtracter.cpp \
-    PolygonExtracter.cpp
+    PolygonExtracter.cpp \
+    Densifier.cpp

-----------------------------------------------------------------------

Summary of changes:
 include/geos/geom/util/Densifier.h            |  91 ++++++++++++++
 include/geos/geom/util/Makefile.am            |   9 +-
 src/geom/util/Densifier.cpp                   | 168 ++++++++++++++++++++++++++
 src/geom/util/Makefile.am                     |   7 +-
 tests/xmltester/CMakeLists.txt                |   1 +
 tests/xmltester/Makefile.am                   |   1 +
 tests/xmltester/XMLTester.cpp                 |  24 ++++
 tests/xmltester/tests/general/TestDensify.xml |  57 +++++++++
 8 files changed, 351 insertions(+), 7 deletions(-)
 create mode 100644 include/geos/geom/util/Densifier.h
 create mode 100644 src/geom/util/Densifier.cpp
 create mode 100644 tests/xmltester/tests/general/TestDensify.xml


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list