Skip to content

Commit

Permalink
added buffer to convex hull, trimmed vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
elidwa committed Sep 27, 2024
1 parent 0814bf7 commit 1a3d923
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
4 changes: 3 additions & 1 deletion datasets/gebco/package/GebcoBathyRaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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++)
Expand All @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions datasets/landsat/package/LandsatHlsRaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions datasets/pgc/package/PgcDemStripsRaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,11 @@ bool PgcDemStripsRaster::findRasters(finder_t* finder)
rgroup->gmtDate = TimeLib::gps2gmttime(static_cast<int64_t>(gps));
rgroup->gpsTime = static_cast<int64_t>(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)
Expand Down
3 changes: 2 additions & 1 deletion datasets/usgs3dep/package/Usgs3dep1meterDemRaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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)
Expand Down
27 changes: 24 additions & 3 deletions packages/geo/GeoIndexedRaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,9 @@ bool GeoIndexedRaster::openGeoIndex(const OGRGeometry* geo, const std::vector<po
OGRFeature::DestroyFeature(feature);
}

/* Reduce memory footprint */
featuresList.shrink_to_fit();

cols = dset->GetRasterXSize();
rows = dset->GetRasterYSize();

Expand Down Expand Up @@ -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())
Expand All @@ -1149,15 +1154,14 @@ 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);

/* Find rasters intersecting with ogr_point */
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);

Expand Down Expand Up @@ -1461,9 +1465,17 @@ OGRGeometry* GeoIndexedRaster::getConvexHull(const std::vector<point_info_t>* 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;
}

/*----------------------------------------------------------------------------
Expand Down Expand Up @@ -1572,6 +1584,7 @@ void GeoIndexedRaster::applySpatialFilter(OGRLayer* layer, const std::vector<poi
const double startTime = TimeLib::latchtime();

OGRGeometry* filter = getBufferedPoints(points);
// OGRGeometry* filter = getConvexHull(points);
if(filter != NULL)
{
layer->SetSpatialFilter(filter);
Expand Down Expand Up @@ -1648,6 +1661,10 @@ bool GeoIndexedRaster::findAllGroups(const std::vector<point_info_t>* 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)
Expand Down Expand Up @@ -1726,9 +1743,13 @@ bool GeoIndexedRaster::findUniqueRasters(std::vector<unique_raster_t*>& 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)
Expand Down

0 comments on commit 1a3d923

Please sign in to comment.