Merge pull request #3939 from mapycz/v3.0.x-fix-overviews
v3.0.x: GDAL: Fixes of overviews
This commit is contained in:
commit
cabcc079ff
4 changed files with 66 additions and 55 deletions
|
@ -124,6 +124,33 @@ feature_ptr gdal_featureset::next()
|
|||
return feature_ptr();
|
||||
}
|
||||
|
||||
void gdal_featureset::find_best_overview(int bandNumber,
|
||||
int ideal_width,
|
||||
int ideal_height,
|
||||
int & current_width,
|
||||
int & current_height) const
|
||||
{
|
||||
GDALRasterBand * band = dataset_.GetRasterBand(bandNumber);
|
||||
int band_overviews = band->GetOverviewCount();
|
||||
if (band_overviews > 0)
|
||||
{
|
||||
for (int b = 0; b < band_overviews; b++)
|
||||
{
|
||||
GDALRasterBand * overview = band->GetOverview(b);
|
||||
int overview_width = overview->GetXSize();
|
||||
int overview_height = overview->GetYSize();
|
||||
if ((overview_width < current_width ||
|
||||
overview_height < current_height) &&
|
||||
ideal_width <= overview_width &&
|
||||
ideal_height <= overview_height)
|
||||
{
|
||||
current_width = overview_width;
|
||||
current_height = overview_height;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
||||
{
|
||||
feature_ptr feature = feature_factory::create(ctx_,1);
|
||||
|
@ -208,77 +235,55 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
|||
int im_width = width;
|
||||
double im_offset_x = x_off;
|
||||
double im_offset_y = y_off;
|
||||
int current_width = (int)raster_width_;
|
||||
int current_height = (int)raster_height_;
|
||||
int current_width = static_cast<int>(raster_width_);
|
||||
int current_height = static_cast<int>(raster_height_);
|
||||
|
||||
// loop through overviews -- snap up in resolution to closest overview
|
||||
// if necessary we find an image size that most resembles
|
||||
// the resolution of our output image.
|
||||
const double width_res = std::get<0>(q.resolution());
|
||||
const double height_res = std::get<1>(q.resolution());
|
||||
const int ideal_raster_width = static_cast<int>(
|
||||
std::floor(raster_extent_.width() *
|
||||
width_res * filter_factor) + .5);
|
||||
const int ideal_raster_height = static_cast<int>(
|
||||
std::floor(raster_extent_.height() *
|
||||
height_res * filter_factor) + .5);
|
||||
|
||||
// loop through overviews -- snap up in resolution to closest overview if necessary
|
||||
// we find an image size that most resembles the resolution of our output image.
|
||||
double width_res = std::get<0>(q.resolution());
|
||||
double height_res = std::get<1>(q.resolution());
|
||||
int res_adjusted_raster_width = static_cast<int>(std::floor(((double)raster_width_ * width_res) + .5));
|
||||
int res_adjusted_raster_height = static_cast<int>(std::floor(((double)raster_height_ * height_res) + .5));
|
||||
if (band_ > 0 && band_ < nbands_)
|
||||
{
|
||||
GDALRasterBand * band = dataset_.GetRasterBand(band_);
|
||||
int band_overviews = band->GetOverviewCount();
|
||||
if (band_overviews > 0)
|
||||
{
|
||||
for (int b = 0; b < band_overviews; b++)
|
||||
{
|
||||
GDALRasterBand * overview = band->GetOverview(b);
|
||||
int overview_width = overview->GetXSize();
|
||||
int overview_height = overview->GetYSize();
|
||||
if ((overview_width < current_width || overview_height < current_height) &&
|
||||
res_adjusted_raster_width <= overview_width &&
|
||||
res_adjusted_raster_height <= overview_height)
|
||||
{
|
||||
current_width = overview_width;
|
||||
current_height = overview_height;
|
||||
}
|
||||
}
|
||||
}
|
||||
find_best_overview(band_,
|
||||
ideal_raster_width,
|
||||
ideal_raster_height,
|
||||
current_width,
|
||||
current_height);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < nbands_; ++i)
|
||||
{
|
||||
GDALRasterBand * band = dataset_.GetRasterBand(i + 1);
|
||||
int band_overviews = band->GetOverviewCount();
|
||||
if (band_overviews > 0)
|
||||
{
|
||||
for (int b = 0; b < band_overviews; b++)
|
||||
{
|
||||
GDALRasterBand * overview = band->GetOverview(b);
|
||||
int overview_width = overview->GetXSize();
|
||||
int overview_height = overview->GetYSize();
|
||||
if ((overview_width < current_width || overview_height < current_height) &&
|
||||
res_adjusted_raster_width <= overview_width &&
|
||||
res_adjusted_raster_height <= overview_height)
|
||||
{
|
||||
current_width = overview_width;
|
||||
current_height = overview_height;
|
||||
}
|
||||
}
|
||||
}
|
||||
find_best_overview(i + 1,
|
||||
ideal_raster_width,
|
||||
ideal_raster_height,
|
||||
current_width,
|
||||
current_height);
|
||||
}
|
||||
}
|
||||
if (current_width != (int)raster_width_ || current_height != (int)raster_height_)
|
||||
|
||||
if (current_width != (int)raster_width_ ||
|
||||
current_height != (int)raster_height_)
|
||||
{
|
||||
if (current_width != (int)raster_width_)
|
||||
{
|
||||
double ratio = (double)current_width / (double)raster_width_;
|
||||
int adjusted_width = static_cast<int>(std::floor((ratio * im_width) + 0.5));
|
||||
double adjusted_ratio = (double)adjusted_width / (double)im_width;
|
||||
im_offset_x = adjusted_ratio * im_offset_x;
|
||||
im_width = adjusted_width;
|
||||
im_offset_x = std::floor(ratio * im_offset_x);
|
||||
im_width = static_cast<int>(std::ceil(ratio * im_width));
|
||||
}
|
||||
if (current_height != (int)raster_height_)
|
||||
{
|
||||
double ratio = (double)current_height / (double)raster_height_;
|
||||
int adjusted_height = static_cast<int>(std::floor((ratio * im_height) + 0.5));
|
||||
double adjusted_ratio = (double)adjusted_height / (double)im_height;
|
||||
im_offset_y = adjusted_ratio * im_offset_y;
|
||||
im_height = adjusted_height;
|
||||
im_offset_y = std::floor(ratio * im_offset_y);
|
||||
im_height = static_cast<int>(std::ceil(ratio * im_height));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -72,6 +72,12 @@ public:
|
|||
mapnik::feature_ptr next();
|
||||
|
||||
private:
|
||||
void find_best_overview(int bandNumber,
|
||||
int ideal_width,
|
||||
int ideal_height,
|
||||
int & current_width,
|
||||
int & current_height) const;
|
||||
|
||||
mapnik::feature_ptr get_feature(mapnik::query const& q);
|
||||
mapnik::feature_ptr get_feature_at_point(mapnik::coord2d const& p);
|
||||
GDALDataset & dataset_;
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 18f610c211efa95c9d689e350d7ebe635d9c0b36
|
||||
Subproject commit 4de7fe7a00e4e269cdaeb2fd0b69c4bfa4a6a61f
|
|
@ -1 +1 @@
|
|||
Subproject commit 6ece97e8d43915527b4bd83507a9cd9ea9ef910e
|
||||
Subproject commit 13163a419eec939d189a371427022402b98bb08a
|
Loading…
Reference in a new issue