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

Commit

Permalink
fixed MVT tile handling; properly aligning data returned from gdalwarper
Browse files Browse the repository at this point in the history
  • Loading branch information
vaclavblazek committed Apr 10, 2019
1 parent 01517e7 commit 68106e4
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 40 deletions.
2 changes: 1 addition & 1 deletion externals/gdal-drivers
2 changes: 1 addition & 1 deletion externals/libgeo
Submodule libgeo updated 1 files
+13 −6 geo/featurelayers.cpp
2 changes: 1 addition & 1 deletion externals/vts-libs
38 changes: 27 additions & 11 deletions mapproxy/src/mapproxy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ------------------------------------------------------------------------
# core mapproxy library
set(mapproxy-core_SOURCES
error.hpp
Expand All @@ -9,6 +10,7 @@ set(mapproxy-core_SOURCES
support/tileindex.hpp support/tileindex.cpp
support/fileclass.hpp support/fileclass.cpp
support/serialization.hpp support/serialization.cpp
support/aborter.hpp
support/glob.hpp support/glob.cpp
support/tilejson.hpp support/tilejson.cpp
support/cesiumconf.hpp support/cesiumconf.cpp
Expand Down Expand Up @@ -53,12 +55,11 @@ set(mapproxy-core_SOURCES
mapproxy.hpp mapproxy.cpp
)

# test program
define_module(LIBRARY mapproxy-core
DEPENDS
qmf
pysupport pydbglog
vts-libs>=2.4 http>=1.0 geo>=1.28 gdal-drivers>=1.14 geometry>=1.7
vts-libs>=2.4 http>=1.0 geo>=1.28 geometry>=1.7
jsoncpp>=2.1

Boost_SERIALIZATION
Expand All @@ -74,10 +75,32 @@ buildsys_library(mapproxy-core)
target_link_libraries(mapproxy-core ${MODULE_LIBRARIES})
buildsys_target_compile_definitions(mapproxy-core ${MODULE_DEFINITIONS})

# test program
# ------------------------------------------------------------------------
# GDAL machinery
set(mapproxy-gdal_SOURCES
gdalsupport.hpp gdalsupport/gdalsupport.cpp
gdalsupport/types.hpp
gdalsupport/requests.hpp gdalsupport/requests.cpp
gdalsupport/process.hpp gdalsupport/process.cpp
gdalsupport/datasetcache.hpp gdalsupport/datasetcache.cpp
gdalsupport/operations.hpp gdalsupport/operations.cpp
)

define_module(LIBRARY mapproxy-gdal
DEPENDS mapproxy-core
gdal-drivers>=1.14
)

add_library(mapproxy-gdal STATIC ${mapproxy-gdal_SOURCES})
buildsys_library(mapproxy-gdal)
target_link_libraries(mapproxy-gdal ${MODULE_LIBRARIES})
buildsys_target_compile_definitions(mapproxy-gdal ${MODULE_DEFINITIONS})

# ------------------------------------------------------------------------
# Main mapproxy binary
define_module(BINARY mapproxy
DEPENDS
mapproxy-core service>=1.6
mapproxy-gdal mapproxy-core service>=1.6

Boost_SERIALIZATION
Boost_FILESYSTEM
Expand Down Expand Up @@ -123,13 +146,6 @@ set(mapproxy_SOURCES
fileinfo.hpp fileinfo.cpp
core.hpp core.cpp

gdalsupport.hpp gdalsupport/gdalsupport.cpp
gdalsupport/types.hpp
gdalsupport/requests.hpp gdalsupport/requests.cpp
gdalsupport/process.hpp gdalsupport/process.cpp
gdalsupport/datasetcache.hpp gdalsupport/datasetcache.cpp
gdalsupport/operations.hpp gdalsupport/operations.cpp

main.cpp
)

Expand Down
8 changes: 1 addition & 7 deletions mapproxy/src/mapproxy/gdalsupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,12 @@
#include "geo/vectorformat.hpp"
#include "geo/heightcoding.hpp"

#include "vts-libs/vts/nodeinfo.hpp"

#include "support/geo.hpp"
#include "support/layerenancer.hpp"
#include "sink.hpp"

namespace vts = vtslibs::vts;
#include "support/aborter.hpp"

class GdalWarper {
public:
typedef std::shared_ptr<GdalWarper> pointer;

struct Options {
unsigned int processCount;
boost::filesystem::path tmpRoot;
Expand Down
2 changes: 2 additions & 0 deletions mapproxy/src/mapproxy/gdalsupport/gdalsupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,8 @@ void GdalWarper::Detail::cleanup(bool join)
cond().notify_all();
}

// TODO: kill unresponsive processes

// cleanup
while (!workers_.empty()) {
auto head(workers_.begin());
Expand Down
10 changes: 8 additions & 2 deletions mapproxy/src/mapproxy/gdalsupport/operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <new>
#include <algorithm>
#include <cstring>
#include <type_traits>

#include <boost/iostreams/stream_buffer.hpp>
#include <boost/iostreams/device/array.hpp>
Expand All @@ -37,6 +38,8 @@

#include <ogrsf_frmts.h>

#include "utility/gccversion.hpp"

#include "imgproc/rastermask/cvmat.hpp"

#include "geo/verticaladjuster.hpp"
Expand All @@ -60,7 +63,8 @@ cv::Mat* allocateMat(ManagedBuffer &mb
const auto matSize(sizeof(cv::Mat) + dataSize);

// create raw memory to hold matrix and data
char *raw(static_cast<char*>(mb.allocate(matSize)));
char *raw(static_cast<char*>
(mb.allocate_aligned(matSize, alignof(cv::Mat))));

// allocate matrix in raw data block
return new (raw) cv::Mat(size.height, size.width, type
Expand Down Expand Up @@ -401,7 +405,9 @@ allocateHc(ManagedBuffer &mb
{
// create raw memory to hold block and data
char *raw(static_cast<char*>
(mb.allocate(sizeof(GdalWarper::Heightcoded) + data.size())));
(mb.allocate_aligned
(sizeof(GdalWarper::Heightcoded) + data.size()
, alignof(GdalWarper::Heightcoded))));

// poiter to output data
auto *dataPtr(raw + sizeof(GdalWarper::Heightcoded));
Expand Down
8 changes: 8 additions & 0 deletions mapproxy/src/mapproxy/generator/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,18 @@ bool isRemote(const std::string &path)
|| ba::istarts_with(path, "ftp:")));
}

bool isMvt(const std::string &path)
{
return ba::starts_with(path, "mvt:");
}

} // namespace

std::string Generator::absoluteDataset(const std::string &path)
const
{
// handle non-path resources (i.e. URL's)
if (isMvt(path)) { return "mvt:" + absoluteDataset(path.substr(4)); }
if (isRemote(path)) { return path; }
return absolute(path, config_.resourceRoot).string();
}
Expand All @@ -241,7 +247,9 @@ boost::filesystem::path
Generator::absoluteDataset(const boost::filesystem::path &path)
const
{
const auto &spath(path.string());
// handle non-path resources (i.e. URL's)
if (isMvt(spath)) { return "mvt:" + absoluteDataset(spath.substr(4)); }
if (isRemote(path.string())) { return path; }
return absolute(path, config_.resourceRoot);
}
Expand Down
13 changes: 1 addition & 12 deletions mapproxy/src/mapproxy/sink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,10 @@
#include "vts-libs/storage/streams.hpp"

#include "support/fileclass.hpp"
#include "support/aborter.hpp"

namespace vs = vtslibs::storage;

/** Aborter helper.
*/
struct Aborter {
typedef http::ServerSink::AbortedCallback AbortedCallback;

virtual ~Aborter() {}

/** Defaults to dummy aborter
*/
virtual void setAborter(const AbortedCallback&) {};
};

/** Wraps libhttp's sink.
*/
class Sink : public Aborter {
Expand Down
45 changes: 45 additions & 0 deletions mapproxy/src/mapproxy/support/aborter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright (c) 2017 Melown Technologies SE
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef mapproxy_support_aborter_hpp_included_
#define mapproxy_support_aborter_hpp_included_

#include <functional>

/** Aborter helper.
*/
struct Aborter {
typedef std::function<void()> AbortedCallback;

virtual ~Aborter() {}

/** Defaults to dummy aborter
*/
virtual void setAborter(const AbortedCallback&) {};
};

#endif // mapproxy_support_aborter_hpp_included_

6 changes: 3 additions & 3 deletions mapproxy/src/mapproxy/support/wmts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ std::string makeTemplate(const Layer &layer)
}

os << "{TileMatrix}-{TileCol}-{TileRow}." << layer.format;
if (layer.resource.revision) {
os << "?r=" << layer.resource.revision;
if (layer.resource->revision) {
os << "?r=" << layer.resource->revision;
}

return os.str();
Expand Down Expand Up @@ -480,7 +480,7 @@ void content(XML &x, const Layer::list &layers)

Element c(x, "Contents");
for (const auto &layer : layers) {
const auto &r(layer.resource);
const auto &r(*layer.resource);

const TmsEntry &tms(cache.get(r));

Expand Down
4 changes: 2 additions & 2 deletions mapproxy/src/mapproxy/support/wmts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
namespace wmts {

struct Layer {
const Resource &resource;
const Resource *resource;
std::string rootPath;
RasterFormat format;

typedef std::vector<Layer> list;

Layer(const Resource &resource)
: resource(resource), format(RasterFormat::jpg)
: resource(&resource), format(RasterFormat::jpg)
{}
};

Expand Down

0 comments on commit 68106e4

Please sign in to comment.