Updated to use max_image_area as a datasource parameter for GDAL plugin

This commit is contained in:
Blake Thompson 2018-03-30 15:40:30 -05:00
parent 25e4bb3f6c
commit a217b38fd5
6 changed files with 23 additions and 14 deletions

View file

@ -85,6 +85,13 @@ gdal_datasource::gdal_datasource(parameters const& params)
shared_dataset_ = *params.get<mapnik::boolean_type>("shared", false);
band_ = *params.get<mapnik::value_integer>("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<mapnik::value_integer>("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_);
}

View file

@ -68,6 +68,7 @@ private:
bool shared_dataset_;
boost::optional<double> nodata_value_;
double nodata_tolerance_;
int64_t max_image_area_;
};
#endif // GDAL_DATASOURCE_HPP

View file

@ -89,7 +89,8 @@ gdal_featureset::gdal_featureset(GDALDataset& dataset,
double dx,
double dy,
boost::optional<double> const& nodata,
double nodata_tolerance)
double nodata_tolerance,
int64_t max_image_area)
: dataset_(dataset),
ctx_(std::make_shared<mapnik::context_type>()),
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<int>(std::round(std::sqrt(max_im_area * ((double)im_width / (double)im_height))));
int adjusted_height = static_cast<int>(std::round(std::sqrt(max_im_area * ((double)im_height / (double)im_width))));
int adjusted_width = static_cast<int>(std::round(std::sqrt(max_image_area_ * ((double)im_width / (double)im_height))));
int adjusted_height = static_cast<int>(std::round(std::sqrt(max_image_area_ * ((double)im_height / (double)im_width))));
if (adjusted_width < 1)
{
adjusted_width = 1;

View file

@ -66,7 +66,8 @@ public:
double dx,
double dy,
boost::optional<double> 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<double> nodata_value_;
double nodata_tolerance_;
int64_t max_image_area_;
bool first_;
};

@ -1 +1 @@
Subproject commit 3a636431ab189285378686c596be16a440c0808f
Subproject commit a44457cc063249e0d204cde7249d37706bf8844c

@ -1 +1 @@
Subproject commit a6ec8c0919eda8ac2f34ede5c4a53240d0bb275a
Subproject commit c113ce13267124332cc2ecd049d7d2d7397f9a51