[geos-commits] [SCM] GEOS branch 3.11 updated. c3d027aae5674979cd50e5b9c77c0add5148b253

git at osgeo.org git at osgeo.org
Wed May 17 16:43:33 PDT 2023


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, 3.11 has been updated
       via  c3d027aae5674979cd50e5b9c77c0add5148b253 (commit)
      from  0cd873b504579449cc75564bf92d6587b6d99b1d (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 c3d027aae5674979cd50e5b9c77c0add5148b253
Author: Mike Taves <mwtoews at gmail.com>
Date:   Mon May 15 22:31:16 2023 +1200

    GeoJSONReader: Fix 2D empty geometry creation

diff --git a/NEWS.md b/NEWS.md
index 984bc3bd2..81a8ec789 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -7,6 +7,7 @@
   - LargestEmptyCircle: enhance boundary to allow any polygonal geometry (GH-859, Martin Davis)
   - Build issues with RH (GH-860)
   - OffsetCurve: fix EndCap parameter handling (GH-899, Martin Davis)
+  - GeoJSONReader: Fix 2D empty geometry creation (GH-910, Mike Taves)
 
 ## Changes in 3.11.2
 2023-03-16
diff --git a/src/io/GeoJSONReader.cpp b/src/io/GeoJSONReader.cpp
index 4733bbe4d..72849c790 100644
--- a/src/io/GeoJSONReader.cpp
+++ b/src/io/GeoJSONReader.cpp
@@ -240,7 +240,7 @@ std::unique_ptr<geom::LineString> GeoJSONReader::readLineString(
         const geom::Coordinate& c = readCoordinate(coord);
         coordinates.push_back(c);
     }
-    auto coordinateSequence = geometryFactory.getCoordinateSequenceFactory()->create(std::move(coordinates));
+    auto coordinateSequence = geometryFactory.getCoordinateSequenceFactory()->create(std::move(coordinates), 2u);
     return geometryFactory.createLineString(std::move(coordinateSequence));
 }
 
@@ -264,7 +264,7 @@ std::unique_ptr<geom::Polygon> GeoJSONReader::readPolygon(
             const geom::Coordinate& c = readCoordinate(coord);
             coordinates.push_back(c);
         }
-        auto coordinateSequence = geometryFactory.getCoordinateSequenceFactory()->create(std::move(coordinates));
+        auto coordinateSequence = geometryFactory.getCoordinateSequenceFactory()->create(std::move(coordinates), 2u);
         if (!shell) {
             shell = geometryFactory.createLinearRing(std::move(coordinateSequence));
         }
@@ -309,7 +309,7 @@ std::unique_ptr<geom::MultiLineString> GeoJSONReader::readMultiLineString(
             const geom::Coordinate& c = readCoordinate(coord);
             coordinates.push_back(geom::Coordinate{c.x, c.y});
         }
-        auto coordinateSequence = geometryFactory.getCoordinateSequenceFactory()->create(std::move(coordinates));
+        auto coordinateSequence = geometryFactory.getCoordinateSequenceFactory()->create(std::move(coordinates), 2u);
         lines.push_back(geometryFactory.createLineString(std::move(coordinateSequence)));
     }
     return geometryFactory.createMultiLineString(std::move(lines));
diff --git a/tests/unit/io/GeoJSONReaderTest.cpp b/tests/unit/io/GeoJSONReaderTest.cpp
index 0ebd08f2b..3ac500c08 100644
--- a/tests/unit/io/GeoJSONReaderTest.cpp
+++ b/tests/unit/io/GeoJSONReaderTest.cpp
@@ -54,6 +54,7 @@ void object::test<1>
     std::string geojson { "{\"type\":\"Point\",\"coordinates\":[-117.0,33.0]}" };
     GeomPtr geom(geojsonreader.read(geojson));
     ensure_equals("POINT (-117.000 33.000)", geom->toText());
+    ensure_equals(static_cast<size_t>(geom->getCoordinateDimension()), 2u);
 }
 
 // Read a GeoJSON LineString
@@ -65,6 +66,7 @@ void object::test<2>
     std::string geojson { "{\"type\":\"LineString\",\"coordinates\":[[102.0,0.0],[103.0,1.0],[104.0,0.0],[105.0,1.0]]}" };
     GeomPtr geom(geojsonreader.read(geojson));
     ensure_equals("LINESTRING (102.000 0.000, 103.000 1.000, 104.000 0.000, 105.000 1.000)", geom->toText());
+    ensure_equals(static_cast<size_t>(geom->getCoordinateDimension()), 2u);
 }
 
 // Read a GeoJSON Polygon with only an outer ring
@@ -76,6 +78,7 @@ void object::test<3>
     std::string geojson { "{\"type\":\"Polygon\",\"coordinates\":[[[30,10],[40,40],[20,40],[10,20],[30,10]]]}" };
     GeomPtr geom(geojsonreader.read(geojson));
     ensure_equals("POLYGON ((30.000 10.000, 40.000 40.000, 20.000 40.000, 10.000 20.000, 30.000 10.000))", geom->toText());
+    ensure_equals(static_cast<size_t>(geom->getCoordinateDimension()), 2u);
 }
 
 // Read a GeoJSON Point with an outer ring and an inner ring
@@ -87,6 +90,7 @@ void object::test<4>
     std::string geojson { "{\"type\":\"Polygon\",\"coordinates\":[[[35,10],[45,45],[15,40],[10,20],[35,10]],[[20,30],[35,35],[30,20],[20,30]]]}" };
     GeomPtr geom(geojsonreader.read(geojson));
     ensure_equals("POLYGON ((35.000 10.000, 45.000 45.000, 15.000 40.000, 10.000 20.000, 35.000 10.000), (20.000 30.000, 35.000 35.000, 30.000 20.000, 20.000 30.000))", geom->toText());
+    ensure_equals(static_cast<size_t>(geom->getCoordinateDimension()), 2u);
 }
 
 // Read a GeoJSON MultiPoint
@@ -98,6 +102,7 @@ void object::test<5>
     std::string geojson { "{\"type\":\"MultiPoint\",\"coordinates\":[[10, 40], [40, 30], [20, 20], [30, 10]]}" };
     GeomPtr geom(geojsonreader.read(geojson));
     ensure_equals("MULTIPOINT (10.000 40.000, 40.000 30.000, 20.000 20.000, 30.000 10.000)", geom->toText());
+    ensure_equals(static_cast<size_t>(geom->getCoordinateDimension()), 2u);
 }
 
 // Read a GeoJSON MultiLineString
@@ -109,6 +114,7 @@ void object::test<6>
     std::string geojson { "{\"type\":\"MultiLineString\",\"coordinates\":[[[10, 10], [20, 20], [10, 40]],[[40, 40], [30, 30], [40, 20], [30, 10]]]}" };
     GeomPtr geom(geojsonreader.read(geojson));
     ensure_equals("MULTILINESTRING ((10.000 10.000, 20.000 20.000, 10.000 40.000), (40.000 40.000, 30.000 30.000, 40.000 20.000, 30.000 10.000))", geom->toText());
+    ensure_equals(static_cast<size_t>(geom->getCoordinateDimension()), 2u);
 }
 
 // Read a GeoJSON MultiPolygon
@@ -120,6 +126,7 @@ void object::test<7>
     std::string geojson { "{\"type\": \"MultiPolygon\", \"coordinates\": [[[[40, 40], [20, 45], [45, 30], [40, 40]]], [[[20, 35], [10, 30], [10, 10], [30, 5], [45, 20], [20, 35]], [[30, 20], [20, 15], [20, 25], [30, 20]]]]}" };
     GeomPtr geom(geojsonreader.read(geojson));
     ensure_equals("MULTIPOLYGON (((40.000 40.000, 20.000 45.000, 45.000 30.000, 40.000 40.000)), ((20.000 35.000, 10.000 30.000, 10.000 10.000, 30.000 5.000, 45.000 20.000, 20.000 35.000), (30.000 20.000, 20.000 15.000, 20.000 25.000, 30.000 20.000)))", geom->toText());
+    ensure_equals(static_cast<size_t>(geom->getCoordinateDimension()), 2u);
 }
 
 // Read a GeoJSON GeometryCollection
@@ -131,6 +138,7 @@ void object::test<8>
     std::string geojson { "{\"type\": \"GeometryCollection\",\"geometries\": [{\"type\": \"Point\",\"coordinates\": [40, 10]},{\"type\": \"LineString\",\"coordinates\": [[10, 10], [20, 20], [10, 40]]},{\"type\": \"Polygon\",\"coordinates\": [[[40, 40], [20, 45], [45, 30], [40, 40]]]}]}" };
     GeomPtr geom(geojsonreader.read(geojson));
     ensure_equals("GEOMETRYCOLLECTION (POINT (40.000 10.000), LINESTRING (10.000 10.000, 20.000 20.000, 10.000 40.000), POLYGON ((40.000 40.000, 20.000 45.000, 45.000 30.000, 40.000 40.000)))", geom->toText());
+    ensure_equals(static_cast<size_t>(geom->getCoordinateDimension()), 2u);
 }
 
 // Read a GeoJSON Feature with a Point and no properties
@@ -142,7 +150,7 @@ void object::test<9>
     std::string geojson { "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-117.0,33.0]}}" };
     GeomPtr geom(geojsonreader.read(geojson));
     ensure_equals("POINT (-117.000 33.000)", geom->toText());
-
+    ensure_equals(static_cast<size_t>(geom->getCoordinateDimension()), 2u);
 }
 
 // Read a GeoJSON FeatureCollection with two Feature with Points and no properties
@@ -154,7 +162,7 @@ void object::test<10>
     std::string geojson { "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-117.0,33.0]}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-122.0,45.0]}}]}" };
     GeomPtr geom(geojsonreader.read(geojson));
     ensure_equals("GEOMETRYCOLLECTION (POINT (-117.000 33.000), POINT (-122.000 45.000))", geom->toText());
-
+    ensure_equals(static_cast<size_t>(geom->getCoordinateDimension()), 2u);
 }
 
 // Read a GeoJSON empty Point
@@ -166,6 +174,7 @@ void object::test<11>
     std::string geojson { "{\"type\":\"Point\",\"coordinates\":[]}" };
     GeomPtr geom(geojsonreader.read(geojson));
     ensure_equals("POINT EMPTY", geom->toText());
+    ensure_equals(static_cast<size_t>(geom->getCoordinateDimension()), 2u);
 }
 
 // Read a GeoJSON empty LineString
@@ -177,6 +186,7 @@ void object::test<12>
     std::string geojson { "{\"type\":\"LineString\",\"coordinates\":[]}" };
     GeomPtr geom(geojsonreader.read(geojson));
     ensure_equals("LINESTRING EMPTY", geom->toText());
+    ensure_equals(static_cast<size_t>(geom->getCoordinateDimension()), 2u);
 }
 
 // Read a GeoJSON empty Polygon
@@ -188,6 +198,7 @@ void object::test<13>
     std::string geojson { "{\"type\":\"Polygon\",\"coordinates\":[]}" };
     GeomPtr geom(geojsonreader.read(geojson));
     ensure_equals("POLYGON EMPTY", geom->toText());
+    ensure_equals(static_cast<size_t>(geom->getCoordinateDimension()), 2u);
 }
 
 // Read a GeoJSON empty MultiPoint
@@ -199,6 +210,7 @@ void object::test<14>
     std::string geojson { "{\"type\":\"MultiPoint\",\"coordinates\":[]}" };
     GeomPtr geom(geojsonreader.read(geojson));
     ensure_equals("MULTIPOINT EMPTY", geom->toText());
+    ensure_equals(static_cast<size_t>(geom->getCoordinateDimension()), 2u);
 }
 
 // Read a GeoJSON empty MultiLineString
@@ -210,6 +222,7 @@ void object::test<15>
     std::string geojson { "{\"type\":\"MultiLineString\",\"coordinates\":[]}" };
     GeomPtr geom(geojsonreader.read(geojson));
     ensure_equals("MULTILINESTRING EMPTY", geom->toText());
+    ensure_equals(static_cast<size_t>(geom->getCoordinateDimension()), 2u);
 }
 
 // Read a GeoJSON empty MultiPolygon
@@ -221,6 +234,7 @@ void object::test<16>
     std::string geojson { "{\"type\": \"MultiPolygon\", \"coordinates\": []}" };
     GeomPtr geom(geojsonreader.read(geojson));
     ensure_equals("MULTIPOLYGON EMPTY", geom->toText());
+    ensure_equals(static_cast<size_t>(geom->getCoordinateDimension()), 2u);
 }
 
 // Read an empty GeometryCollection
@@ -232,6 +246,7 @@ void object::test<17>
     std::string geojson { "{\"type\": \"GeometryCollection\",\"geometries\": []}" };
     GeomPtr geom(geojsonreader.read(geojson));
     ensure_equals("GEOMETRYCOLLECTION EMPTY", geom->toText());
+    ensure_equals(static_cast<size_t>(geom->getCoordinateDimension()), 2u);
 }
 
 // Read a Simple Feature
@@ -243,6 +258,7 @@ void object::test<18>
     std::string geojson { "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-117.0,33.0]}, \"properties\": {\"id\": 1, \"name\": \"one\", \"required\": true} }" };
     geos::io::GeoJSONFeatureCollection features(geojsonreader.readFeatures(geojson));
     ensure_equals(static_cast<size_t>(1), features.getFeatures().size());
+    ensure_equals(static_cast<size_t>(features.getFeatures()[0].getGeometry()->getCoordinateDimension()), 2u);
     ensure_equals("POINT (-117.000 33.000)", features.getFeatures()[0].getGeometry()->toText());
     ensure_equals(1.0, features.getFeatures()[0].getProperties().at("id").getNumber());
     ensure_equals("one", features.getFeatures()[0].getProperties().at("name").getString());
@@ -258,6 +274,7 @@ void object::test<19>
     std::string geojson { "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-117.0,33.0]}, \"properties\": {\"id\": 1, \"name\": \"one\", \"items\": [1,2,3,4], \"nested\": {\"id\":2, \"name\":\"two\"}}}" };
     geos::io::GeoJSONFeatureCollection features(geojsonreader.readFeatures(geojson));
     ensure_equals(static_cast<size_t>(1), features.getFeatures().size());
+    ensure_equals(static_cast<size_t>(features.getFeatures()[0].getGeometry()->getCoordinateDimension()), 2u);
     ensure_equals("POINT (-117.000 33.000)", features.getFeatures()[0].getGeometry()->toText());
     ensure_equals(1.0, features.getFeatures()[0].getProperties().at("id").getNumber());
     ensure_equals("one", features.getFeatures()[0].getProperties().at("name").getString());
@@ -282,6 +299,7 @@ void object::test<20>
      "]}" };
     geos::io::GeoJSONFeatureCollection features(geojsonreader.readFeatures(geojson));
     ensure_equals(static_cast<size_t>(3), features.getFeatures().size());
+    ensure_equals(static_cast<size_t>(features.getFeatures()[0].getGeometry()->getCoordinateDimension()), 2u);
     ensure_equals("POLYGON ((87.890 64.923, 76.992 55.178, 102.656 46.558, 115.312 60.413, 94.570 58.447, 87.890 64.923))", features.getFeatures()[0].getGeometry()->toText());
     ensure_equals(1.0, features.getFeatures()[0].getProperties().at("id").getNumber());
     ensure_equals("LINESTRING (1.406 48.690, 41.835 34.016, 22.500 13.923)", features.getFeatures()[1].getGeometry()->toText());
@@ -299,6 +317,7 @@ void object::test<21>
     std::string geojson { "{\"type\":\"Polygon\",\"coordinates\":[[]]}" };
     GeomPtr geom(geojsonreader.read(geojson));
     ensure_equals("POLYGON EMPTY", geom->toText());
+    ensure_equals(static_cast<size_t>(geom->getCoordinateDimension()), 2u);
 }
 
 // Read a GeoJSON Point with only one coordinate
@@ -405,6 +424,7 @@ void object::test<27>
     std::string geojson { "{\"type\":\"Polygon\",\"coordinates\":[[],[]]}" };
     GeomPtr geom(geojsonreader.read(geojson));
     ensure_equals("POLYGON EMPTY", geom->toText());
+    ensure_equals(static_cast<size_t>(geom->getCoordinateDimension()), 2u);
 }
 
 // Read a GeoJSON empty MultiLineString with empty LineStrings
@@ -416,6 +436,7 @@ void object::test<28>
     std::string geojson { "{\"type\":\"MultiLineString\",\"coordinates\":[[],[],[]]}" };
     GeomPtr geom(geojsonreader.read(geojson));
     ensure_equals("MULTILINESTRING EMPTY", geom->toText());
+    ensure_equals(static_cast<size_t>(geom->getCoordinateDimension()), 2u);
 }
 
 // Read a GeoJSON Point with too many coordinates

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

Summary of changes:
 NEWS.md                             |  1 +
 src/io/GeoJSONReader.cpp            |  6 +++---
 tests/unit/io/GeoJSONReaderTest.cpp | 25 +++++++++++++++++++++++--
 3 files changed, 27 insertions(+), 5 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list