[geos-commits] [SCM] GEOS branch main updated. d880957a155d095988ff97060bc1d4ca5643cf90

git at osgeo.org git at osgeo.org
Tue Jul 13 08:42:19 PDT 2021


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, main has been updated
       via  d880957a155d095988ff97060bc1d4ca5643cf90 (commit)
       via  2e49624cb4cad5225806279a26644d38727ae709 (commit)
      from  2df86bc1191f578047fb30331cae254486ace191 (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 d880957a155d095988ff97060bc1d4ca5643cf90
Merge: 2df86bc 2e49624
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Tue Jul 13 08:41:26 2021 -0700

    Merge branch 'GeoJson' of https://github.com/whuaegeanse/geos into main


commit 2e49624cb4cad5225806279a26644d38727ae709
Author: whuaegeansea <whuaegeansea at gmail.com>
Date:   Tue Jul 13 11:11:04 2021 +0800

    Fix bug of wrong index in encodeMultiPolygon. Remove unsed variables.
    And enhance functions by removing temp const reference before returning.

diff --git a/src/io/GeoJSONWriter.cpp b/src/io/GeoJSONWriter.cpp
index c35f3a3..c8bbab5 100644
--- a/src/io/GeoJSONWriter.cpp
+++ b/src/io/GeoJSONWriter.cpp
@@ -43,24 +43,21 @@ std::string GeoJSONWriter::write(const geom::Geometry* geometry, GeoJSONType typ
 {
     json j;
     encode(geometry, type, j);
-    const std::string& geojson = j.dump();
-    return geojson;
+    return j.dump();
 }
 
 std::string GeoJSONWriter::writeFormatted(const geom::Geometry* geometry, GeoJSONType type, int indent)
 {
     json j;
     encode(geometry, type, j);
-    const std::string& geojson = j.dump(indent);
-    return geojson;
+    return j.dump(indent);
 }
 
 std::string GeoJSONWriter::write(const GeoJSONFeature& feature)
 {
     json j;
     encodeFeature(feature, j);
-    const std::string& geojson = j.dump();
-    return geojson;
+    return j.dump();
 }
 
 void GeoJSONWriter::encodeGeoJSONValue(const std::string& key, const GeoJSONValue& value,
@@ -123,8 +120,7 @@ std::string GeoJSONWriter::write(const GeoJSONFeatureCollection& features)
         featuresJson.push_back(featureJson);
     }
     j["features"] = featuresJson;
-    const std::string& geojson = j.dump();
-    return geojson;
+    return j.dump();
 }
 
 void GeoJSONWriter::encodeFeature(const GeoJSONFeature& feature, geos_nlohmann::ordered_json& j)
@@ -223,7 +219,7 @@ void GeoJSONWriter::encodePolygon(const geom::Polygon* poly, geos_nlohmann::orde
     j["type"] = "Polygon";
     std::vector<std::vector<std::pair<double, double>>> rings;
     auto ring = poly->getExteriorRing();
-    auto coords = ring->getCoordinates();
+    rings.reserve(poly->getNumInteriorRing()+1);
     rings.push_back(convertCoordinateSequence(ring->getCoordinates().get()));
     for (size_t i = 0; i < poly->getNumInteriorRing(); i++) {
         rings.push_back(convertCoordinateSequence(poly->getInteriorRingN(i)->getCoordinates().get()));
@@ -241,6 +237,7 @@ void GeoJSONWriter::encodeMultiLineString(const geom::MultiLineString* multiLine
 {
     j["type"] = "MultiLineString";
     std::vector<std::vector<std::pair<double, double>>> lines;
+    lines.reserve(multiLineString->getNumGeometries());
     for (size_t i = 0; i < multiLineString->getNumGeometries(); i++) {
         lines.push_back(convertCoordinateSequence(multiLineString->getGeometryN(i)->getCoordinates().get()));
     }
@@ -256,10 +253,10 @@ void GeoJSONWriter::encodeMultiPolygon(const geom::MultiPolygon* multiPolygon, g
         const Polygon* polygon = multiPolygon->getGeometryN(i);
         std::vector<std::vector<std::pair<double, double>>> rings;
         auto ring = polygon->getExteriorRing();
-        auto coords = ring->getCoordinates();
+        rings.reserve(polygon->getNumInteriorRing() + 1);
         rings.push_back(convertCoordinateSequence(ring->getCoordinates().get()));
         for (size_t j = 0; j < polygon->getNumInteriorRing(); j++) {
-            rings.push_back(convertCoordinateSequence(polygon->getInteriorRingN(i)->getCoordinates().get()));
+            rings.push_back(convertCoordinateSequence(polygon->getInteriorRingN(j)->getCoordinates().get()));
         }
         polygons.push_back(rings);
     }

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

Summary of changes:
 src/io/GeoJSONWriter.cpp | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list