From d42fdfc314b86abfb3c90b5012e49c2b1d844715 Mon Sep 17 00:00:00 2001 From: Vaclav Blazek Date: Wed, 21 Oct 2020 21:53:21 +0200 Subject: [PATCH] Various warp-related fixes; setup-resource uses cubicspline for downsamplig; metatile warping uses avg(min, max) if value is unavailable. --- externals/libgeo | 2 +- externals/libutility | 2 +- externals/vts-libs | 2 +- mapproxy/src/mapproxy/definition/factory.cpp | 4 ---- .../src/mapproxy/gdalsupport/gdalsupport.cpp | 21 +++++++++++++------ .../src/mapproxy/gdalsupport/operations.cpp | 8 ++++++- mapproxy/src/mapproxy/generator/metatile.cpp | 6 ++++++ .../src/mapproxy/generator/surface-dem.cpp | 1 + mapproxy/src/setup-resource/main.cpp | 4 +++- 9 files changed, 35 insertions(+), 15 deletions(-) diff --git a/externals/libgeo b/externals/libgeo index cf1929f..cb59d65 160000 --- a/externals/libgeo +++ b/externals/libgeo @@ -1 +1 @@ -Subproject commit cf1929f9a1502a84a599eeb4bd61b52360730229 +Subproject commit cb59d65e10938429d751bab148d2f7dfa0e0aa25 diff --git a/externals/libutility b/externals/libutility index dfb9318..9b817ae 160000 --- a/externals/libutility +++ b/externals/libutility @@ -1 +1 @@ -Subproject commit dfb931846039b6747bbbb0138acfb678c9b6bd63 +Subproject commit 9b817aec16f75429fc3cba96093b0e9196266a6e diff --git a/externals/vts-libs b/externals/vts-libs index d6f289f..f533edf 160000 --- a/externals/vts-libs +++ b/externals/vts-libs @@ -1 +1 @@ -Subproject commit d6f289fd94571a42802923ac0a4901b8d31a2f4d +Subproject commit f533edf55458ca2100cffcdb11af5c88c390a105 diff --git a/mapproxy/src/mapproxy/definition/factory.cpp b/mapproxy/src/mapproxy/definition/factory.cpp index d835e80..ba24ef5 100644 --- a/mapproxy/src/mapproxy/definition/factory.cpp +++ b/mapproxy/src/mapproxy/definition/factory.cpp @@ -47,9 +47,6 @@ DefinitionBase::pointer definition(const Resource::Generator &type) const auto &r(registry()); auto fregistry(r.find(type)); if (fregistry == r.end()) { - for (const auto &item : registry()) { - LOG(info4) << " " << item.first; - } LOGTHROW(err1, UnknownGenerator) << "Unknown generator type <" << type << ">."; } @@ -60,7 +57,6 @@ void registerDefinition(const Resource::Generator &type , const std::function &factory) { - LOG(info4) << "registering <" << type << ">."; registry().insert(Registry::value_type(type, factory)); } diff --git a/mapproxy/src/mapproxy/gdalsupport/gdalsupport.cpp b/mapproxy/src/mapproxy/gdalsupport/gdalsupport.cpp index b019336..ca62470 100644 --- a/mapproxy/src/mapproxy/gdalsupport/gdalsupport.cpp +++ b/mapproxy/src/mapproxy/gdalsupport/gdalsupport.cpp @@ -720,6 +720,9 @@ void GdalWarper::Detail::runManager(Process::Id parentId) void GdalWarper::Detail::killLeviathan() { + // stop if there are no workers (yet) + if (workers_.empty()) { return; } + utility::PidList pids; for (const auto &item : workers_) { pids.push_back(item.first); } @@ -767,13 +770,19 @@ void GdalWarper::Detail::killLeviathan() << "Killing large GDAL process " << u.pid << " occupying " << (double(total) / 1024) << "MB of memory."; - auto fworkers(workers_.find(u.pid)); - if (fworkers != workers_.end()) { - fworkers->second->terminate(); - } else { - // should not happen - Process::kill(u.pid); + try { + auto fworkers(workers_.find(u.pid)); + if (fworkers != workers_.end()) { + fworkers->second->terminate(); + } else { + // should not happen + Process::kill(u.pid); + } + } catch (const std::exception &e) { + LOG(warn2) << "Unable to kill worker process: <" + << e.what() << ">; ignoring."; } + total -= u.mem; } } diff --git a/mapproxy/src/mapproxy/gdalsupport/operations.cpp b/mapproxy/src/mapproxy/gdalsupport/operations.cpp index 1f033d9..b33b414 100644 --- a/mapproxy/src/mapproxy/gdalsupport/operations.cpp +++ b/mapproxy/src/mapproxy/gdalsupport/operations.cpp @@ -243,7 +243,13 @@ cv::Mat* warpValueMinMax(DatasetCache &cache, ManagedBuffer &mb { // skip invalid value auto value(*id); - if (value == ForcedNodata) { continue; } + if (value == ForcedNodata) { + if ((*idmin == ForcedNodata) || (*idmax == ForcedNodata)) { + continue; + } + // no value but we have valid min/max -> average + value = (*idmin + *idmax) / 2; + } auto &sample(*itile); sample[0] = value; diff --git a/mapproxy/src/mapproxy/generator/metatile.cpp b/mapproxy/src/mapproxy/generator/metatile.cpp index d33ea1d..d564a50 100644 --- a/mapproxy/src/mapproxy/generator/metatile.cpp +++ b/mapproxy/src/mapproxy/generator/metatile.cpp @@ -274,9 +274,15 @@ metatileFromDemImpl(const vts::TileId &tileId, Sink &sink, Arsenal &arsenal << ", size in tiles: " << vts::tileRangesSize(block.view) << "."; +#if 0 #if GDAL_VERSION_NUM >= 2020000 // force average since cubicspline is somewhat dubious on GDAL >= 2.2 + // FIXME: disabled, seems to be working when GDAL is fixed const auto resampling(geo::GeoDataset::Resampling::average); +#else + // use "dem" resampling (cubicspline or average) + const auto resampling(geo::GeoDataset::Resampling::dem); +#endif #else // use "dem" resampling (cubicspline or average) const auto resampling(geo::GeoDataset::Resampling::dem); diff --git a/mapproxy/src/mapproxy/generator/surface-dem.cpp b/mapproxy/src/mapproxy/generator/surface-dem.cpp index c4d4782..2830512 100644 --- a/mapproxy/src/mapproxy/generator/surface-dem.cpp +++ b/mapproxy/src/mapproxy/generator/surface-dem.cpp @@ -420,6 +420,7 @@ void SurfaceDem::generateNavtile(const vts::TileId &tileId const auto *metanode(metatile.get(tileId, std::nothrow)); if (!metanode) { sink.error(utility::makeError("Metatile not found.")); + return; } const auto heightRange(metanode->heightRange); diff --git a/mapproxy/src/setup-resource/main.cpp b/mapproxy/src/setup-resource/main.cpp index 982417b..fb0cb74 100644 --- a/mapproxy/src/setup-resource/main.cpp +++ b/mapproxy/src/setup-resource/main.cpp @@ -587,7 +587,9 @@ fs::path createVrtWO(const calipers::Measurement &cm { LogLinePrefix linePrefix(" (dem)"); createVrtWO(datasetPath, rootDir, "dem" - , geo::GeoDataset::Resampling::dem, cm); + // , geo::GeoDataset::Resampling::average + , geo::GeoDataset::Resampling::cubicspline + , cm); } LOG(info4) << "Generating minimum height overviews.";