Make max_image_area a datasource parameter for GDAL.
This commit is contained in:
parent
9bcd733def
commit
e128d75366
5 changed files with 22 additions and 13 deletions
|
@ -82,6 +82,13 @@ gdal_datasource::gdal_datasource(parameters const& params)
|
||||||
|
|
||||||
shared_dataset_ = *params.get<mapnik::boolean_type>("shared", false);
|
shared_dataset_ = *params.get<mapnik::boolean_type>("shared", false);
|
||||||
band_ = *params.get<mapnik::value_integer>("band", -1);
|
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 GDAL_VERSION_NUM >= 1600
|
||||||
if (shared_dataset_)
|
if (shared_dataset_)
|
||||||
|
@ -235,7 +242,8 @@ featureset_ptr gdal_datasource::features(query const& q) const
|
||||||
dx_,
|
dx_,
|
||||||
dy_,
|
dy_,
|
||||||
nodata_value_,
|
nodata_value_,
|
||||||
nodata_tolerance_);
|
nodata_tolerance_,
|
||||||
|
max_image_area_);
|
||||||
}
|
}
|
||||||
|
|
||||||
featureset_ptr gdal_datasource::features_at_point(coord2d const& pt, double tol) const
|
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_,
|
dx_,
|
||||||
dy_,
|
dy_,
|
||||||
nodata_value_,
|
nodata_value_,
|
||||||
nodata_tolerance_);
|
nodata_tolerance_,
|
||||||
|
max_image_area_);
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,7 @@ private:
|
||||||
bool shared_dataset_;
|
bool shared_dataset_;
|
||||||
boost::optional<double> nodata_value_;
|
boost::optional<double> nodata_value_;
|
||||||
double nodata_tolerance_;
|
double nodata_tolerance_;
|
||||||
|
int64_t max_image_area_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GDAL_DATASOURCE_HPP
|
#endif // GDAL_DATASOURCE_HPP
|
||||||
|
|
|
@ -89,7 +89,8 @@ gdal_featureset::gdal_featureset(GDALDataset& dataset,
|
||||||
double dx,
|
double dx,
|
||||||
double dy,
|
double dy,
|
||||||
boost::optional<double> const& nodata,
|
boost::optional<double> const& nodata,
|
||||||
double nodata_tolerance)
|
double nodata_tolerance,
|
||||||
|
int64_t max_image_area)
|
||||||
: dataset_(dataset),
|
: dataset_(dataset),
|
||||||
ctx_(std::make_shared<mapnik::context_type>()),
|
ctx_(std::make_shared<mapnik::context_type>()),
|
||||||
band_(band),
|
band_(band),
|
||||||
|
@ -102,6 +103,7 @@ gdal_featureset::gdal_featureset(GDALDataset& dataset,
|
||||||
nbands_(nbands),
|
nbands_(nbands),
|
||||||
nodata_value_(nodata),
|
nodata_value_(nodata),
|
||||||
nodata_tolerance_(nodata_tolerance),
|
nodata_tolerance_(nodata_tolerance),
|
||||||
|
max_image_area_(max_image_area),
|
||||||
first_(true)
|
first_(true)
|
||||||
{
|
{
|
||||||
ctx_->push("nodata");
|
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;
|
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_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_im_area * ((double)im_height / (double)im_width))));
|
int adjusted_height = static_cast<int>(std::round(std::sqrt(max_image_area_ * ((double)im_height / (double)im_width))));
|
||||||
if (adjusted_width < 1)
|
if (adjusted_width < 1)
|
||||||
{
|
{
|
||||||
adjusted_width = 1;
|
adjusted_width = 1;
|
||||||
|
|
|
@ -66,7 +66,8 @@ public:
|
||||||
double dx,
|
double dx,
|
||||||
double dy,
|
double dy,
|
||||||
boost::optional<double> const& nodata,
|
boost::optional<double> const& nodata,
|
||||||
double nodata_tolerance);
|
double nodata_tolerance,
|
||||||
|
int64_t max_image_area);
|
||||||
virtual ~gdal_featureset();
|
virtual ~gdal_featureset();
|
||||||
mapnik::feature_ptr next();
|
mapnik::feature_ptr next();
|
||||||
|
|
||||||
|
@ -85,6 +86,7 @@ private:
|
||||||
int nbands_;
|
int nbands_;
|
||||||
boost::optional<double> nodata_value_;
|
boost::optional<double> nodata_value_;
|
||||||
double nodata_tolerance_;
|
double nodata_tolerance_;
|
||||||
|
int64_t max_image_area_;
|
||||||
bool first_;
|
bool first_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 924e0bcf16a2607cc002517c1d4e98f67edcbd39
|
Subproject commit 6ece97e8d43915527b4bd83507a9cd9ea9ef910e
|
Loading…
Reference in a new issue