port latest changes from "raster_overzoom_quest" branch.

This commit is contained in:
artemp 2017-05-12 15:37:12 +02:00
parent 88fb137061
commit 5d48d98697
2 changed files with 349 additions and 381 deletions

View file

@ -187,19 +187,9 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
int width = end_x - x_off;
int height = end_y - y_off;
// don't process almost invisible data
if (box.width() < 0.5)
{
width = 0;
}
if (box.height() < 0.5)
{
height = 0;
}
//calculate actual box2d of returned raster
box2d<double> feature_raster_extent(x_off, y_off, x_off + width, y_off + height);
intersect = t.backward(feature_raster_extent);
feature_raster_extent = t.backward(feature_raster_extent);
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Raster extent=" << raster_extent_;
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: View extent=" << intersect;
@ -208,26 +198,7 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
if (width > 0 && height > 0)
{
double width_res = std::get<0>(q.resolution());
double height_res = std::get<1>(q.resolution());
int im_width = int(width_res * intersect.width() + 0.5);
int im_height = int(height_res * intersect.height() + 0.5);
double filter_factor = q.get_filter_factor();
im_width = int(im_width * filter_factor + 0.5);
im_height = int(im_height * filter_factor + 0.5);
// case where we need to avoid upsampling so that the
// image can be later scaled within raster_symbolizer
if (im_width >= width || im_height >= height)
{
im_width = width;
im_height = height;
}
if (im_width > 0 && im_height > 0)
{
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Image Size=(" << im_width << "," << im_height << ")";
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Image Size=(" << width << "," << height << ")";
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Reading band=" << band_;
if (band_ > 0) // we are querying a single band
{
@ -243,7 +214,7 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
{
case GDT_Byte:
{
mapnik::image_gray8 image(im_width, im_height);
mapnik::image_gray8 image(width, height);
image.set(std::numeric_limits<std::uint8_t>::max());
raster_nodata = band->GetNoDataValue(&raster_has_nodata);
raster_io_error = band->RasterIO(GF_Read, x_off, y_off, width, height,
@ -253,7 +224,7 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
{
throw datasource_exception(CPLGetLastErrorMsg());
}
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(intersect, image, filter_factor);
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(feature_raster_extent, intersect, image, 0.0);
// set nodata value to be used in raster colorizer
if (nodata_value_) raster->set_nodata(*nodata_value_);
else raster->set_nodata(raster_nodata);
@ -263,7 +234,7 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
case GDT_Float64:
case GDT_Float32:
{
mapnik::image_gray32f image(im_width, im_height);
mapnik::image_gray32f image(width, height);
image.set(std::numeric_limits<float>::max());
raster_nodata = band->GetNoDataValue(&raster_has_nodata);
raster_io_error = band->RasterIO(GF_Read, x_off, y_off, width, height,
@ -273,7 +244,7 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
{
throw datasource_exception(CPLGetLastErrorMsg());
}
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(intersect, image, filter_factor);
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(feature_raster_extent, intersect, image, 0.0);
// set nodata value to be used in raster colorizer
if (nodata_value_) raster->set_nodata(*nodata_value_);
else raster->set_nodata(raster_nodata);
@ -282,7 +253,7 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
}
case GDT_UInt16:
{
mapnik::image_gray16 image(im_width, im_height);
mapnik::image_gray16 image(width, height);
image.set(std::numeric_limits<std::uint16_t>::max());
raster_nodata = band->GetNoDataValue(&raster_has_nodata);
raster_io_error = band->RasterIO(GF_Read, x_off, y_off, width, height,
@ -292,7 +263,7 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
{
throw datasource_exception(CPLGetLastErrorMsg());
}
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(intersect, image, filter_factor);
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(feature_raster_extent, intersect, image, 0.0);
// set nodata value to be used in raster colorizer
if (nodata_value_) raster->set_nodata(*nodata_value_);
else raster->set_nodata(raster_nodata);
@ -302,7 +273,7 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
default:
case GDT_Int16:
{
mapnik::image_gray16s image(im_width, im_height);
mapnik::image_gray16s image(width, height);
image.set(std::numeric_limits<std::int16_t>::max());
raster_nodata = band->GetNoDataValue(&raster_has_nodata);
raster_io_error = band->RasterIO(GF_Read, x_off, y_off, width, height,
@ -312,7 +283,7 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
{
throw datasource_exception(CPLGetLastErrorMsg());
}
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(intersect, image, filter_factor);
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(feature_raster_extent, intersect, image, 0.0);
// set nodata value to be used in raster colorizer
if (nodata_value_) raster->set_nodata(*nodata_value_);
else raster->set_nodata(raster_nodata);
@ -323,7 +294,7 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
}
else // working with all bands
{
mapnik::image_rgba8 image(im_width, im_height);
mapnik::image_rgba8 image(width, height);
image.set(std::numeric_limits<std::uint32_t>::max());
for (int i = 0; i < nbands_; ++i)
{
@ -612,7 +583,7 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
}
}
}
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(intersect, image, filter_factor);
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(feature_raster_extent, intersect, image, 0.0);
// set nodata value to be used in raster colorizer
if (nodata_value_) raster->set_nodata(*nodata_value_);
else raster->set_nodata(raster_nodata);
@ -625,7 +596,6 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
}
return feature;
}
}
return feature_ptr();
}

View file

@ -96,6 +96,8 @@ feature_ptr raster_featureset<LookupPolicy>::next()
int end_y = static_cast<int>(std::ceil(ext.maxy()));
// clip to available data
if (x_off >= image_width) x_off = image_width - 1;
if (y_off >= image_width) y_off = image_width - 1;
if (x_off < 0) x_off = 0;
if (y_off < 0) y_off = 0;
if (end_x > image_width) end_x = image_width;
@ -103,12 +105,8 @@ feature_ptr raster_featureset<LookupPolicy>::next()
int width = end_x - x_off;
int height = end_y - y_off;
if (width < 1) {
width = 1;
}
if (height < 1) {
height = 1;
}
if (width < 1) width = 1;
if (height < 1) height = 1;
// calculate actual box2d of returned raster
box2d<double> feature_raster_extent(rem.minx() + x_off,