From a217b38fd5873e977d3698b2b05e84c900fe9719 Mon Sep 17 00:00:00 2001 From: Blake Thompson Date: Fri, 30 Mar 2018 15:40:30 -0500 Subject: [PATCH] Updated to use max_image_area as a datasource parameter for GDAL plugin --- 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 | 2 +- test/data-visual | 2 +- 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/plugins/input/gdal/gdal_datasource.cpp b/plugins/input/gdal/gdal_datasource.cpp index a5a6fc535..f47c26331 100644 --- a/plugins/input/gdal/gdal_datasource.cpp +++ b/plugins/input/gdal/gdal_datasource.cpp @@ -84,6 +84,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_) @@ -237,7 +244,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 @@ -256,5 +264,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 7fc74975b..bbd2f7607 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 4363e2f93..7ec336f55 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"); @@ -278,16 +280,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 beabb7df1..325c6a999 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 b/test/data index 3a636431a..a44457cc0 160000 --- a/test/data +++ b/test/data @@ -1 +1 @@ -Subproject commit 3a636431ab189285378686c596be16a440c0808f +Subproject commit a44457cc063249e0d204cde7249d37706bf8844c diff --git a/test/data-visual b/test/data-visual index a6ec8c091..c113ce132 160000 --- a/test/data-visual +++ b/test/data-visual @@ -1 +1 @@ -Subproject commit a6ec8c0919eda8ac2f34ede5c4a53240d0bb275a +Subproject commit c113ce13267124332cc2ecd049d7d2d7397f9a51