2007-04-25 19:15:38 +00:00
|
|
|
/*****************************************************************************
|
2011-11-14 03:37:50 +00:00
|
|
|
*
|
2007-04-25 19:15:38 +00:00
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
2015-06-16 10:49:16 +00:00
|
|
|
* Copyright (C) 2015 Artem Pavlenko
|
2007-04-25 19:15:38 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2011-05-16 22:17:50 +00:00
|
|
|
// mapnik
|
2016-03-03 00:48:07 +00:00
|
|
|
#include <mapnik/datasource.hpp>
|
2011-11-08 11:50:56 +00:00
|
|
|
#include <mapnik/global.hpp>
|
2012-04-08 00:20:56 +00:00
|
|
|
#include <mapnik/debug.hpp>
|
2015-01-22 17:39:37 +00:00
|
|
|
#include <mapnik/image.hpp>
|
2013-01-04 17:23:06 +00:00
|
|
|
#include <mapnik/raster.hpp>
|
2014-08-28 09:29:04 +00:00
|
|
|
#include <mapnik/view_transform.hpp>
|
2013-01-04 17:23:06 +00:00
|
|
|
#include <mapnik/feature.hpp>
|
2011-05-16 22:17:50 +00:00
|
|
|
#include <mapnik/feature_factory.hpp>
|
2014-10-01 01:35:07 +00:00
|
|
|
|
2013-01-17 21:53:48 +00:00
|
|
|
// stl
|
|
|
|
#include <cmath>
|
2014-01-18 03:13:53 +00:00
|
|
|
#include <memory>
|
2014-10-01 01:35:07 +00:00
|
|
|
#include <sstream>
|
2013-01-17 21:53:48 +00:00
|
|
|
|
2012-04-08 00:20:56 +00:00
|
|
|
#include "gdal_featureset.hpp"
|
|
|
|
#include <gdal_priv.h>
|
|
|
|
|
2009-12-16 20:02:06 +00:00
|
|
|
using mapnik::box2d;
|
2007-04-25 19:15:38 +00:00
|
|
|
using mapnik::feature_ptr;
|
2014-08-28 09:17:15 +00:00
|
|
|
using mapnik::view_transform;
|
2010-09-19 17:52:17 +00:00
|
|
|
using mapnik::datasource_exception;
|
2011-05-16 22:17:50 +00:00
|
|
|
using mapnik::feature_factory;
|
2007-04-25 19:15:38 +00:00
|
|
|
|
2016-06-13 09:14:59 +00:00
|
|
|
#ifdef MAPNIK_LOG
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
void get_overview_meta(GDALRasterBand* band)
|
|
|
|
{
|
|
|
|
int band_overviews = band->GetOverviewCount();
|
|
|
|
if (band_overviews > 0)
|
|
|
|
{
|
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: " << band_overviews << " overviews found!";
|
|
|
|
|
|
|
|
for (int b = 0; b < band_overviews; b++)
|
|
|
|
{
|
|
|
|
GDALRasterBand * overview = band->GetOverview(b);
|
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "Overview= " << b
|
|
|
|
<< " Width=" << overview->GetXSize()
|
|
|
|
<< " Height=" << overview->GetYSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: No overviews found!";
|
|
|
|
}
|
|
|
|
|
|
|
|
int bsx,bsy;
|
|
|
|
double scale;
|
|
|
|
band->GetBlockSize(&bsx, &bsy);
|
|
|
|
scale = band->GetScale();
|
|
|
|
|
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "Block=" << bsx << "x" << bsy
|
|
|
|
<< " Scale=" << scale
|
|
|
|
<< " Type=" << GDALGetDataTypeName(band->GetRasterDataType())
|
|
|
|
<< "Color=" << GDALGetColorInterpretationName(band->GetColorInterpretation());
|
|
|
|
}
|
|
|
|
} // anonymous ns
|
|
|
|
#endif
|
2011-10-22 00:46:29 +00:00
|
|
|
gdal_featureset::gdal_featureset(GDALDataset& dataset,
|
|
|
|
int band,
|
|
|
|
gdal_query q,
|
|
|
|
mapnik::box2d<double> extent,
|
2012-08-15 19:37:17 +00:00
|
|
|
unsigned width,
|
|
|
|
unsigned height,
|
2011-10-22 00:46:29 +00:00
|
|
|
int nbands,
|
|
|
|
double dx,
|
|
|
|
double dy,
|
2014-01-18 03:13:53 +00:00
|
|
|
boost::optional<double> const& nodata,
|
|
|
|
double nodata_tolerance)
|
2011-11-14 03:37:50 +00:00
|
|
|
: dataset_(dataset),
|
2013-09-20 13:00:11 +00:00
|
|
|
ctx_(std::make_shared<mapnik::context_type>()),
|
2011-11-14 03:37:50 +00:00
|
|
|
band_(band),
|
|
|
|
gquery_(q),
|
|
|
|
raster_extent_(extent),
|
|
|
|
raster_width_(width),
|
|
|
|
raster_height_(height),
|
|
|
|
dx_(dx),
|
|
|
|
dy_(dy),
|
|
|
|
nbands_(nbands),
|
2012-04-03 23:06:36 +00:00
|
|
|
nodata_value_(nodata),
|
2014-01-18 03:13:53 +00:00
|
|
|
nodata_tolerance_(nodata_tolerance),
|
2012-01-17 22:58:00 +00:00
|
|
|
first_(true)
|
2010-11-14 14:54:28 +00:00
|
|
|
{
|
2013-09-25 21:37:21 +00:00
|
|
|
ctx_->push("nodata");
|
2010-11-14 14:54:28 +00:00
|
|
|
}
|
2007-04-25 19:15:38 +00:00
|
|
|
|
2010-05-30 03:23:59 +00:00
|
|
|
gdal_featureset::~gdal_featureset()
|
|
|
|
{
|
|
|
|
}
|
2007-04-25 19:15:38 +00:00
|
|
|
|
|
|
|
feature_ptr gdal_featureset::next()
|
|
|
|
{
|
2010-02-03 16:56:42 +00:00
|
|
|
if (first_)
|
|
|
|
{
|
2010-08-18 20:42:00 +00:00
|
|
|
first_ = false;
|
2012-04-09 01:00:51 +00:00
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Next feature in Dataset=" << &dataset_;
|
2014-08-12 12:40:45 +00:00
|
|
|
return mapnik::util::apply_visitor(query_dispatch(*this), gquery_);
|
2010-02-03 16:56:42 +00:00
|
|
|
}
|
|
|
|
return feature_ptr();
|
2009-09-27 17:23:09 +00:00
|
|
|
}
|
2009-05-15 10:31:49 +00:00
|
|
|
|
2009-09-27 17:23:09 +00:00
|
|
|
feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
|
|
|
{
|
2012-01-16 22:55:44 +00:00
|
|
|
feature_ptr feature = feature_factory::create(ctx_,1);
|
2013-09-25 21:37:21 +00:00
|
|
|
int raster_has_nodata = 0;
|
|
|
|
double raster_nodata = 0;
|
2010-02-03 16:56:42 +00:00
|
|
|
GDALRasterBand * red = 0;
|
|
|
|
GDALRasterBand * green = 0;
|
|
|
|
GDALRasterBand * blue = 0;
|
|
|
|
GDALRasterBand * alpha = 0;
|
2011-11-14 03:37:50 +00:00
|
|
|
GDALRasterBand * grey = 0;
|
2014-10-31 03:32:56 +00:00
|
|
|
CPLErr raster_io_error = CE_None;
|
2012-02-02 01:37:35 +00:00
|
|
|
|
2010-09-18 19:19:27 +00:00
|
|
|
/*
|
2012-04-09 10:05:49 +00:00
|
|
|
#ifdef MAPNIK_LOG
|
2011-11-14 03:37:50 +00:00
|
|
|
double tr[6];
|
|
|
|
dataset_.GetGeoTransform(tr);
|
|
|
|
|
2012-04-09 01:00:51 +00:00
|
|
|
const double dx = tr[1];
|
|
|
|
const double dy = tr[5];
|
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: dx_=" << dx_ << " dx=" << dx << " dy_=" << dy_ << "dy=" << dy;
|
2012-04-08 00:20:56 +00:00
|
|
|
#endif
|
2010-09-18 19:19:27 +00:00
|
|
|
*/
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2014-08-28 09:17:15 +00:00
|
|
|
view_transform t(raster_width_, raster_height_, raster_extent_, 0, 0);
|
2010-09-18 19:19:27 +00:00
|
|
|
box2d<double> intersect = raster_extent_.intersect(q.get_bbox());
|
2010-02-03 16:56:42 +00:00
|
|
|
box2d<double> box = t.forward(intersect);
|
2009-09-27 17:23:09 +00:00
|
|
|
|
2010-03-17 08:34:43 +00:00
|
|
|
//size of resized output pixel in source image domain
|
2013-10-11 11:35:34 +00:00
|
|
|
double margin_x = 1.0 / (std::fabs(dx_) * std::get<0>(q.resolution()));
|
|
|
|
double margin_y = 1.0 / (std::fabs(dy_) * std::get<1>(q.resolution()));
|
2010-03-17 08:34:43 +00:00
|
|
|
if (margin_x < 1)
|
2011-10-22 00:46:29 +00:00
|
|
|
{
|
2010-03-17 08:34:43 +00:00
|
|
|
margin_x = 1.0;
|
2011-10-22 00:46:29 +00:00
|
|
|
}
|
2010-03-17 08:34:43 +00:00
|
|
|
if (margin_y < 1)
|
2011-10-22 00:46:29 +00:00
|
|
|
{
|
2010-03-17 08:34:43 +00:00
|
|
|
margin_y = 1.0;
|
2011-10-22 00:46:29 +00:00
|
|
|
}
|
|
|
|
|
2010-03-03 03:23:53 +00:00
|
|
|
//select minimum raster containing whole box
|
2010-03-17 08:34:43 +00:00
|
|
|
int x_off = rint(box.minx() - margin_x);
|
|
|
|
int y_off = rint(box.miny() - margin_y);
|
|
|
|
int end_x = rint(box.maxx() + margin_x);
|
|
|
|
int end_y = rint(box.maxy() + margin_y);
|
2011-10-22 00:46:29 +00:00
|
|
|
|
2010-03-03 03:23:53 +00:00
|
|
|
//clip to available data
|
|
|
|
if (x_off < 0)
|
2011-10-22 00:46:29 +00:00
|
|
|
{
|
2010-03-03 03:23:53 +00:00
|
|
|
x_off = 0;
|
2011-10-22 00:46:29 +00:00
|
|
|
}
|
2010-03-03 03:23:53 +00:00
|
|
|
if (y_off < 0)
|
2011-10-22 00:46:29 +00:00
|
|
|
{
|
2010-03-03 03:23:53 +00:00
|
|
|
y_off = 0;
|
2011-10-22 00:46:29 +00:00
|
|
|
}
|
2010-09-18 19:19:27 +00:00
|
|
|
if (end_x > (int)raster_width_)
|
2011-10-22 00:46:29 +00:00
|
|
|
{
|
2010-09-18 19:19:27 +00:00
|
|
|
end_x = raster_width_;
|
2011-10-22 00:46:29 +00:00
|
|
|
}
|
2010-09-18 19:19:27 +00:00
|
|
|
if (end_y > (int)raster_height_)
|
2011-10-22 00:46:29 +00:00
|
|
|
{
|
2010-09-18 19:19:27 +00:00
|
|
|
end_y = raster_height_;
|
2011-10-22 00:46:29 +00:00
|
|
|
}
|
2010-03-03 03:23:53 +00:00
|
|
|
int width = end_x - x_off;
|
|
|
|
int height = end_y - y_off;
|
2011-10-22 00:46:29 +00:00
|
|
|
|
2010-03-03 03:23:53 +00:00
|
|
|
// don't process almost invisible data
|
|
|
|
if (box.width() < 0.5)
|
2011-10-22 00:46:29 +00:00
|
|
|
{
|
2010-03-03 03:23:53 +00:00
|
|
|
width = 0;
|
2011-10-22 00:46:29 +00:00
|
|
|
}
|
2010-03-03 03:23:53 +00:00
|
|
|
if (box.height() < 0.5)
|
2011-10-22 00:46:29 +00:00
|
|
|
{
|
2010-03-03 03:23:53 +00:00
|
|
|
height = 0;
|
2011-10-22 00:46:29 +00:00
|
|
|
}
|
|
|
|
|
2010-03-03 03:23:53 +00:00
|
|
|
//calculate actual box2d of returned raster
|
2011-10-22 00:46:29 +00:00
|
|
|
box2d<double> feature_raster_extent(x_off, y_off, x_off + width, y_off + height);
|
2010-03-03 03:23:53 +00:00
|
|
|
intersect = t.backward(feature_raster_extent);
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2012-04-09 01:00:51 +00:00
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Raster extent=" << raster_extent_;
|
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: View extent=" << intersect;
|
2013-10-11 11:35:34 +00:00
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Query resolution=" << std::get<0>(q.resolution()) << "," << std::get<1>(q.resolution());
|
2012-04-09 10:05:49 +00:00
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: StartX=" << x_off << " StartY=" << y_off << " Width=" << width << " Height=" << height;
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2010-02-03 16:56:42 +00:00
|
|
|
if (width > 0 && height > 0)
|
|
|
|
{
|
2013-10-11 11:35:34 +00:00
|
|
|
double width_res = std::get<0>(q.resolution());
|
|
|
|
double height_res = std::get<1>(q.resolution());
|
2010-08-18 20:42:00 +00:00
|
|
|
int im_width = int(width_res * intersect.width() + 0.5);
|
|
|
|
int im_height = int(height_res * intersect.height() + 0.5);
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2013-11-28 06:50:15 +00:00
|
|
|
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);
|
2010-06-20 04:06:23 +00:00
|
|
|
|
2010-08-18 20:42:00 +00:00
|
|
|
// case where we need to avoid upsampling so that the
|
2011-11-14 03:37:50 +00:00
|
|
|
// image can be later scaled within raster_symbolizer
|
2010-08-18 20:42:00 +00:00
|
|
|
if (im_width >= width || im_height >= height)
|
|
|
|
{
|
|
|
|
im_width = width;
|
|
|
|
im_height = height;
|
|
|
|
}
|
2009-05-15 10:31:49 +00:00
|
|
|
|
2010-08-18 20:42:00 +00:00
|
|
|
if (im_width > 0 && im_height > 0)
|
|
|
|
{
|
2012-04-09 01:00:51 +00:00
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Image Size=(" << im_width << "," << im_height << ")";
|
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Reading band=" << band_;
|
2010-11-14 14:54:28 +00:00
|
|
|
if (band_ > 0) // we are querying a single band
|
2010-08-18 20:42:00 +00:00
|
|
|
{
|
2015-02-04 21:41:58 +00:00
|
|
|
GDALRasterBand * band = dataset_.GetRasterBand(band_);
|
2010-09-19 17:52:17 +00:00
|
|
|
if (band_ > nbands_)
|
2011-10-22 00:46:29 +00:00
|
|
|
{
|
2014-10-01 01:35:07 +00:00
|
|
|
std::ostringstream s;
|
|
|
|
s << "GDAL Plugin: " << band_ << " is an invalid band, dataset only has " << nbands_ << "bands";
|
|
|
|
throw datasource_exception(s.str());
|
2011-10-22 00:46:29 +00:00
|
|
|
}
|
2015-02-04 21:41:58 +00:00
|
|
|
GDALDataType band_type = band->GetRasterDataType();
|
|
|
|
switch (band_type)
|
|
|
|
{
|
|
|
|
case GDT_Byte:
|
|
|
|
{
|
|
|
|
mapnik::image_gray8 image(im_width, im_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,
|
2015-05-04 10:49:11 +00:00
|
|
|
image.data(), image.width(), image.height(),
|
2015-02-04 21:41:58 +00:00
|
|
|
GDT_Byte, 0, 0);
|
|
|
|
if (raster_io_error == CE_Failure)
|
|
|
|
{
|
|
|
|
throw datasource_exception(CPLGetLastErrorMsg());
|
|
|
|
}
|
|
|
|
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(intersect, image, filter_factor);
|
|
|
|
// set nodata value to be used in raster colorizer
|
|
|
|
if (nodata_value_) raster->set_nodata(*nodata_value_);
|
|
|
|
else raster->set_nodata(raster_nodata);
|
|
|
|
feature->set_raster(raster);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GDT_Float64:
|
|
|
|
case GDT_Float32:
|
2014-12-03 17:16:42 +00:00
|
|
|
{
|
2015-02-04 21:41:58 +00:00
|
|
|
mapnik::image_gray32f image(im_width, im_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,
|
2015-05-04 10:49:11 +00:00
|
|
|
image.data(), image.width(), image.height(),
|
2015-02-04 21:41:58 +00:00
|
|
|
GDT_Float32, 0, 0);
|
|
|
|
if (raster_io_error == CE_Failure)
|
|
|
|
{
|
|
|
|
throw datasource_exception(CPLGetLastErrorMsg());
|
|
|
|
}
|
|
|
|
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(intersect, image, filter_factor);
|
|
|
|
// set nodata value to be used in raster colorizer
|
|
|
|
if (nodata_value_) raster->set_nodata(*nodata_value_);
|
|
|
|
else raster->set_nodata(raster_nodata);
|
|
|
|
feature->set_raster(raster);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GDT_UInt16:
|
|
|
|
{
|
|
|
|
mapnik::image_gray16 image(im_width, im_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,
|
2015-05-04 10:49:11 +00:00
|
|
|
image.data(), image.width(), image.height(),
|
2015-02-04 21:41:58 +00:00
|
|
|
GDT_UInt16, 0, 0);
|
|
|
|
if (raster_io_error == CE_Failure)
|
|
|
|
{
|
|
|
|
throw datasource_exception(CPLGetLastErrorMsg());
|
|
|
|
}
|
|
|
|
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(intersect, image, filter_factor);
|
|
|
|
// set nodata value to be used in raster colorizer
|
|
|
|
if (nodata_value_) raster->set_nodata(*nodata_value_);
|
|
|
|
else raster->set_nodata(raster_nodata);
|
|
|
|
feature->set_raster(raster);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
case GDT_Int16:
|
|
|
|
{
|
|
|
|
mapnik::image_gray16s image(im_width, im_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,
|
2015-05-04 10:49:11 +00:00
|
|
|
image.data(), image.width(), image.height(),
|
2015-02-04 21:41:58 +00:00
|
|
|
GDT_Int16, 0, 0);
|
|
|
|
if (raster_io_error == CE_Failure)
|
|
|
|
{
|
|
|
|
throw datasource_exception(CPLGetLastErrorMsg());
|
|
|
|
}
|
|
|
|
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(intersect, image, filter_factor);
|
|
|
|
// set nodata value to be used in raster colorizer
|
|
|
|
if (nodata_value_) raster->set_nodata(*nodata_value_);
|
|
|
|
else raster->set_nodata(raster_nodata);
|
|
|
|
feature->set_raster(raster);
|
|
|
|
break;
|
|
|
|
}
|
2014-10-31 03:32:56 +00:00
|
|
|
}
|
2010-08-18 20:42:00 +00:00
|
|
|
}
|
|
|
|
else // working with all bands
|
|
|
|
{
|
2015-01-22 02:31:02 +00:00
|
|
|
mapnik::image_rgba8 image(im_width, im_height);
|
2014-11-28 11:51:23 +00:00
|
|
|
image.set(std::numeric_limits<std::uint32_t>::max());
|
2010-09-18 19:19:27 +00:00
|
|
|
for (int i = 0; i < nbands_; ++i)
|
2010-08-18 20:42:00 +00:00
|
|
|
{
|
2011-10-22 00:46:29 +00:00
|
|
|
GDALRasterBand * band = dataset_.GetRasterBand(i + 1);
|
2012-04-08 00:20:56 +00:00
|
|
|
#ifdef MAPNIK_LOG
|
2011-10-22 00:46:29 +00:00
|
|
|
get_overview_meta(band);
|
2010-08-18 20:42:00 +00:00
|
|
|
#endif
|
|
|
|
GDALColorInterp color_interp = band->GetColorInterpretation();
|
|
|
|
switch (color_interp)
|
|
|
|
{
|
|
|
|
case GCI_RedBand:
|
|
|
|
red = band;
|
2012-04-09 01:00:51 +00:00
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found red band";
|
2010-08-18 20:42:00 +00:00
|
|
|
break;
|
|
|
|
case GCI_GreenBand:
|
|
|
|
green = band;
|
2012-04-09 01:00:51 +00:00
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found green band";
|
2010-08-18 20:42:00 +00:00
|
|
|
break;
|
|
|
|
case GCI_BlueBand:
|
|
|
|
blue = band;
|
2012-04-09 01:00:51 +00:00
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found blue band";
|
2010-08-18 20:42:00 +00:00
|
|
|
break;
|
|
|
|
case GCI_AlphaBand:
|
|
|
|
alpha = band;
|
2012-04-09 01:00:51 +00:00
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found alpha band";
|
2010-08-18 20:42:00 +00:00
|
|
|
break;
|
|
|
|
case GCI_GrayIndex:
|
|
|
|
grey = band;
|
2012-04-09 01:00:51 +00:00
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found gray band";
|
2010-08-18 20:42:00 +00:00
|
|
|
break;
|
|
|
|
case GCI_PaletteIndex:
|
|
|
|
{
|
|
|
|
grey = band;
|
2013-08-20 02:30:23 +00:00
|
|
|
#ifdef MAPNIK_LOG
|
2012-04-09 01:00:51 +00:00
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found gray band, and colortable...";
|
2010-08-18 20:42:00 +00:00
|
|
|
GDALColorTable *color_table = band->GetColorTable();
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2011-10-22 00:46:29 +00:00
|
|
|
if (color_table)
|
2010-08-18 20:42:00 +00:00
|
|
|
{
|
|
|
|
int count = color_table->GetColorEntryCount();
|
2012-04-09 01:00:51 +00:00
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Color Table count=" << count;
|
2012-04-09 10:05:49 +00:00
|
|
|
|
2010-11-14 14:54:28 +00:00
|
|
|
for (int j = 0; j < count; j++)
|
2010-08-18 20:42:00 +00:00
|
|
|
{
|
2010-11-14 14:54:28 +00:00
|
|
|
const GDALColorEntry *ce = color_table->GetColorEntry (j);
|
|
|
|
if (! ce) continue;
|
2012-04-09 01:00:51 +00:00
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Color entry RGB=" << ce->c1 << "," <<ce->c2 << "," << ce->c3;
|
2010-08-18 20:42:00 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-20 02:30:23 +00:00
|
|
|
#endif
|
2010-08-18 20:42:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GCI_Undefined:
|
2014-07-22 21:33:59 +00:00
|
|
|
#if GDAL_VERSION_NUM <= 1730
|
|
|
|
if (nbands_ == 4)
|
|
|
|
{
|
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found undefined band (assumming alpha band)";
|
|
|
|
alpha = band;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found undefined band (assumming gray band)";
|
|
|
|
grey = band;
|
|
|
|
}
|
|
|
|
#else
|
2012-04-09 01:00:51 +00:00
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Found undefined band (assumming gray band)";
|
2010-08-18 20:42:00 +00:00
|
|
|
grey = band;
|
2014-07-22 21:33:59 +00:00
|
|
|
#endif
|
2010-08-18 20:42:00 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-04-09 01:00:51 +00:00
|
|
|
MAPNIK_LOG_WARN(gdal) << "gdal_featureset: Band type unknown!";
|
2010-08-18 20:42:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (red && green && blue)
|
|
|
|
{
|
2012-04-09 01:00:51 +00:00
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Processing rgb bands...";
|
2013-09-25 21:37:21 +00:00
|
|
|
raster_nodata = red->GetNoDataValue(&raster_has_nodata);
|
2011-03-11 21:28:18 +00:00
|
|
|
GDALColorTable *color_table = red->GetColorTable();
|
2014-01-18 03:13:53 +00:00
|
|
|
bool has_nodata = nodata_value_ || raster_has_nodata;
|
2015-02-05 19:38:27 +00:00
|
|
|
|
|
|
|
// we can deduce the alpha channel from nodata in the Byte case
|
|
|
|
// by reusing the reading of R,G,B bands directly
|
2015-04-02 21:11:45 +00:00
|
|
|
if (has_nodata && !color_table && red->GetRasterDataType() == GDT_Byte)
|
2011-03-11 21:28:18 +00:00
|
|
|
{
|
2014-01-18 03:13:53 +00:00
|
|
|
double apply_nodata = nodata_value_ ? *nodata_value_ : raster_nodata;
|
2013-09-25 21:37:21 +00:00
|
|
|
// read the data in and create an alpha channel from the nodata values
|
2014-01-18 03:13:53 +00:00
|
|
|
// TODO - we assume here the nodata value for the red band applies to all bands
|
|
|
|
// more details about this at http://trac.osgeo.org/gdal/ticket/2734
|
2015-05-04 10:49:11 +00:00
|
|
|
float* imageData = (float*)image.bytes();
|
2014-10-31 03:32:56 +00:00
|
|
|
raster_io_error = red->RasterIO(GF_Read, x_off, y_off, width, height,
|
|
|
|
imageData, image.width(), image.height(),
|
|
|
|
GDT_Float32, 0, 0);
|
|
|
|
if (raster_io_error == CE_Failure) {
|
|
|
|
throw datasource_exception(CPLGetLastErrorMsg());
|
|
|
|
}
|
2011-03-11 21:28:18 +00:00
|
|
|
int len = image.width() * image.height();
|
2011-10-22 00:46:29 +00:00
|
|
|
for (int i = 0; i < len; ++i)
|
2011-03-11 21:28:18 +00:00
|
|
|
{
|
2014-01-18 03:13:53 +00:00
|
|
|
if (std::fabs(apply_nodata - imageData[i]) < nodata_tolerance_)
|
2011-10-22 00:46:29 +00:00
|
|
|
{
|
|
|
|
*reinterpret_cast<unsigned *>(&imageData[i]) = 0;
|
|
|
|
}
|
2011-03-11 21:28:18 +00:00
|
|
|
else
|
2011-10-22 00:46:29 +00:00
|
|
|
{
|
|
|
|
*reinterpret_cast<unsigned *>(&imageData[i]) = 0xFFFFFFFF;
|
|
|
|
}
|
2011-03-11 21:28:18 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-05 19:33:52 +00:00
|
|
|
|
|
|
|
/* Use dataset RasterIO in priority in 99.9% of the cases */
|
|
|
|
if( red->GetBand() == 1 && green->GetBand() == 2 && blue->GetBand() == 3 )
|
|
|
|
{
|
|
|
|
int nBandsToRead = 3;
|
2016-04-05 19:27:32 +00:00
|
|
|
if( alpha != nullptr && alpha->GetBand() == 4 && !raster_has_nodata )
|
2015-02-05 19:33:52 +00:00
|
|
|
{
|
|
|
|
nBandsToRead = 4;
|
2016-04-05 19:27:32 +00:00
|
|
|
alpha = nullptr; // to avoid reading it again afterwards
|
2015-02-05 19:33:52 +00:00
|
|
|
}
|
|
|
|
raster_io_error = dataset_.RasterIO(GF_Read, x_off, y_off, width, height,
|
2015-05-04 10:49:11 +00:00
|
|
|
image.bytes(),
|
2015-02-05 19:33:52 +00:00
|
|
|
image.width(), image.height(), GDT_Byte,
|
2016-04-05 19:27:32 +00:00
|
|
|
nBandsToRead, nullptr,
|
2015-02-05 19:33:52 +00:00
|
|
|
4, 4 * image.width(), 1);
|
|
|
|
if (raster_io_error == CE_Failure) {
|
|
|
|
throw datasource_exception(CPLGetLastErrorMsg());
|
|
|
|
}
|
2014-10-31 03:32:56 +00:00
|
|
|
}
|
2015-02-05 19:33:52 +00:00
|
|
|
else
|
|
|
|
{
|
2015-05-04 10:49:11 +00:00
|
|
|
raster_io_error = red->RasterIO(GF_Read, x_off, y_off, width, height, image.bytes() + 0,
|
2015-02-05 19:33:52 +00:00
|
|
|
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
|
|
|
if (raster_io_error == CE_Failure) {
|
|
|
|
throw datasource_exception(CPLGetLastErrorMsg());
|
|
|
|
}
|
2015-05-04 10:49:11 +00:00
|
|
|
raster_io_error = green->RasterIO(GF_Read, x_off, y_off, width, height, image.bytes() + 1,
|
2015-02-05 19:33:52 +00:00
|
|
|
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
|
|
|
if (raster_io_error == CE_Failure) {
|
|
|
|
throw datasource_exception(CPLGetLastErrorMsg());
|
|
|
|
}
|
2015-05-04 10:49:11 +00:00
|
|
|
raster_io_error = blue->RasterIO(GF_Read, x_off, y_off, width, height, image.bytes() + 2,
|
2015-02-05 19:33:52 +00:00
|
|
|
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
|
|
|
if (raster_io_error == CE_Failure) {
|
|
|
|
throw datasource_exception(CPLGetLastErrorMsg());
|
|
|
|
}
|
2014-10-31 03:32:56 +00:00
|
|
|
}
|
2015-02-05 19:38:27 +00:00
|
|
|
|
|
|
|
// In the case we skipped initializing the alpha channel
|
|
|
|
if (has_nodata && !color_table && red->GetRasterDataType() == GDT_Byte)
|
|
|
|
{
|
|
|
|
double apply_nodata = nodata_value_ ? *nodata_value_ : raster_nodata;
|
|
|
|
if( apply_nodata >= 0 && apply_nodata <= 255 )
|
|
|
|
{
|
|
|
|
int len = image.width() * image.height();
|
2015-05-04 10:49:11 +00:00
|
|
|
GByte* pabyBytes = (GByte*) image.bytes();
|
2015-02-05 19:38:27 +00:00
|
|
|
for (int i = 0; i < len; ++i)
|
|
|
|
{
|
|
|
|
// TODO - we assume here the nodata value for the red band applies to all bands
|
|
|
|
// more details about this at http://trac.osgeo.org/gdal/ticket/2734
|
2015-02-05 23:41:57 +00:00
|
|
|
if (std::fabs(apply_nodata - pabyBytes[4*i]) < nodata_tolerance_)
|
2015-02-05 19:38:27 +00:00
|
|
|
pabyBytes[4*i + 3] = 0;
|
|
|
|
else
|
|
|
|
pabyBytes[4*i + 3] = 255;
|
|
|
|
}
|
|
|
|
}
|
2014-10-31 03:32:56 +00:00
|
|
|
}
|
2010-08-18 20:42:00 +00:00
|
|
|
}
|
|
|
|
else if (grey)
|
|
|
|
{
|
2012-04-09 01:00:51 +00:00
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Processing gray band...";
|
2013-09-25 21:37:21 +00:00
|
|
|
raster_nodata = grey->GetNoDataValue(&raster_has_nodata);
|
2011-10-22 00:46:29 +00:00
|
|
|
GDALColorTable* color_table = grey->GetColorTable();
|
2013-09-25 21:37:21 +00:00
|
|
|
bool has_nodata = nodata_value_ || raster_has_nodata;
|
|
|
|
if (!color_table && has_nodata)
|
2011-03-11 21:28:18 +00:00
|
|
|
{
|
2013-09-25 21:37:21 +00:00
|
|
|
double apply_nodata = nodata_value_ ? *nodata_value_ : raster_nodata;
|
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: applying nodata value for layer=" << apply_nodata;
|
2011-03-11 21:28:18 +00:00
|
|
|
// first read the data in and create an alpha channel from the nodata values
|
2015-05-04 10:49:11 +00:00
|
|
|
float* imageData = (float*)image.bytes();
|
2014-10-31 03:32:56 +00:00
|
|
|
raster_io_error = grey->RasterIO(GF_Read, x_off, y_off, width, height,
|
|
|
|
imageData, image.width(), image.height(),
|
|
|
|
GDT_Float32, 0, 0);
|
2014-11-28 11:51:23 +00:00
|
|
|
if (raster_io_error == CE_Failure)
|
|
|
|
{
|
2014-10-31 03:32:56 +00:00
|
|
|
throw datasource_exception(CPLGetLastErrorMsg());
|
|
|
|
}
|
2011-03-11 21:28:18 +00:00
|
|
|
int len = image.width() * image.height();
|
2011-10-22 00:46:29 +00:00
|
|
|
for (int i = 0; i < len; ++i)
|
2011-03-11 21:28:18 +00:00
|
|
|
{
|
2014-01-18 03:13:53 +00:00
|
|
|
if (std::fabs(apply_nodata - imageData[i]) < nodata_tolerance_)
|
2011-10-22 00:46:29 +00:00
|
|
|
{
|
|
|
|
*reinterpret_cast<unsigned *>(&imageData[i]) = 0;
|
|
|
|
}
|
2011-03-11 21:28:18 +00:00
|
|
|
else
|
2011-10-22 00:46:29 +00:00
|
|
|
{
|
2013-09-25 21:37:21 +00:00
|
|
|
*reinterpret_cast<unsigned *>(&imageData[i]) = 0xFFFFFFFF;
|
2011-10-22 00:46:29 +00:00
|
|
|
}
|
2011-03-11 21:28:18 +00:00
|
|
|
}
|
|
|
|
}
|
2014-11-28 11:51:23 +00:00
|
|
|
|
2015-05-04 10:49:11 +00:00
|
|
|
raster_io_error = grey->RasterIO(GF_Read, x_off, y_off, width, height, image.bytes() + 0,
|
2014-10-31 03:32:56 +00:00
|
|
|
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
2014-11-28 11:51:23 +00:00
|
|
|
if (raster_io_error == CE_Failure)
|
|
|
|
{
|
2014-10-31 03:32:56 +00:00
|
|
|
throw datasource_exception(CPLGetLastErrorMsg());
|
|
|
|
}
|
2014-11-28 11:51:23 +00:00
|
|
|
|
2015-05-04 10:49:11 +00:00
|
|
|
raster_io_error = grey->RasterIO(GF_Read,x_off, y_off, width, height, image.bytes() + 1,
|
2014-10-31 03:32:56 +00:00
|
|
|
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
2014-11-28 11:51:23 +00:00
|
|
|
if (raster_io_error == CE_Failure)
|
|
|
|
{
|
2014-10-31 03:32:56 +00:00
|
|
|
throw datasource_exception(CPLGetLastErrorMsg());
|
|
|
|
}
|
2014-11-28 11:51:23 +00:00
|
|
|
|
2015-05-04 10:49:11 +00:00
|
|
|
raster_io_error = grey->RasterIO(GF_Read,x_off, y_off, width, height, image.bytes() + 2,
|
2014-10-31 03:32:56 +00:00
|
|
|
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
2014-11-28 11:51:23 +00:00
|
|
|
|
|
|
|
if (raster_io_error == CE_Failure)
|
|
|
|
{
|
2014-10-31 03:32:56 +00:00
|
|
|
throw datasource_exception(CPLGetLastErrorMsg());
|
|
|
|
}
|
2011-01-27 03:11:22 +00:00
|
|
|
|
|
|
|
if (color_table)
|
|
|
|
{
|
2013-09-25 21:37:21 +00:00
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Loading color table...";
|
2011-01-27 03:11:22 +00:00
|
|
|
for (unsigned y = 0; y < image.height(); ++y)
|
|
|
|
{
|
2015-05-04 10:49:11 +00:00
|
|
|
unsigned int* row = image.get_row(y);
|
2011-01-27 03:11:22 +00:00
|
|
|
for (unsigned x = 0; x < image.width(); ++x)
|
|
|
|
{
|
|
|
|
unsigned value = row[x] & 0xff;
|
2013-09-25 21:37:21 +00:00
|
|
|
const GDALColorEntry *ce = color_table->GetColorEntry(value);
|
|
|
|
if (ce)
|
2011-10-22 00:46:29 +00:00
|
|
|
{
|
2013-09-25 21:37:21 +00:00
|
|
|
row[x] = (ce->c4 << 24)| (ce->c3 << 16) | (ce->c2 << 8) | (ce->c1) ;
|
2012-04-03 23:06:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-25 21:37:21 +00:00
|
|
|
// make lacking color entry fully alpha
|
|
|
|
// note - gdal_translate makes black
|
|
|
|
row[x] = 0;
|
2011-01-27 03:11:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-18 20:42:00 +00:00
|
|
|
}
|
|
|
|
if (alpha)
|
|
|
|
{
|
2012-04-09 01:00:51 +00:00
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: processing alpha band...";
|
2014-01-18 03:13:53 +00:00
|
|
|
if (!raster_has_nodata)
|
2013-09-25 21:37:21 +00:00
|
|
|
{
|
2015-05-04 10:49:11 +00:00
|
|
|
raster_io_error = alpha->RasterIO(GF_Read, x_off, y_off, width, height, image.bytes() + 3,
|
2014-10-31 03:32:56 +00:00
|
|
|
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
|
|
|
if (raster_io_error == CE_Failure) {
|
|
|
|
throw datasource_exception(CPLGetLastErrorMsg());
|
|
|
|
}
|
2014-01-18 03:13:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-05 02:18:38 +00:00
|
|
|
MAPNIK_LOG_WARN(gdal) << "warning: nodata value (" << raster_nodata << ") used to set transparency instead of alpha band";
|
2013-09-25 21:37:21 +00:00
|
|
|
}
|
2010-08-18 20:42:00 +00:00
|
|
|
}
|
2016-05-17 17:44:12 +00:00
|
|
|
else if( dataset_.GetRasterCount() > 0 && dataset_.GetRasterBand(1) )
|
|
|
|
{
|
|
|
|
// Check if we have a non-alpha mask band (for example a TIFF internal mask)
|
|
|
|
int flags = dataset_.GetRasterBand(1)->GetMaskFlags();
|
|
|
|
GDALRasterBand* mask = 0;
|
|
|
|
if (flags == GMF_PER_DATASET)
|
|
|
|
{
|
|
|
|
mask = dataset_.GetRasterBand(1)->GetMaskBand();
|
|
|
|
}
|
|
|
|
if (mask)
|
|
|
|
{
|
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: found and processing mask band...";
|
|
|
|
if (!raster_has_nodata)
|
|
|
|
{
|
|
|
|
raster_io_error = mask->RasterIO(GF_Read, x_off, y_off, width, height, image.bytes() + 3,
|
|
|
|
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
|
|
|
if (raster_io_error == CE_Failure) {
|
|
|
|
throw datasource_exception(CPLGetLastErrorMsg());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MAPNIK_LOG_WARN(gdal) << "warning: nodata value (" << raster_nodata << ") used to set transparency instead of mask band";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-28 11:51:23 +00:00
|
|
|
mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(intersect, image, filter_factor);
|
|
|
|
// set nodata value to be used in raster colorizer
|
|
|
|
if (nodata_value_) raster->set_nodata(*nodata_value_);
|
|
|
|
else raster->set_nodata(raster_nodata);
|
|
|
|
feature->set_raster(raster);
|
2013-09-25 21:37:21 +00:00
|
|
|
}
|
|
|
|
// report actual/original source nodata in feature attributes
|
|
|
|
if (raster_has_nodata)
|
|
|
|
{
|
|
|
|
feature->put("nodata",raster_nodata);
|
|
|
|
}
|
2010-08-18 20:42:00 +00:00
|
|
|
return feature;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return feature_ptr();
|
2009-09-27 17:23:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
feature_ptr gdal_featureset::get_feature_at_point(mapnik::coord2d const& pt)
|
|
|
|
{
|
2014-10-31 03:32:56 +00:00
|
|
|
CPLErr raster_io_error = CE_None;
|
|
|
|
|
2010-11-14 14:54:28 +00:00
|
|
|
if (band_ > 0)
|
|
|
|
{
|
2010-08-18 20:42:00 +00:00
|
|
|
unsigned raster_xsize = dataset_.GetRasterXSize();
|
|
|
|
unsigned raster_ysize = dataset_.GetRasterYSize();
|
2009-09-27 17:23:09 +00:00
|
|
|
|
2010-08-18 20:42:00 +00:00
|
|
|
double gt[6];
|
|
|
|
dataset_.GetGeoTransform(gt);
|
2009-09-27 17:23:09 +00:00
|
|
|
|
2011-10-22 00:46:29 +00:00
|
|
|
double det = gt[1] * gt[5] - gt[2] * gt[4];
|
2010-08-18 20:42:00 +00:00
|
|
|
// subtract half a pixel width & height because gdal coord reference
|
|
|
|
// is the top-left corner of a pixel, not the center.
|
|
|
|
double X = pt.x - gt[0] - gt[1]/2;
|
|
|
|
double Y = pt.y - gt[3] - gt[5]/2;
|
|
|
|
double det1 = gt[1]*Y + gt[4]*X;
|
|
|
|
double det2 = gt[2]*Y + gt[5]*X;
|
2012-08-15 19:37:17 +00:00
|
|
|
unsigned x = static_cast<unsigned>(det2/det);
|
|
|
|
unsigned y = static_cast<unsigned>(det1/det);
|
2009-09-27 17:23:09 +00:00
|
|
|
|
2010-11-14 14:54:28 +00:00
|
|
|
if (x < raster_xsize && y < raster_ysize)
|
|
|
|
{
|
2012-04-09 10:05:49 +00:00
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: pt.x=" << pt.x << " pt.y=" << pt.y;
|
|
|
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: x=" << x << " y=" << y;
|
|
|
|
|
2011-10-22 00:46:29 +00:00
|
|
|
GDALRasterBand* band = dataset_.GetRasterBand(band_);
|
2013-09-25 21:37:21 +00:00
|
|
|
int raster_has_nodata;
|
|
|
|
double nodata = band->GetNoDataValue(&raster_has_nodata);
|
2010-08-18 20:42:00 +00:00
|
|
|
double value;
|
2014-10-31 03:32:56 +00:00
|
|
|
raster_io_error = band->RasterIO(GF_Read, x, y, 1, 1, &value, 1, 1, GDT_Float64, 0, 0);
|
|
|
|
if (raster_io_error == CE_Failure) {
|
|
|
|
throw datasource_exception(CPLGetLastErrorMsg());
|
|
|
|
}
|
2013-09-25 21:37:21 +00:00
|
|
|
if (! raster_has_nodata || value != nodata)
|
2010-11-14 14:54:28 +00:00
|
|
|
{
|
2012-02-02 01:37:35 +00:00
|
|
|
// construct feature
|
2012-01-16 22:55:44 +00:00
|
|
|
feature_ptr feature = feature_factory::create(ctx_,1);
|
2015-04-09 20:22:51 +00:00
|
|
|
feature->set_geometry(mapnik::geometry::point<double>(pt.x,pt.y));
|
2013-09-25 22:24:08 +00:00
|
|
|
feature->put_new("value",value);
|
|
|
|
if (raster_has_nodata)
|
|
|
|
{
|
|
|
|
feature->put_new("nodata",nodata);
|
|
|
|
}
|
2010-08-18 20:42:00 +00:00
|
|
|
return feature;
|
|
|
|
}
|
|
|
|
}
|
2010-02-03 16:56:42 +00:00
|
|
|
}
|
|
|
|
return feature_ptr();
|
2007-04-25 19:15:38 +00:00
|
|
|
}
|