[geos-commits] r2990 - in trunk: include/geos/geom include/geos/io src/geom src/io tests/unit/noding

svn_geos at osgeo.org svn_geos at osgeo.org
Tue May 18 15:18:54 EDT 2010


Author: warmerdam
Date: 2010-05-18 15:18:54 -0400 (Tue, 18 May 2010)
New Revision: 2990

Modified:
   trunk/include/geos/geom/CoordinateArraySequence.h
   trunk/include/geos/geom/CoordinateArraySequenceFactory.inl
   trunk/include/geos/geom/CoordinateSequenceFactory.h
   trunk/include/geos/io/WKTReader.h
   trunk/src/geom/CoordinateArraySequence.cpp
   trunk/src/geom/GeometryFactory.cpp
   trunk/src/io/WKTReader.cpp
   trunk/tests/unit/noding/BasicSegmentStringTest.cpp
   trunk/tests/unit/noding/NodedSegmentStringTest.cpp
Log:
preserve dimension as part of CoordinateArraySequence and while reading WKT (#345)

Modified: trunk/include/geos/geom/CoordinateArraySequence.h
===================================================================
--- trunk/include/geos/geom/CoordinateArraySequence.h	2010-05-15 12:47:00 UTC (rev 2989)
+++ trunk/include/geos/geom/CoordinateArraySequence.h	2010-05-18 19:18:54 UTC (rev 2990)
@@ -38,7 +38,7 @@
 class GEOS_DLL CoordinateArraySequence : public CoordinateSequence {
 public:
 
-	CoordinateArraySequence(const CoordinateArraySequence &cl);
+        CoordinateArraySequence(const CoordinateArraySequence &cl);
 
 	CoordinateSequence *clone() const;
 
@@ -61,10 +61,11 @@
 	CoordinateArraySequence();
 
 	/// Construct sequence taking ownership of given Coordinate vector
-	CoordinateArraySequence(std::vector<Coordinate> *coords);
-
+	CoordinateArraySequence(std::vector<Coordinate> *coords,
+                                std::size_t dimension = 3);
+        
 	/// Construct sequence allocating space for n coordinates
-	CoordinateArraySequence(std::size_t n);
+	CoordinateArraySequence(std::size_t n, std::size_t dimension = 3);
 
 	~CoordinateArraySequence();
 
@@ -108,7 +109,7 @@
 
 	void expandEnvelope(Envelope &env) const;
 
-	size_t getDimension() const { return 3; }
+        std::size_t getDimension() const { return dimension; }
 
 	void apply_rw(const CoordinateFilter *filter); 
 
@@ -118,6 +119,7 @@
 
 private:
 	std::vector<Coordinate> *vect;
+        std::size_t dimension;
 };
 
 /// This is for backward API compatibility

Modified: trunk/include/geos/geom/CoordinateArraySequenceFactory.inl
===================================================================
--- trunk/include/geos/geom/CoordinateArraySequenceFactory.inl	2010-05-15 12:47:00 UTC (rev 2989)
+++ trunk/include/geos/geom/CoordinateArraySequenceFactory.inl	2010-05-18 19:18:54 UTC (rev 2990)
@@ -26,22 +26,21 @@
 INLINE CoordinateSequence*
 CoordinateArraySequenceFactory::create(std::vector<Coordinate> *coords) const
 {
-	return new CoordinateArraySequence(coords);
+	return new CoordinateArraySequence(coords,3);
 }
 
 INLINE CoordinateSequence *
 CoordinateArraySequenceFactory::create(std::vector<Coordinate> *coords,
-		size_t /* dimension */) const
+		size_t dimension ) const
 {
-	return new CoordinateArraySequence(coords);
+	return new CoordinateArraySequence(coords,dimension);
 }
 
 INLINE CoordinateSequence *
-CoordinateArraySequenceFactory::create(std::size_t size, std::size_t /* dimension */)
+CoordinateArraySequenceFactory::create(std::size_t size, std::size_t dimension)
 		const
 {
-	/* CoordinateArraySequence only accepts 3d Coordinates */
-	return new CoordinateArraySequence(size);
+	return new CoordinateArraySequence(size,dimension);
 }
 
 

Modified: trunk/include/geos/geom/CoordinateSequenceFactory.h
===================================================================
--- trunk/include/geos/geom/CoordinateSequenceFactory.h	2010-05-15 12:47:00 UTC (rev 2989)
+++ trunk/include/geos/geom/CoordinateSequenceFactory.h	2010-05-18 19:18:54 UTC (rev 2990)
@@ -63,7 +63,8 @@
 	 * @param coordinates the coordinates
 	 */
 	virtual CoordinateSequence *create(
-			std::vector<Coordinate> *coordinates) const=0;
+            std::vector<Coordinate> *coordinates,
+            std::size_t dimension=3 ) const=0;
 
 	/** \brief
 	 * Creates a CoordinateSequence of the specified size and dimension.
@@ -76,7 +77,7 @@
 	 * 	(if user-specifiable, otherwise ignored)
 	 */
 	virtual CoordinateSequence *create(std::size_t size,
-			size_t dimension) const=0;
+                                           std::size_t dimension) const=0;
 
 	virtual ~CoordinateSequenceFactory();
 };

Modified: trunk/include/geos/io/WKTReader.h
===================================================================
--- trunk/include/geos/io/WKTReader.h	2010-05-15 12:47:00 UTC (rev 2989)
+++ trunk/include/geos/io/WKTReader.h	2010-05-18 19:18:54 UTC (rev 2990)
@@ -103,7 +103,7 @@
 	const geom::GeometryFactory *geometryFactory;
 	const geom::PrecisionModel *precisionModel;
 
-	void getPreciseCoordinate(io::StringTokenizer *tokenizer, geom::Coordinate&);
+	void getPreciseCoordinate(io::StringTokenizer *tokenizer, geom::Coordinate&, std::size_t &dim );
 
 	bool isNumberNext(io::StringTokenizer *tokenizer);
 };

Modified: trunk/src/geom/CoordinateArraySequence.cpp
===================================================================
--- trunk/src/geom/CoordinateArraySequence.cpp	2010-05-15 12:47:00 UTC (rev 2989)
+++ trunk/src/geom/CoordinateArraySequence.cpp	2010-05-18 19:18:54 UTC (rev 2990)
@@ -31,26 +31,31 @@
 namespace geom { // geos::geom
 
 CoordinateArraySequence::CoordinateArraySequence():
-	vect(new vector<Coordinate>())
+	vect(new vector<Coordinate>()),
+        dimension(3)
 {
 }
 
-CoordinateArraySequence::CoordinateArraySequence(size_t n):
-	vect(new vector<Coordinate>(n))
+CoordinateArraySequence::CoordinateArraySequence(size_t n, 
+                                                 size_t dimension_in ):
+	vect(new vector<Coordinate>(n)),
+        dimension(dimension_in)
 {
 }
 
 CoordinateArraySequence::CoordinateArraySequence(
-	vector<Coordinate> *coords): vect(coords)
+    vector<Coordinate> *coords, size_t dimension_in )
+        : vect(coords), dimension(dimension_in)
 {
 	if ( ! vect ) vect = new vector<Coordinate>();
 }
 
 CoordinateArraySequence::CoordinateArraySequence(
-	const CoordinateArraySequence &c)
+    const CoordinateArraySequence &c )
 	:
 	CoordinateSequence(c),
-	vect(new vector<Coordinate>(*(c.vect)))
+	vect(new vector<Coordinate>(*(c.vect))),
+        dimension(c.getDimension())
 {
 }
 

Modified: trunk/src/geom/GeometryFactory.cpp
===================================================================
--- trunk/src/geom/GeometryFactory.cpp	2010-05-15 12:47:00 UTC (rev 2989)
+++ trunk/src/geom/GeometryFactory.cpp	2010-05-18 19:18:54 UTC (rev 2990)
@@ -235,7 +235,8 @@
 	if (coordinate.isNull()) {
 		return createPoint();
 	} else {
-		CoordinateSequence *cl=coordinateListFactory->create(new vector<Coordinate>(1, coordinate));
+		std::size_t dim = ISNAN(coordinate.z) ? 2 : 3;
+		CoordinateSequence *cl = coordinateListFactory->create(new vector<Coordinate>(1, coordinate), dim);
 		//cl->setAt(coordinate, 0);
 		Point *ret = createPoint(cl);
 		return ret;

Modified: trunk/src/io/WKTReader.cpp
===================================================================
--- trunk/src/io/WKTReader.cpp	2010-05-15 12:47:00 UTC (rev 2989)
+++ trunk/src/io/WKTReader.cpp	2010-05-18 19:18:54 UTC (rev 2990)
@@ -72,20 +72,23 @@
 CoordinateSequence*
 WKTReader::getCoordinates(StringTokenizer *tokenizer)
 {
+	size_t dim;
 	string nextToken=getNextEmptyOrOpener(tokenizer);
 	if (nextToken=="EMPTY") {
 		return geometryFactory->getCoordinateSequenceFactory()->create(NULL);
 		//new CoordinateArraySequence(); 
 	}
+
+	Coordinate coord;
+	getPreciseCoordinate(tokenizer, coord, dim);
+
 	CoordinateSequence *coordinates = \
-		geometryFactory->getCoordinateSequenceFactory()->create(NULL);
-	Coordinate coord;
-	getPreciseCoordinate(tokenizer, coord);
+            geometryFactory->getCoordinateSequenceFactory()->create((size_t)0,dim);
 	coordinates->add(coord);
 	try {
 		nextToken=getNextCloserOrComma(tokenizer);
 		while (nextToken==",") {
-			getPreciseCoordinate(tokenizer, coord);
+			getPreciseCoordinate(tokenizer, coord, dim );
 			coordinates->add(coord);
 			nextToken=getNextCloserOrComma(tokenizer);
 		}
@@ -93,18 +96,23 @@
 		delete coordinates;
 		throw;
 	}
+
 	return coordinates;
 }
 
 void
-WKTReader::getPreciseCoordinate(StringTokenizer *tokenizer, Coordinate& coord)
+WKTReader::getPreciseCoordinate(StringTokenizer *tokenizer, 
+                                Coordinate& coord,
+                                size_t &dim )
 {
 	coord.x=getNextNumber(tokenizer);
 	coord.y=getNextNumber(tokenizer);
 	if (isNumberNext(tokenizer)) {
 		coord.z=getNextNumber(tokenizer);
+		dim = 3;
 	} else {
 		coord.z=DoubleNotANumber;
+		dim = 2;
 	}
 	precisionModel->makePrecise(coord);
 }
@@ -221,13 +229,14 @@
 Point*
 WKTReader::readPointText(StringTokenizer *tokenizer)
 {
+	size_t dim;
 	string nextToken=getNextEmptyOrOpener(tokenizer);
 	if (nextToken=="EMPTY") {
 		return geometryFactory->createPoint(Coordinate::getNull());
 	}
 
 	Coordinate coord;
-	getPreciseCoordinate(tokenizer, coord);
+	getPreciseCoordinate(tokenizer, coord, dim);
 	getNextCloser(tokenizer);
 
 	return geometryFactory->createPoint(coord);
@@ -258,6 +267,8 @@
 
 	if ( tok == StringTokenizer::TT_NUMBER )
 	{
+		size_t dim;
+
 		// Try to parse deprecated form "MULTIPOINT(0 0, 1 1)"
 		const CoordinateSequenceFactory* csf = \
 			geometryFactory->getCoordinateSequenceFactory();
@@ -265,7 +276,7 @@
 		try {
 			do {
 				Coordinate coord;
-				getPreciseCoordinate(tokenizer, coord);
+				getPreciseCoordinate(tokenizer, coord, dim);
 				coords->add(coord);
 				nextToken=getNextCloserOrComma(tokenizer);
 			} while(nextToken == ",");

Modified: trunk/tests/unit/noding/BasicSegmentStringTest.cpp
===================================================================
--- trunk/tests/unit/noding/BasicSegmentStringTest.cpp	2010-05-15 12:47:00 UTC (rev 2989)
+++ trunk/tests/unit/noding/BasicSegmentStringTest.cpp	2010-05-18 19:18:54 UTC (rev 2990)
@@ -64,7 +64,7 @@
     template<>
     void object::test<1>()
     {
-    	CoordinateSequenceAutoPtr cs(csFactory->create(0, 2));
+    	CoordinateSequenceAutoPtr cs(csFactory->create((size_t)0, 2));
 
 	ensure(0 != cs.get());
 
@@ -107,7 +107,7 @@
     template<>
     void object::test<2>()
     {
-    	CoordinateSequenceAutoPtr cs(csFactory->create(0, 2));
+    	CoordinateSequenceAutoPtr cs(csFactory->create((size_t)0, 2));
 
 	ensure(0 != cs.get());
 
@@ -143,7 +143,7 @@
     template<>
     void object::test<3>()
     {
-    	CoordinateSequenceAutoPtr cs(csFactory->create(0, 2));
+    	CoordinateSequenceAutoPtr cs(csFactory->create((size_t)0, 2));
 
 	ensure(0 != cs.get());
 

Modified: trunk/tests/unit/noding/NodedSegmentStringTest.cpp
===================================================================
--- trunk/tests/unit/noding/NodedSegmentStringTest.cpp	2010-05-15 12:47:00 UTC (rev 2989)
+++ trunk/tests/unit/noding/NodedSegmentStringTest.cpp	2010-05-18 19:18:54 UTC (rev 2990)
@@ -64,7 +64,7 @@
     template<>
     void object::test<1>()
     {
-        CoordinateSequenceAutoPtr cs(csFactory->create(0, 2));
+        CoordinateSequenceAutoPtr cs(csFactory->create((size_t)0, 2));
 
         ensure(0 != cs.get());
 
@@ -111,7 +111,7 @@
     template<>
     void object::test<2>()
     {
-        CoordinateSequenceAutoPtr cs(csFactory->create(0, 2));
+        CoordinateSequenceAutoPtr cs(csFactory->create((size_t)0, 2));
 
     ensure(0 != cs.get());
 
@@ -148,7 +148,7 @@
     template<>
     void object::test<3>()
     {
-        CoordinateSequenceAutoPtr cs(csFactory->create(0, 2));
+        CoordinateSequenceAutoPtr cs(csFactory->create((size_t)0, 2));
 
     ensure(0 != cs.get());
 
@@ -221,7 +221,7 @@
         geos::geom::Coordinate p1(10, 0);
 
 
-        CoordinateSequenceAutoPtr cs(csFactory->create(0, 2));
+        CoordinateSequenceAutoPtr cs(csFactory->create((size_t)0, 2));
         cs->add(p0);
         cs->add(p1);
 



More information about the geos-commits mailing list