From e128d753667718b9af937bc2aeef52cf25f5f449 Mon Sep 17 00:00:00 2001 From: Blake Thompson Date: Fri, 30 Mar 2018 14:47:34 -0500 Subject: [PATCH] Make max_image_area a datasource parameter for GDAL. --- plugins/input/gdal/gdal_datasource.cpp | 13 +++++++++++-- plugins/input/gdal/gdal_datasource.hpp | 1 + plugins/input/gdal/gdal_featureset.cpp | 15 ++++++--------- plugins/input/gdal/gdal_featureset.hpp | 4 +++- test/data-visual | 2 +- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/plugins/input/gdal/gdal_datasource.cpp b/plugins/input/gdal/gdal_datasource.cpp index 2454ed65b..3baa92137 100644 --- a/plugins/input/gdal/gdal_datasource.cpp +++ b/plugins/input/gdal/gdal_datasource.cpp @@ -82,6 +82,13 @@ gdal_datasource::gdal_datasource(parameters const& params) shared_dataset_ = *params.get("shared", false); band_ = *params.get("band", -1); + + // Maximum memory limitation for image will be simply based on the maximum + // area we allow for an image. The true memory footprint therefore will vary based + // on the type of imagery that exists. This is not the maximum size of an image + // on disk but rather the maximum size we will load into mapnik from GDAL. + // max_im_area based on 50 mb limit for RGBA + max_image_area_ = *params.get("max_image_area", (50*1024*1024) / 4); #if GDAL_VERSION_NUM >= 1600 if (shared_dataset_) @@ -235,7 +242,8 @@ featureset_ptr gdal_datasource::features(query const& q) const dx_, dy_, nodata_value_, - nodata_tolerance_); + nodata_tolerance_, + max_image_area_); } featureset_ptr gdal_datasource::features_at_point(coord2d const& pt, double tol) const @@ -254,5 +262,6 @@ featureset_ptr gdal_datasource::features_at_point(coord2d const& pt, double tol) dx_, dy_, nodata_value_, - nodata_tolerance_); + nodata_tolerance_, + max_image_area_); } diff --git a/plugins/input/gdal/gdal_datasource.hpp b/plugins/input/gdal/gdal_datasource.hpp index 3fc3036c8..05aba16fd 100644 --- a/plugins/input/gdal/gdal_datasource.hpp +++ b/plugins/input/gdal/gdal_datasource.hpp @@ -68,6 +68,7 @@ private: bool shared_dataset_; boost::optional nodata_value_; double nodata_tolerance_; + int64_t max_image_area_; }; #endif // GDAL_DATASOURCE_HPP diff --git a/plugins/input/gdal/gdal_featureset.cpp b/plugins/input/gdal/gdal_featureset.cpp index bd7d27e07..ca3e81510 100644 --- a/plugins/input/gdal/gdal_featureset.cpp +++ b/plugins/input/gdal/gdal_featureset.cpp @@ -89,7 +89,8 @@ gdal_featureset::gdal_featureset(GDALDataset& dataset, double dx, double dy, boost::optional const& nodata, - double nodata_tolerance) + double nodata_tolerance, + int64_t max_image_area) : dataset_(dataset), ctx_(std::make_shared()), band_(band), @@ -102,6 +103,7 @@ gdal_featureset::gdal_featureset(GDALDataset& dataset, nbands_(nbands), nodata_value_(nodata), nodata_tolerance_(nodata_tolerance), + max_image_area_(max_image_area), first_(true) { ctx_->push("nodata"); @@ -280,16 +282,11 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q) } } - // Maximum memory limitation for image will be simply based on the maximum - // area we allow for an image. The true memory footprint therefore will vary based - // on the type of imagery that exists. - // max_im_area based on 50 mb limit for RGBA - constexpr int64_t max_im_area = (50*1024*1024) / 4; int64_t im_area = (int64_t)im_width * (int64_t)im_height; - if (im_area > max_im_area) + if (im_area > max_image_area_) { - int adjusted_width = static_cast(std::round(std::sqrt(max_im_area * ((double)im_width / (double)im_height)))); - int adjusted_height = static_cast(std::round(std::sqrt(max_im_area * ((double)im_height / (double)im_width)))); + int adjusted_width = static_cast(std::round(std::sqrt(max_image_area_ * ((double)im_width / (double)im_height)))); + int adjusted_height = static_cast(std::round(std::sqrt(max_image_area_ * ((double)im_height / (double)im_width)))); if (adjusted_width < 1) { adjusted_width = 1; diff --git a/plugins/input/gdal/gdal_featureset.hpp b/plugins/input/gdal/gdal_featureset.hpp index f2f66f796..198d8a129 100644 --- a/plugins/input/gdal/gdal_featureset.hpp +++ b/plugins/input/gdal/gdal_featureset.hpp @@ -66,7 +66,8 @@ public: double dx, double dy, boost::optional const& nodata, - double nodata_tolerance); + double nodata_tolerance, + int64_t max_image_area); virtual ~gdal_featureset(); mapnik::feature_ptr next(); @@ -85,6 +86,7 @@ private: int nbands_; boost::optional nodata_value_; double nodata_tolerance_; + int64_t max_image_area_; bool first_; }; diff --git a/test/data-visual b/test/data-visual index 924e0bcf1..6ece97e8d 160000 --- a/test/data-visual +++ b/test/data-visual @@ -1 +1 @@ -Subproject commit 924e0bcf16a2607cc002517c1d4e98f67edcbd39 +Subproject commit 6ece97e8d43915527b4bd83507a9cd9ea9ef910e