Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
terrain: using zero height instead of nodata; generating all tiles ab…
Browse files Browse the repository at this point in the history
…ove first valid tiles, all level=0 tiles are generated
  • Loading branch information
vaclavblazek committed Apr 10, 2019
1 parent 68106e4 commit 606943c
Show file tree
Hide file tree
Showing 18 changed files with 202 additions and 55 deletions.
2 changes: 1 addition & 1 deletion externals/libqmf
Submodule libqmf updated 1 files
+2 −0 qmf/qmf.cpp
2 changes: 1 addition & 1 deletion mapproxy/src/mapproxy/cesium/cesium.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">

<script src="https://cesiumjs.org/releases/1.55/Build/Cesium/Cesium.js"></script>
<script src="https://cesiumjs.org/releases/1.56/Build/Cesium/Cesium.js"></script>
<style>
@import url(https://cesiumjs.org/releases/1.55/Build/Cesium/Widgets/widgets.css);
html, body, #cesiumContainer {
Expand Down
10 changes: 10 additions & 0 deletions mapproxy/src/mapproxy/cesium/cesium.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ function processBoundLayer(config, bl) {
}

function processConfig(config) {
if (typeof(config.defaultView !== "undefined")) {
// set default rectangle from config
Cesium.Camera.DEFAULT_VIEW_FACTOR = 0.0;
Cesium.Camera.DEFAULT_VIEW_RECTANGLE
= Cesium.Rectangle.fromDegrees(config.defaultView[0]
, config.defaultView[1]
, config.defaultView[2]
, config.defaultView[3]);
}

if (config.boundLayer) {
config.boundLayer = resolveUrl(config.boundLayer, document.URL);
return loadJson(config.boundLayer, "application/json"
Expand Down
5 changes: 5 additions & 0 deletions mapproxy/src/mapproxy/gdalsupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class GdalWarper {
math::Size2 size;
geo::GeoDataset::Resampling resampling;
boost::optional<std::string> mask;
boost::optional<double> nodata;

RasterRequest(Operation operation
, const std::string &dataset
Expand All @@ -135,6 +136,10 @@ class GdalWarper {
, srs(srs), extents(extents), size(size), resampling(resampling)
, mask(mask)
{}

RasterRequest& setNodata(const boost::optional<double> &value) {
nodata = value; return *this;
}
};

Raster warp(const RasterRequest &request, Aborter &sink);
Expand Down
45 changes: 31 additions & 14 deletions mapproxy/src/mapproxy/gdalsupport/operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,26 @@ cv::Mat* allocateMat(ManagedBuffer &mb
, raw + sizeof(cv::Mat));
}

inline geo::OptionalNodataValue
asOptNodata(const geo::NodataValue &nodata
, const geo::NodataValue &dflt = boost::none)
{
return nodata ? nodata : dflt;
}

cv::Mat* warpImage(DatasetCache &cache, ManagedBuffer &mb
, const std::string &dataset
, const geo::SrsDefinition &srs
, const math::Extents2 &extents
, const math::Size2 &size
, geo::GeoDataset::Resampling resampling
, const boost::optional<std::string> &maskDataset
, bool optimize)
, bool optimize
, const geo::NodataValue &nodata)
{
auto &src(cache(dataset));
auto dst(geo::GeoDataset::deriveInMemory(src, srs, size, extents));
auto dst(geo::GeoDataset::deriveInMemory
(src, srs, size, extents, boost::none, asOptNodata(nodata)));
src.warpInto(dst, resampling);

if (optimize && dst.cmask().empty()) {
Expand Down Expand Up @@ -116,10 +125,12 @@ cv::Mat* warpMask(DatasetCache &cache, ManagedBuffer &mb
, const math::Extents2 &extents
, const math::Size2 &size
, geo::GeoDataset::Resampling resampling
, bool optimize)
, bool optimize
, const geo::NodataValue &nodata)
{
auto &src(cache(dataset));
auto dst(geo::GeoDataset::deriveInMemory(src, srs, size, extents));
auto dst(geo::GeoDataset::deriveInMemory
(src, srs, size, extents, boost::none, asOptNodata(nodata)));
src.warpInto(dst, resampling);

// fetch mask from dataset (optimized, all valid -> invalid matrix)
Expand Down Expand Up @@ -176,19 +187,22 @@ cv::Mat* warpValueMinMax(DatasetCache &cache, ManagedBuffer &mb
, const geo::SrsDefinition &srs
, const math::Extents2 &extents
, const math::Size2 &size
, geo::GeoDataset::Resampling resampling)
, geo::GeoDataset::Resampling resampling
, const geo::NodataValue &nodata)
{
// combined result of warped dataset and result of warpMinMax
auto &src(cache(dataset));
auto &minSrc(cache(dataset + ".min"));
auto &maxSrc(cache(dataset + ".max"));

const auto nd(asOptNodata(nodata, ForcedNodata));

auto dst(geo::GeoDataset::deriveInMemory
(src, srs, size, extents, GDT_Float32, ForcedNodata));
(src, srs, size, extents, GDT_Float32, nd));
auto minDst(geo::GeoDataset::deriveInMemory
(minSrc, srs, size, extents, GDT_Float32, ForcedNodata));
(minSrc, srs, size, extents, GDT_Float32, nd));
auto maxDst(geo::GeoDataset::deriveInMemory
(maxSrc, srs, size, extents, GDT_Float32, ForcedNodata));
(maxSrc, srs, size, extents, GDT_Float32, nd));

geo::GeoDataset::WarpOptions warpOptions;
#if GDAL_VERSION_NUM >= 2020000
Expand Down Expand Up @@ -253,7 +267,8 @@ cv::Mat* warpDem(DatasetCache &cache, ManagedBuffer &mb
, const geo::SrsDefinition &srs
, const math::Extents2 &extents
, const math::Size2 &requestedSize
, bool optimize)
, bool optimize
, const geo::NodataValue &nodata)
{
auto &src(cache(dataset));

Expand All @@ -279,7 +294,7 @@ cv::Mat* warpDem(DatasetCache &cache, ManagedBuffer &mb
// warp in floats
auto dst(geo::GeoDataset::deriveInMemory
(src, srs, gridSize, gridExtents, ::GDT_Float32
, ForcedNodata));
, asOptNodata(nodata, ForcedNodata)));

auto wri(src.warpInto(dst, geo::GeoDataset::Resampling::dem));
LOG(info1) << "Warp result: scale=" << wri.scale
Expand All @@ -305,13 +320,14 @@ cv::Mat* warp(DatasetCache &cache, ManagedBuffer &mb
return warpImage
(cache, mb, req.dataset, req.srs, req.extents, req.size
, req.resampling, req.mask
, (req.operation == Operation::image));
, (req.operation == Operation::image), req.nodata);

case Operation::mask:
case Operation::maskNoOpt:
return warpMask
(cache, mb, req.dataset, req.srs, req.extents, req.size
, req.resampling, (req.operation == Operation::mask));
, req.resampling, (req.operation == Operation::mask)
, req.nodata);

case Operation::detailMask:
return warpDetailMask
Expand All @@ -321,12 +337,13 @@ cv::Mat* warp(DatasetCache &cache, ManagedBuffer &mb
case Operation::demOptimal:
return warpDem
(cache, mb, req.dataset, req.srs, req.extents, req.size
, (req.operation == Operation::demOptimal));
, (req.operation == Operation::demOptimal)
, req.nodata);

case Operation::valueMinMax:
return warpValueMinMax
(cache, mb, req.dataset, req.srs, req.extents, req.size
, req.resampling);
, req.resampling, req.nodata);
}
throw;
}
Expand Down
3 changes: 2 additions & 1 deletion mapproxy/src/mapproxy/gdalsupport/requests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ShRaster::ShRaster(const GdalWarper::RasterRequest &other
, size_(other.size)
, resampling_(other.resampling)
, mask_(sm.get_allocator<char>())
, nodata_(other.nodata)
, response_()
{
if (other.mask) {
Expand All @@ -60,7 +61,7 @@ ShRaster::operator GdalWarper::RasterRequest() const {
, std::string(dataset_.data(), dataset_.size())
, geo::SrsDefinition(asString(srs_), srsType_)
, extents_, size_, resampling_
, asOptional(mask_));
, asOptional(mask_)).setNodata(nodata_);
}

cv::Mat* ShRaster::response() {
Expand Down
1 change: 1 addition & 0 deletions mapproxy/src/mapproxy/gdalsupport/requests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class ShRaster : boost::noncopyable {
math::Size2 size_;
geo::GeoDataset::Resampling resampling_;
String mask_;
boost::optional<double> nodata_;

// response matrix
cv::Mat *response_;
Expand Down
7 changes: 4 additions & 3 deletions mapproxy/src/mapproxy/generator/surface-dem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ class DemSampler {

} // namespace

AugmentedMesh SurfaceDem::generateMeshImpl(const vts::NodeInfo &nodeInfo
, Sink &sink
, Arsenal &arsenal) const
AugmentedMesh SurfaceDem
::generateMeshImpl(const vts::NodeInfo &nodeInfo, Sink &sink
, Arsenal &arsenal, const OptHeight &defaultHeight) const
{
const int samplesPerSide(128);
const TileFacesCalculator tileFacesCalculator;
Expand All @@ -347,6 +347,7 @@ AugmentedMesh SurfaceDem::generateMeshImpl(const vts::NodeInfo &nodeInfo
, dem_.dataset
, nodeInfo.srsDef(), nodeInfo.extents()
, math::Size2(samplesPerSide, samplesPerSide))
.setNodata(defaultHeight)
, sink));

sink.checkAborted();
Expand Down
6 changes: 3 additions & 3 deletions mapproxy/src/mapproxy/generator/surface-dem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class SurfaceDem : public SurfaceBase {
, const SurfaceFileInfo &fileInfo
, Arsenal &arsenal) const;

virtual AugmentedMesh generateMeshImpl(const vts::NodeInfo &nodeInfo
, Sink &sink
, Arsenal &arsenal) const;
virtual AugmentedMesh
generateMeshImpl(const vts::NodeInfo &nodeInfo, Sink &sink
, Arsenal &arsenal, const OptHeight &defaultHeight) const;

virtual void generateNavtile(const vts::TileId &tileId
, Sink &sink
Expand Down
6 changes: 3 additions & 3 deletions mapproxy/src/mapproxy/generator/surface-spheroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,9 @@ void SurfaceSpheroid::generateMetatile(const vts::TileId &tileId
sink.content(os.str(), fi.sinkFileInfo());
}

AugmentedMesh SurfaceSpheroid::generateMeshImpl(const vts::NodeInfo &nodeInfo
, Sink &sink
, Arsenal&) const
AugmentedMesh
SurfaceSpheroid::generateMeshImpl(const vts::NodeInfo &nodeInfo, Sink &sink
, Arsenal&, const OptHeight&) const
{
// TODO: calculate tile sampling
const int samplesPerSide(10);
Expand Down
3 changes: 2 additions & 1 deletion mapproxy/src/mapproxy/generator/surface-spheroid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class SurfaceSpheroid : public SurfaceBase {

virtual AugmentedMesh generateMeshImpl(const vts::NodeInfo &nodeInfo
, Sink &sink
, Arsenal &arsenal) const;
, Arsenal &arsenal
, const OptHeight&) const;

virtual void generateNavtile(const vts::TileId &tileId
, Sink &sink
Expand Down
Loading

0 comments on commit 606943c

Please sign in to comment.