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

Commit

Permalink
Merge pull request #21 from melowntech/vasek/setup-resource-tweaks
Browse files Browse the repository at this point in the history
mapproxy-setup-resource tweaks
  • Loading branch information
vaclavblazek authored Jul 18, 2022
2 parents 87ae520 + 48c5c79 commit cea2845
Show file tree
Hide file tree
Showing 30 changed files with 88 additions and 58 deletions.
2 changes: 1 addition & 1 deletion externals/buildsys/common
Submodule common updated 1 files
+9 −3 deb.mk
2 changes: 1 addition & 1 deletion externals/libdbglog
2 changes: 1 addition & 1 deletion externals/libhttp
2 changes: 1 addition & 1 deletion externals/libjsoncpp
2 changes: 1 addition & 1 deletion externals/libmath
2 changes: 1 addition & 1 deletion externals/libminiball
2 changes: 1 addition & 1 deletion externals/libpydbglog
2 changes: 1 addition & 1 deletion externals/libqmf
2 changes: 1 addition & 1 deletion externals/libshtools
4 changes: 2 additions & 2 deletions mapproxy/src/calipers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(mp-calipers_SOURCES

add_library(mp-calipers ${mp-calipers_SOURCES})
target_link_libraries(mp-calipers ${MODULE_LIBRARIES})
buildsys_target_compile_definitions(mp-calipers ${MODULE_DEFINITIONS})
target_compile_definitions(mp-calipers PRIVATE ${MODULE_DEFINITIONS})
buildsys_library(mp-calipers)

# ------------------------------------------------------------------------
Expand All @@ -29,7 +29,7 @@ set(mapproxy-calipers_SOURCES

add_executable(mapproxy-calipers ${mapproxy-calipers_SOURCES})
target_link_libraries(mapproxy-calipers mp-calipers ${MODULE_LIBRARIES})
buildsys_target_compile_definitions(mapproxy-calipers ${MODULE_DEFINITIONS})
target_compile_definitions(mapproxy-calipers PRIVATE ${MODULE_DEFINITIONS})
buildsys_binary(mapproxy-calipers)
set_target_version(mapproxy-calipers ${vts-mapproxy_VERSION})

Expand Down
4 changes: 2 additions & 2 deletions mapproxy/src/generatevrtwo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(mp-generatevrtwo_SOURCES

add_library(mp-generatevrtwo ${mp-generatevrtwo_SOURCES})
target_link_libraries(mp-generatevrtwo ${MODULE_LIBRARIES})
buildsys_target_compile_definitions(mp-generatevrtwo ${MODULE_DEFINITIONS})
target_compile_definitions(mp-generatevrtwo PRIVATE ${MODULE_DEFINITIONS})
buildsys_library(mp-generatevrtwo)

# ------------------------------------------------------------------------
Expand All @@ -29,7 +29,7 @@ set(generatevrtwo_SOURCES

add_executable(generatevrtwo ${generatevrtwo_SOURCES})
target_link_libraries(generatevrtwo mp-generatevrtwo ${MODULE_LIBRARIES})
buildsys_target_compile_definitions(generatevrtwo ${MODULE_DEFINITIONS})
target_compile_definitions(generatevrtwo PRIVATE ${MODULE_DEFINITIONS})
buildsys_binary(generatevrtwo)
set_target_version(generatevrtwo ${vts-mapproxy_VERSION})

Expand Down
6 changes: 3 additions & 3 deletions mapproxy/src/mapproxy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ define_module(LIBRARY mapproxy-core
add_library(mapproxy-core STATIC ${mapproxy-core_SOURCES})
buildsys_library(mapproxy-core)
target_link_libraries(mapproxy-core ${MODULE_LIBRARIES})
buildsys_target_compile_definitions(mapproxy-core ${MODULE_DEFINITIONS})
target_compile_definitions(mapproxy-core PRIVATE ${MODULE_DEFINITIONS})

# ------------------------------------------------------------------------
# GDAL machinery
Expand All @@ -106,7 +106,7 @@ define_module(LIBRARY mapproxy-gdal
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})
target_compile_definitions(mapproxy-gdal PRIVATE ${MODULE_DEFINITIONS})

# ------------------------------------------------------------------------
# Main mapproxy binary
Expand Down Expand Up @@ -225,7 +225,7 @@ add_executable(mapproxy
${mapproxy_OL_SOURCES}
)
target_link_libraries(mapproxy mapproxy-core ${MODULE_LIBRARIES})
buildsys_target_compile_definitions(mapproxy ${MODULE_DEFINITIONS})
target_compile_definitions(mapproxy PRIVATE ${MODULE_DEFINITIONS})
buildsys_binary(mapproxy)
set_target_version(mapproxy ${vts-mapproxy_VERSION})

Expand Down
24 changes: 12 additions & 12 deletions mapproxy/src/mapproxy/mapproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,43 @@ namespace fs = boost::filesystem;
bool Mapproxy::supportsReferenceFrame(const std::string &referenceFrame)
{
const auto reply
(ctrl_.command("supports-reference-frame", referenceFrame));
(ctrl_->command("supports-reference-frame", referenceFrame));
if (reply.empty()) {
LOGTHROW(err2, std::runtime_error)
<< "Invalid reply from mapproxy.";
}

return ctrl_.parseBoolean(reply.front());
return ctrl_->parseBoolean(reply.front());
}

bool Mapproxy::has(const Resource::Id &resourceId) const
{
const auto reply(ctrl_.command("has-resource", resourceId.referenceFrame
const auto reply(ctrl_->command("has-resource", resourceId.referenceFrame
, resourceId.group, resourceId.id));
if (reply.empty()) {
LOGTHROW(err2, std::runtime_error)
<< "Invalid reply from mapproxy.";
}

return ctrl_.parseBoolean(reply.front());
return ctrl_->parseBoolean(reply.front());
}

bool Mapproxy::isReady(const Resource::Id &resourceId) const
{
const auto reply(ctrl_.command("is-resource-ready"
const auto reply(ctrl_->command("is-resource-ready"
, resourceId.referenceFrame
, resourceId.group, resourceId.id));
if (reply.empty()) {
LOGTHROW(err2, std::runtime_error)
<< "Invalid reply from mapproxy.";
}

return ctrl_.parseBoolean(reply.front());
return ctrl_->parseBoolean(reply.front());
}

std::string Mapproxy::url(const Resource::Id &resourceId) const
{
const auto reply(ctrl_.command("resource-url", resourceId.referenceFrame
const auto reply(ctrl_->command("resource-url", resourceId.referenceFrame
, resourceId.group, resourceId.id));
if (reply.empty()) {
LOGTHROW(err2, std::runtime_error)
Expand All @@ -81,26 +81,26 @@ std::string Mapproxy::url(const Resource::Id &resourceId) const

std::uint64_t Mapproxy::updateResources()
{
auto reply(ctrl_.command("update-resources"));
auto reply(ctrl_->command("update-resources"));
if (reply.size() < 2) { return 0; }
return boost::lexical_cast<std::uint64_t>(reply[1]);
}

bool Mapproxy::updatedSince(std::uint64_t timestamp) const
{
const auto reply(ctrl_.command("updated-since", timestamp));
const auto reply(ctrl_->command("updated-since", timestamp));
if (reply.empty()) {
LOGTHROW(err2, std::runtime_error)
<< "Invalid reply from mapproxy.";
}

return ctrl_.parseBoolean(reply.front());
return ctrl_->parseBoolean(reply.front());
}

bool Mapproxy::updatedSince(const Resource::Id &resourceId
, std::uint64_t timestamp, bool nothrow) const
{
const auto reply(ctrl_.command("updated-since", timestamp
const auto reply(ctrl_->command("updated-since", timestamp
, resourceId.referenceFrame
, resourceId.group, resourceId.id
, nothrow ? "true" : "false"));
Expand All @@ -109,5 +109,5 @@ bool Mapproxy::updatedSince(const Resource::Id &resourceId
<< "Invalid reply from mapproxy.";
}

return ctrl_.parseBoolean(reply.front());
return ctrl_->parseBoolean(reply.front());
}
7 changes: 3 additions & 4 deletions mapproxy/src/mapproxy/mapproxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
*/
class Mapproxy {
public:
Mapproxy(const boost::filesystem::path &ctrl)
: ctrl_(ctrl)
Mapproxy(const std::string &ctrl)
: ctrl_(service::ctrlClientFactory(ctrl))
{}

/** Is given reference frame supported?
Expand Down Expand Up @@ -77,8 +77,7 @@ class Mapproxy {
const;

private:
// mutable because we want to mark non-changing functions as const
mutable service::CtrlClient ctrl_;
std::shared_ptr<service::CtrlClientBase> ctrl_;
};


Expand Down
2 changes: 1 addition & 1 deletion mapproxy/src/mapproxy/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ set(generate-tileindex_SOURCES

add_executable(mapproxy-generate-tileindex ${generate-tileindex_SOURCES})
target_link_libraries(mapproxy-generate-tileindex ${MODULE_LIBRARIES})
buildsys_target_compile_definitions(mapproxy-generate-tileindex ${MODULE_DEFINITIONS})
target_compile_definitions(mapproxy-generate-tileindex PRIVATE ${MODULE_DEFINITIONS})
buildsys_binary(mapproxy-generate-tileindex)
set_target_version(mapproxy-generate-tileindex ${vts-mapproxy_VERSION})
2 changes: 1 addition & 1 deletion mapproxy/src/rf-mask/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set(rf-mask_SOURCES

add_executable(mapproxy-rf-mask ${rf-mask_SOURCES})
target_link_libraries(mapproxy-rf-mask ${MODULE_LIBRARIES})
buildsys_target_compile_definitions(mapproxy-rf-mask ${MODULE_DEFINITIONS})
target_compile_definitions(mapproxy-rf-mask PRIVATE ${MODULE_DEFINITIONS})
buildsys_binary(mapproxy-rf-mask)
set_target_version(mapproxy-rf-mask ${vts-mapproxy_VERSION})

Expand Down
2 changes: 1 addition & 1 deletion mapproxy/src/setup-resource/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set(setup-resource_SOURCES

add_executable(mapproxy-setup-resource ${setup-resource_SOURCES})
target_link_libraries(mapproxy-setup-resource ${MODULE_LIBRARIES})
buildsys_target_compile_definitions(mapproxy-setup-resource ${MODULE_DEFINITIONS})
target_compile_definitions(mapproxy-setup-resource PRIVATE ${MODULE_DEFINITIONS})
buildsys_binary(mapproxy-setup-resource)
set_target_version(mapproxy-setup-resource ${vts-mapproxy_VERSION})

Expand Down
47 changes: 39 additions & 8 deletions mapproxy/src/setup-resource/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ namespace ba = boost::algorithm;

namespace vts = vtslibs::vts;
namespace vr = vtslibs::registry;
namespace vs = vtslibs::storage;

UTILITY_GENERATE_ENUM_CI(ResourceType,
((tms)("TMS"))
Expand All @@ -92,6 +93,7 @@ struct Config {
boost::optional<geo::GeoDataset::Resampling> tmsResampling;
bool transparent;
std::vector<std::string> attributions;
vs::CreditIds credits;
boost::optional<vts::Lod> bottomLod;

vrtwo::Color::optional background;
Expand All @@ -100,10 +102,14 @@ struct Config {

fs::path mapproxyDataRoot;
fs::path mapproxyDefinitionDir;
fs::path mapproxyCtrl;
std::string mapproxyCtrl;

bool parallel = true;

struct {
boost::optional<fs::path> datasetHome;
} override;

Config()
: format(RasterFormat::jpg)
, transparent(false)
Expand Down Expand Up @@ -146,6 +152,7 @@ void SetupResource::configuration(po::options_description &cmdline
, po::positional_options_description &pd)
{
vr::registryConfiguration(config, vr::defaultPath());
vr::creditsConfiguration(cmdline);

cmdline.add_options()
("referenceFrame", po::value(&resourceId_.referenceFrame)->required()
Expand Down Expand Up @@ -187,14 +194,18 @@ void SetupResource::configuration(po::options_description &cmdline
->default_value(config_.autoCreditId)->required()
, "First numeric ID of the auto-generated credits.")

("attribution", po::value(&config_.attributions)->required()
, "Atribution text, one per attribution. "
"At least one attribution is required.")
("attribution", po::value(&config_.attributions)
, "Attribution text, one per attribution. "
"At least one attribution/credits is required.")

("bottomLod", po::value<vts::Lod>()
, "Desired bottom LOD. The actual bottom might be deeper in "
"case of more detail dataset.")

("override.datasetHome", po::value<fs::path>()
, "Dataset home path override if the default is undesirable. "
"Relative to --dataRoot. Use with caution.")

("background", po::value<vrtwo::Color>()
, "Optional background. If whole warped tile contains this "
"color it is left empty in the output. Solid dataset with this color "
Expand All @@ -215,7 +226,7 @@ void SetupResource::configuration(po::options_description &cmdline
, po::value(&config_.mapproxyDefinitionDir)->required()
, "Path to mapproxy resource definition directory.")
("mapproxy.ctrl", po::value(&config_.mapproxyCtrl)->required()
, "Path to mapproxy control socket.")
, "Mapproxy control socket path/CTRL URI.")
;

pd.add("dataset", 1)
Expand All @@ -227,6 +238,11 @@ void SetupResource::configuration(po::options_description &cmdline
void SetupResource::configure(const po::variables_map &vars)
{
vr::registryConfigure(vars);
config_.credits = vr::creditsConfigure(vars);

if (config_.attributions.empty() && config_.credits.empty()) {
throw po::required_option("attribution-or-credits");
}

if (vars.count("resourceType")) {
resourceType_ = vars["resourceType"].as<ResourceType>();
Expand All @@ -249,6 +265,11 @@ void SetupResource::configure(const po::variables_map &vars)
config_.background = vars["background"].as<vrtwo::Color>();
}

if (vars.count("override.datasetHome")) {
config_.override.datasetHome = vars["override.datasetHome"]
.as<fs::path>();
}

// absolutize destination paths
config_.mapproxyDataRoot = fs::absolute(config_.mapproxyDataRoot);
config_.mapproxyDefinitionDir
Expand Down Expand Up @@ -723,6 +744,14 @@ void addCredits(Resource &r, const vr::Credit::dict &credits)
r.registry.credits.update(credits);
}

void addCredits(Resource &r, const vs::CreditIds &credits)
{
for (const auto &creditId : credits) {
r.credits.insert
(DualId(vr::system.credits(creditId).id, creditId));
}
}

std::string md5sum(const fs::path &path)
{
utility::ifstreambuf f(path.string());
Expand Down Expand Up @@ -827,8 +856,9 @@ int SetupResource::run()
const auto datasetFileName(fs::path(dataset_).filename());

const auto datasetHome
(utility::addExtension(datasetFileName
, "." + md5sum(dataset_)));
(config_.override.datasetHome.value_or
(utility::addExtension(datasetFileName
, "." + md5sum(dataset_))));

const auto rootDir(config.mapproxyDataRoot / datasetHome);
const auto baseDatasetPath("original-dataset" / datasetFileName);
Expand All @@ -851,7 +881,7 @@ int SetupResource::run()

if (linkDataset_ == DatasetLink::relative) {
// relativize already absolute path
dst = utility::lexically_relative(dst, rootDir);
dst = dst.lexically_relative(rootDir / ".");
}

// link
Expand Down Expand Up @@ -902,6 +932,7 @@ int SetupResource::run()

// add credits
addCredits(r, credits);
addCredits(r, config_.credits);

r.lodRange = cm.lodRange;
r.tileRange = cm.tileRange;
Expand Down
Loading

0 comments on commit cea2845

Please sign in to comment.