+add support for better resampling when using bilinear scaling with gdal plugin (with or without overviews)

This commit is contained in:
Dane Springmeyer 2010-06-20 04:06:23 +00:00
parent 182628e3ab
commit 4707e1a6f3
4 changed files with 29 additions and 9 deletions

View file

@ -64,7 +64,8 @@ inline GDALDataset *gdal_datasource::open_dataset() const
gdal_datasource::gdal_datasource(parameters const& params)
: datasource(params),
desc_(*params.get<std::string>("type"),"utf-8")
desc_(*params.get<std::string>("type"),"utf-8"),
filter_factor_(*params_.get<double>("filter_factor",0.0))
{
#ifdef MAPNIK_DEBUG
@ -134,11 +135,11 @@ layer_descriptor gdal_datasource::get_descriptor() const
featureset_ptr gdal_datasource::features(query const& q) const
{
gdal_query gq = q;
return featureset_ptr(new gdal_featureset(*open_dataset(), band_, gq));
return featureset_ptr(new gdal_featureset(*open_dataset(), band_, gq, filter_factor_));
}
featureset_ptr gdal_datasource::features_at_point(coord2d const& pt) const
{
gdal_query gq = pt;
return featureset_ptr(new gdal_featureset(*open_dataset(), band_, gq));
return featureset_ptr(new gdal_featureset(*open_dataset(), band_, gq, filter_factor_));
}

View file

@ -47,6 +47,7 @@ class gdal_datasource : public mapnik::datasource
unsigned width_;
unsigned height_;
bool shared_dataset_;
double filter_factor_;
inline GDALDataset *open_dataset() const;
};

View file

@ -37,10 +37,11 @@ using mapnik::point_impl;
using mapnik::geometry2d;
gdal_featureset::gdal_featureset(GDALDataset & dataset, int band, gdal_query q)
gdal_featureset::gdal_featureset(GDALDataset & dataset, int band, gdal_query q, double filter_factor)
: dataset_(dataset),
band_(band),
gquery_(q),
filter_factor_(filter_factor),
first_(true) {}
gdal_featureset::~gdal_featureset()
@ -149,11 +150,27 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
if (width > 0 && height > 0)
{
int im_width = int(boost::get<0>(q.resolution()) * intersect.width() + 0.5);
int im_height = int(boost::get<1>(q.resolution()) * intersect.height() + 0.5);
double width_res = boost::get<0>(q.resolution());
double height_res = boost::get<1>(q.resolution());
int im_width = int(width_res * intersect.width() + 0.5);
int im_height = int(height_res * intersect.height() + 0.5);
// if layer-level filter_factor is set, apply it
if (filter_factor_)
{
im_width *= filter_factor_;
im_height *= filter_factor_;
}
// otherwise respect symbolizer level factor applied to query, default of 1.0
else
{
double sym_downsample_factor = q.get_filter_factor();
im_width *= sym_downsample_factor;
im_height *= sym_downsample_factor;
}
// case where we need to avoid upsampling so that the
// image can be later scaled within raster_symbolizer
// image can be later scaled within raster_symbolizer
if (im_width >= width || im_height >= height)
{
im_width = width;

View file

@ -36,7 +36,7 @@ class gdal_featureset : public mapnik::Featureset
{
public:
gdal_featureset(GDALDataset & dataset, int band, gdal_query q);
gdal_featureset(GDALDataset & dataset, int band, gdal_query q, double filter_factor);
virtual ~gdal_featureset();
mapnik::feature_ptr next();
private:
@ -46,6 +46,7 @@ class gdal_featureset : public mapnik::Featureset
GDALDataset & dataset_;
int band_;
gdal_query gquery_;
double filter_factor_;
bool first_;
};