2222 * This will properly maintain the copyright information. Maxar
2323 * copyrights will be updated automatically.
2424 *
25- * @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Maxar (http://www.maxar.com/)
25+ * @copyright Copyright (C) 2015- 2023 Maxar (http://www.maxar.com/)
2626 */
2727
2828#include " MapCropper.h"
@@ -190,6 +190,10 @@ void MapCropper::apply(OsmMapPtr& map)
190190 LOG_VARD (_bounds->toString ());
191191 LOG_VARD (_inclusionCrit.get ());
192192
193+ // First iteration finds the elements to delete and crop
194+ vector<long > waysToRemove;
195+ vector<long > waysToRemoveFully;
196+ vector<long > waysToCrop;
193197 // go through all the ways
194198 long wayCtr = 0 ;
195199 // Make a copy because the map is modified below
@@ -253,9 +257,9 @@ void MapCropper::apply(OsmMapPtr& map)
253257 LOG_TRACE (" Dropping wholly outside way: " << w->getElementId () << " ..." );
254258 // Removal is based on the parent setting, either remove it fully or leave it in the relation
255259 if (_removeFromParentRelation)
256- RemoveWayByEid::removeWayFully (map, w->getId ());
260+ waysToRemoveFully. emplace_back ( w->getId ());
257261 else
258- RemoveWayByEid::removeWay (map, w->getId ());
262+ waysToRemove. emplace_back ( w->getId ());
259263 _numWaysOutOfBounds++;
260264 _numAffected++;
261265 }
@@ -271,7 +275,7 @@ void MapCropper::apply(OsmMapPtr& map)
271275 {
272276 // Way isn't wholly inside and the configuration requires it to be, so remove the way.
273277 LOG_TRACE (" Dropping due to _keepOnlyFeaturesInsideBounds=true: " << w->getElementId () << " ..." );
274- RemoveWayByEid::removeWayFully (map, w->getId ());
278+ waysToRemoveFully. emplace_back ( w->getId ());
275279 _numWaysOutOfBounds++;
276280 _numAffected++;
277281 }
@@ -280,7 +284,7 @@ void MapCropper::apply(OsmMapPtr& map)
280284 // Way crosses the boundary and we're not configured to keep ways that cross the bounds, so
281285 // do an expensive operation to decide how much to keep, if any.
282286 LOG_TRACE (" Cropping due to _keepEntireFeaturesCrossingBounds=false: " << w->getElementId () << " ..." );
283- _cropWay (map, w->getId ());
287+ waysToCrop. emplace_back ( w->getId ());
284288 _numWaysCrossingThreshold++;
285289 }
286290 else
@@ -299,6 +303,17 @@ void MapCropper::apply(OsmMapPtr& map)
299303 StringUtils::formatLargeNumber (ways.size ()) << " ways." );
300304 }
301305 }
306+
307+ // Bulk remove ways from map and relations too
308+ map->bulkRemoveWays (waysToRemoveFully, true );
309+
310+ // Bulk remove ways from map only
311+ map->bulkRemoveWays (waysToRemove, false );
312+
313+ // Iterate the ways that cross the bounds and crop
314+ for (auto id : waysToCrop)
315+ _cropWay (map, id);
316+
302317 LOG_VARD (map->size ());
303318 OsmMapWriterFactory::writeDebugMap (map, className (), " after-way-removal" );
304319
0 commit comments