diff --git a/datasets/gebco/package/GebcoBathyRaster.cpp b/datasets/gebco/package/GebcoBathyRaster.cpp index 48da88f0..3450cc3f 100644 --- a/datasets/gebco/package/GebcoBathyRaster.cpp +++ b/datasets/gebco/package/GebcoBathyRaster.cpp @@ -99,7 +99,6 @@ bool GebcoBathyRaster::findRasters(finder_t* finder) if (!rastergeo->Intersects(geo)) continue; rasters_group_t* rgroup = new rasters_group_t; - rgroup->infovect.reserve(1); rgroup->id = feature->GetFieldAsString("id"); rgroup->gpsTime = getGmtDate(feature, DATE_TAG, rgroup->gmtDate); @@ -125,6 +124,7 @@ bool GebcoBathyRaster::findRasters(finder_t* finder) rgroup->infovect.push_back(rinfo); } } + rgroup->infovect.shrink_to_fit(); mlog(DEBUG, "Added group: %s with %ld rasters", rgroup->id.c_str(), rgroup->infovect.size()); for(unsigned j = 0; j < rgroup->infovect.size(); j++) @@ -133,6 +133,8 @@ bool GebcoBathyRaster::findRasters(finder_t* finder) // Add the group finder->rasterGroups.push_back(rgroup); } + finder->rasterGroups.shrink_to_fit(); + mlog(DEBUG, "Found %ld raster groups", finder->rasterGroups.size()); } catch (const RunTimeException &e) diff --git a/datasets/landsat/package/LandsatHlsRaster.cpp b/datasets/landsat/package/LandsatHlsRaster.cpp index 59aa305f..8ec7bbc0 100644 --- a/datasets/landsat/package/LandsatHlsRaster.cpp +++ b/datasets/landsat/package/LandsatHlsRaster.cpp @@ -181,7 +181,6 @@ bool LandsatHlsRaster::findRasters(finder_t* finder) /* Set raster group time and group id */ rasters_group_t* rgroup = new rasters_group_t; - rgroup->infovect.reserve(MAX_LANDSAT_RASTER_GROUP_SIZE); rgroup->id = feature->GetFieldAsString("id"); rgroup->gpsTime = getGmtDate(feature, DATE_TAG, rgroup->gmtDate); @@ -220,10 +219,13 @@ bool LandsatHlsRaster::findRasters(finder_t* finder) } } } - mlog(DEBUG, "Added group: %s with %ld rasters", rgroup->id.c_str(), rgroup->infovect.size()); + rgroup->infovect.shrink_to_fit(); + + // mlog(DEBUG, "Added group: %s with %ld rasters", rgroup->id.c_str(), rgroup->infovect.size()); finder->rasterGroups.push_back(rgroup); } - mlog(DEBUG, "Found %ld raster groups", finder->rasterGroups.size()); + finder->rasterGroups.shrink_to_fit(); + // mlog(DEBUG, "Found %ld raster groups", finder->rasterGroups.size()); } catch (const RunTimeException &e) { diff --git a/datasets/pgc/package/PgcDemStripsRaster.cpp b/datasets/pgc/package/PgcDemStripsRaster.cpp index 53956529..4b2a214b 100644 --- a/datasets/pgc/package/PgcDemStripsRaster.cpp +++ b/datasets/pgc/package/PgcDemStripsRaster.cpp @@ -262,9 +262,11 @@ bool PgcDemStripsRaster::findRasters(finder_t* finder) rgroup->gmtDate = TimeLib::gps2gmttime(static_cast(gps)); rgroup->gpsTime = static_cast(gps); rgroup->infovect.push_back(demRinfo); + rgroup->infovect.shrink_to_fit(); finder->rasterGroups.push_back(rgroup); } } + finder->rasterGroups.shrink_to_fit(); mlog(DEBUG, "Found %ld raster groups", finder->rasterGroups.size()); } catch (const RunTimeException &e) diff --git a/datasets/usgs3dep/package/Usgs3dep1meterDemRaster.cpp b/datasets/usgs3dep/package/Usgs3dep1meterDemRaster.cpp index 4be50ac5..ff65cb16 100644 --- a/datasets/usgs3dep/package/Usgs3dep1meterDemRaster.cpp +++ b/datasets/usgs3dep/package/Usgs3dep1meterDemRaster.cpp @@ -113,7 +113,6 @@ bool Usgs3dep1meterDemRaster::findRasters(finder_t* finder) if (!rastergeo->Intersects(geo)) continue; rasters_group_t* rgroup = new rasters_group_t; - rgroup->infovect.reserve(1); rgroup->id = feature->GetFieldAsString("id"); rgroup->gpsTime = getGmtDate(feature, DATE_TAG, rgroup->gmtDate); @@ -129,10 +128,12 @@ bool Usgs3dep1meterDemRaster::findRasters(finder_t* finder) rinfo.fileName = filePath + fileName.substr(pos); rgroup->infovect.push_back(rinfo); } + rgroup->infovect.shrink_to_fit(); mlog(DEBUG, "Added group: %s with %ld rasters", rgroup->id.c_str(), rgroup->infovect.size()); finder->rasterGroups.push_back(rgroup); } + finder->rasterGroups.shrink_to_fit(); mlog(DEBUG, "Found %ld raster groups", finder->rasterGroups.size()); } catch (const RunTimeException &e) diff --git a/packages/geo/GeoIndexedRaster.cpp b/packages/geo/GeoIndexedRaster.cpp index c6172c57..01ae25a1 100644 --- a/packages/geo/GeoIndexedRaster.cpp +++ b/packages/geo/GeoIndexedRaster.cpp @@ -703,6 +703,9 @@ bool GeoIndexedRaster::openGeoIndex(const OGRGeometry* geo, const std::vectorGetRasterXSize(); rows = dset->GetRasterYSize(); @@ -1138,6 +1141,8 @@ void* GeoIndexedRaster::groupsFinderThread(void *param) localFeaturesList.push_back(gf->obj->featuresList[j]->Clone()); } + mlog(DEBUG, "Finding groups for %zu points, range: %u - %u, features cloned: %u", gf->points->size(), start, end, size); + for(uint32_t i = start; i < end; i++) { if(!gf->obj->isSampling()) @@ -1149,8 +1154,6 @@ void* GeoIndexedRaster::groupsFinderThread(void *param) const point_info_t& pinfo = gf->points->at(i); OGRPoint* ogr_point = new OGRPoint(pinfo.point.x, pinfo.point.y, pinfo.point.z); - GroupOrdering* groupList = new GroupOrdering(); - /* Set finder for the whole range of features */ Finder finder(ogr_point, &localFeaturesList); @@ -1158,6 +1161,7 @@ void* GeoIndexedRaster::groupsFinderThread(void *param) gf->obj->findRasters(&finder); /* Filter rasters based on gps time */ + GroupOrdering* groupList = new GroupOrdering(); const int64_t gps = gf->obj->usePOItime() ? pinfo.gps : 0.0; gf->obj->filterRasters(gps, groupList); @@ -1461,9 +1465,17 @@ OGRGeometry* GeoIndexedRaster::getConvexHull(const std::vector* po if(convexHull == NULL) { mlog(ERROR, "Failed to create a convex hull around points."); + return NULL; } - return convexHull; + /* Add a buffer around the convex hull to avoid missing edge points */ + OGRGeometry* bufferedConvexHull = convexHull->Buffer(DISTANCE); + if(bufferedConvexHull) + { + OGRGeometryFactory::destroyGeometry(convexHull); + } + + return bufferedConvexHull; } /*---------------------------------------------------------------------------- @@ -1572,6 +1584,7 @@ void GeoIndexedRaster::applySpatialFilter(OGRLayer* layer, const std::vectorSetSpatialFilter(filter); @@ -1648,6 +1661,10 @@ bool GeoIndexedRaster::findAllGroups(const std::vector* points, throw RunTimeException(CRITICAL, RTE_ERROR, "Number of points groups does not match number of points"); } + /* Reduce memory usage */ + pointsGroups.shrink_to_fit(); + rasterToPointsMap.rehash(rasterToPointsMap.size()); + status = true; } catch (const RunTimeException &e) @@ -1726,9 +1743,13 @@ bool GeoIndexedRaster::findUniqueRasters(std::vector& uniqueRa const point_groups_t& pg = pointsGroups[pointIndx]; ur->pointSamples.push_back({ pg.pointInfo, NULL, false, SS_NO_ERRORS }); } + ur->pointSamples.shrink_to_fit(); } } + /* Reduce memory usage */ + uniqueRasters.shrink_to_fit(); + status = true; } catch(const RunTimeException& e)