Skip to content

v0.2.49..v0.2.50 changeset GeometryUtils.cpp

Garret Voltz edited this page Nov 6, 2019 · 1 revision
diff --git a/hoot-core/src/main/cpp/hoot/core/util/GeometryUtils.cpp b/hoot-core/src/main/cpp/hoot/core/util/GeometryUtils.cpp
index 324d15c..5d9fbf4 100644
--- a/hoot-core/src/main/cpp/hoot/core/util/GeometryUtils.cpp
+++ b/hoot-core/src/main/cpp/hoot/core/util/GeometryUtils.cpp
@@ -226,7 +226,8 @@ Geometry* GeometryUtils::validateGeometryCollection(
 
   for (size_t i = 0; i < gc->getNumGeometries(); i++)
   {
-    Geometry* tmp = result->Union(validateGeometry(gc->getGeometryN(i)));
+    std::shared_ptr<Geometry> geometry(validateGeometry(gc->getGeometryN(i)));
+    Geometry* tmp = result->Union(geometry.get());
     delete result;
     result = tmp;
   }
@@ -268,7 +269,7 @@ Geometry* GeometryUtils::validatePolygon(const Polygon* p)
   {
     const LineString* oldShell = p->getExteriorRing();
     std::shared_ptr<LinearRing> oldLinearRing(
-      GeometryFactory::getDefaultInstance()->createLinearRing(*oldShell->getCoordinates()));
+      GeometryFactory::getDefaultInstance()->createLinearRing(oldShell->getCoordinates()));
     LinearRing* shell = validateLinearRing(oldLinearRing.get());
     std::vector<Geometry*>* holes = new vector<Geometry*>();
     holes->reserve(p->getNumInteriorRing());
@@ -337,41 +338,46 @@ QString GeometryUtils::envelopeToConfigString(const Envelope& bounds)
 OsmMapPtr GeometryUtils::createMapFromBounds(const geos::geom::Envelope& bounds)
 {
   OsmMapPtr boundaryMap(new OsmMap());
+  createBoundsInMap(boundaryMap, bounds);
+  return boundaryMap;
+}
 
+ElementId GeometryUtils::createBoundsInMap(const OsmMapPtr& map, const geos::geom::Envelope& bounds)
+{
   NodePtr lowerLeft(
     new Node(
       Status::Unknown1,
-      boundaryMap->createNextNodeId(),
+      map->createNextNodeId(),
       geos::geom::Coordinate(bounds.getMinX(), bounds.getMinY())));
-  boundaryMap->addNode(lowerLeft);
+  map->addNode(lowerLeft);
   NodePtr upperRight(
     new Node(
       Status::Unknown1,
-      boundaryMap->createNextNodeId(),
+      map->createNextNodeId(),
       geos::geom::Coordinate(bounds.getMaxX(), bounds.getMaxY())));
-  boundaryMap->addNode(upperRight);
+  map->addNode(upperRight);
   NodePtr upperLeft(
     new Node(
       Status::Unknown1,
-      boundaryMap->createNextNodeId(),
+      map->createNextNodeId(),
       geos::geom::Coordinate(bounds.getMinX(), bounds.getMaxY())));
-  boundaryMap->addNode(upperLeft);
+  map->addNode(upperLeft);
   NodePtr lowerRight(
     new Node(
       Status::Unknown1,
-      boundaryMap->createNextNodeId(),
+      map->createNextNodeId(),
       geos::geom::Coordinate(bounds.getMaxX(), bounds.getMinY())));
-  boundaryMap->addNode(lowerRight);
+  map->addNode(lowerRight);
 
-  WayPtr bbox(new Way(Status::Unknown1, boundaryMap->createNextWayId()));
+  WayPtr bbox(new Way(Status::Unknown1, map->createNextWayId()));
   bbox->addNode(lowerLeft->getId());
   bbox->addNode(upperLeft->getId());
   bbox->addNode(upperRight->getId());
   bbox->addNode(lowerRight->getId());
   bbox->addNode(lowerLeft->getId());
-  boundaryMap->addWay(bbox);
+  map->addWay(bbox);
 
-  return boundaryMap;
+  return bbox->getElementId();
 }
 
 }
Clone this wiki locally