- fix indentation and trailing spaces (generally coding style) in gdal plugin partially related to #911
This commit is contained in:
parent
10d35add23
commit
3d0de64051
4 changed files with 216 additions and 135 deletions
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2007 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -55,15 +55,22 @@ inline GDALDataset *gdal_datasource::open_dataset() const
|
|||
GDALDataset *dataset;
|
||||
#if GDAL_VERSION_NUM >= 1600
|
||||
if (shared_dataset_)
|
||||
{
|
||||
dataset = reinterpret_cast<GDALDataset*>(GDALOpenShared((dataset_name_).c_str(), GA_ReadOnly));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
dataset = reinterpret_cast<GDALDataset*>(GDALOpen((dataset_name_).c_str(), GA_ReadOnly));
|
||||
|
||||
if (! dataset) throw datasource_exception(CPLGetLastErrorMsg());
|
||||
return dataset;
|
||||
}
|
||||
|
||||
if (! dataset)
|
||||
{
|
||||
throw datasource_exception(CPLGetLastErrorMsg());
|
||||
}
|
||||
|
||||
return dataset;
|
||||
}
|
||||
|
||||
|
||||
gdal_datasource::gdal_datasource(parameters const& params, bool bind)
|
||||
|
@ -82,9 +89,13 @@ gdal_datasource::gdal_datasource(parameters const& params, bool bind)
|
|||
|
||||
boost::optional<std::string> base = params_.get<std::string>("base");
|
||||
if (base)
|
||||
{
|
||||
dataset_name_ = *base + "/" + *file;
|
||||
}
|
||||
else
|
||||
{
|
||||
dataset_name_ = *file;
|
||||
}
|
||||
|
||||
if (bind)
|
||||
{
|
||||
|
@ -105,7 +116,6 @@ void gdal_datasource::bind() const
|
|||
width_ = dataset->GetRasterXSize();
|
||||
height_ = dataset->GetRasterYSize();
|
||||
|
||||
|
||||
double tr[6];
|
||||
bool bbox_override = false;
|
||||
boost::optional<std::string> bbox_s = params_.get<std::string>("bbox");
|
||||
|
@ -114,6 +124,7 @@ void gdal_datasource::bind() const
|
|||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "GDAL Plugin: bbox parameter=" << *bbox_s << std::endl;
|
||||
#endif
|
||||
|
||||
bbox_override = extent_.from_string(*bbox_s);
|
||||
if (! bbox_override)
|
||||
{
|
||||
|
@ -166,6 +177,7 @@ void gdal_datasource::bind() const
|
|||
|
||||
extent_.init(x0, y0, x1, y1);
|
||||
}
|
||||
|
||||
GDALClose(dataset);
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
|
@ -207,8 +219,18 @@ featureset_ptr gdal_datasource::features(query const& q) const
|
|||
if (! is_bound_) bind();
|
||||
|
||||
gdal_query gq = q;
|
||||
|
||||
// TODO - move to boost::make_shared, but must reduce # of args to <= 9
|
||||
return featureset_ptr(new gdal_featureset(*open_dataset(), band_, gq, extent_, width_, height_, nbands_, dx_, dy_, filter_factor_));
|
||||
return featureset_ptr(new gdal_featureset(*open_dataset(),
|
||||
band_,
|
||||
gq,
|
||||
extent_,
|
||||
width_,
|
||||
height_,
|
||||
nbands_,
|
||||
dx_,
|
||||
dy_,
|
||||
filter_factor_));
|
||||
}
|
||||
|
||||
featureset_ptr gdal_datasource::features_at_point(coord2d const& pt) const
|
||||
|
@ -216,6 +238,16 @@ featureset_ptr gdal_datasource::features_at_point(coord2d const& pt) const
|
|||
if (! is_bound_) bind();
|
||||
|
||||
gdal_query gq = pt;
|
||||
return featureset_ptr(new gdal_featureset(*open_dataset(), band_, gq, extent_, width_, height_, nbands_, dx_, dy_, filter_factor_));
|
||||
}
|
||||
|
||||
// TODO - move to boost::make_shared, but must reduce # of args to <= 9
|
||||
return featureset_ptr(new gdal_featureset(*open_dataset(),
|
||||
band_,
|
||||
gq,
|
||||
extent_,
|
||||
width_,
|
||||
height_,
|
||||
nbands_,
|
||||
dx_,
|
||||
dy_,
|
||||
filter_factor_));
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2007 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2007 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -41,9 +41,16 @@ using mapnik::datasource_exception;
|
|||
using mapnik::feature_factory;
|
||||
|
||||
|
||||
gdal_featureset::gdal_featureset(GDALDataset & dataset, int band, gdal_query q,
|
||||
mapnik::box2d<double> extent, double width, double height, int nbands,
|
||||
double dx, double dy, double filter_factor)
|
||||
gdal_featureset::gdal_featureset(GDALDataset& dataset,
|
||||
int band,
|
||||
gdal_query q,
|
||||
mapnik::box2d<double> extent,
|
||||
double width,
|
||||
double height,
|
||||
int nbands,
|
||||
double dx,
|
||||
double dy,
|
||||
double filter_factor)
|
||||
: dataset_(dataset),
|
||||
band_(band),
|
||||
gquery_(q),
|
||||
|
@ -63,6 +70,7 @@ gdal_featureset::~gdal_featureset()
|
|||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "GDAL Plugin: closing dataset = " << &dataset_ << std::endl;
|
||||
#endif
|
||||
|
||||
GDALClose(&dataset_);
|
||||
}
|
||||
|
||||
|
@ -76,11 +84,15 @@ feature_ptr gdal_featureset::next()
|
|||
#endif
|
||||
|
||||
query *q = boost::get<query>(&gquery_);
|
||||
if(q) {
|
||||
if (q)
|
||||
{
|
||||
return get_feature(*q);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
coord2d *p = boost::get<coord2d>(&gquery_);
|
||||
if(p) {
|
||||
if (p)
|
||||
{
|
||||
return get_feature_at_point(*p);
|
||||
}
|
||||
}
|
||||
|
@ -116,30 +128,50 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
|||
double margin_x = 1.0 / (fabs(dx_) * boost::get<0>(q.resolution()));
|
||||
double margin_y = 1.0 / (fabs(dy_) * boost::get<1>(q.resolution()));
|
||||
if (margin_x < 1)
|
||||
{
|
||||
margin_x = 1.0;
|
||||
}
|
||||
if (margin_y < 1)
|
||||
{
|
||||
margin_y = 1.0;
|
||||
}
|
||||
|
||||
//select minimum raster containing whole box
|
||||
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);
|
||||
|
||||
//clip to available data
|
||||
if (x_off < 0)
|
||||
{
|
||||
x_off = 0;
|
||||
}
|
||||
if (y_off < 0)
|
||||
{
|
||||
y_off = 0;
|
||||
}
|
||||
if (end_x > (int)raster_width_)
|
||||
{
|
||||
end_x = raster_width_;
|
||||
}
|
||||
if (end_y > (int)raster_height_)
|
||||
{
|
||||
end_y = raster_height_;
|
||||
}
|
||||
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);
|
||||
|
@ -197,7 +229,9 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
|||
if (band_ > 0) // we are querying a single band
|
||||
{
|
||||
if (band_ > nbands_)
|
||||
{
|
||||
throw datasource_exception((boost::format("GDAL Plugin: '%d' is an invalid band, dataset only has '%d' bands\n") % band_ % nbands_).str());
|
||||
}
|
||||
|
||||
float* imageData = (float*)image.getBytes();
|
||||
GDALRasterBand * band = dataset_.GetRasterBand(band_);
|
||||
|
@ -209,9 +243,10 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
|||
|
||||
feature->set_raster(mapnik::raster_ptr(boost::make_shared<mapnik::raster>(intersect,image)));
|
||||
if (hasNoData)
|
||||
{
|
||||
feature->props()["NODATA"] = nodata;
|
||||
}
|
||||
|
||||
}
|
||||
else // working with all bands
|
||||
{
|
||||
for (int i = 0; i < nbands_; ++i)
|
||||
|
@ -316,10 +351,14 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
|||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
if (nodata == imageData[i])
|
||||
{
|
||||
*reinterpret_cast<unsigned *>(&imageData[i]) = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
*reinterpret_cast<unsigned *>(&imageData[i]) = 0xFFFFFFFF;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -329,7 +368,6 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
|||
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
||||
blue->RasterIO(GF_Read, x_off, y_off, width, height, image.getBytes() + 2,
|
||||
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
||||
|
||||
}
|
||||
else if (grey)
|
||||
{
|
||||
|
@ -356,11 +394,15 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
|||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
if (nodata == imageData[i])
|
||||
{
|
||||
*reinterpret_cast<unsigned *>(&imageData[i]) = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
*reinterpret_cast<unsigned *> (&imageData[i]) = 0xFFFFFFFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
grey->RasterIO(GF_Read, x_off, y_off, width, height, image.getBytes() + 0,
|
||||
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
||||
|
@ -381,7 +423,8 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
|||
{
|
||||
unsigned value = row[x] & 0xff;
|
||||
const GDALColorEntry *ce = color_table->GetColorEntry(value);
|
||||
if (ce ){
|
||||
if (ce )
|
||||
{
|
||||
// TODO - big endian support
|
||||
row[x] = (ce->c4 << 24)| (ce->c3 << 16) | (ce->c2 << 8) | (ce->c1) ;
|
||||
}
|
||||
|
@ -484,4 +527,3 @@ void gdal_featureset::get_overview_meta(GDALRasterBand * band)
|
|||
% GDALGetColorInterpretationName(band->GetColorInterpretation()) << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2007 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -38,9 +38,16 @@ typedef boost::variant<mapnik::query,mapnik::coord2d> gdal_query;
|
|||
class gdal_featureset : public mapnik::Featureset
|
||||
{
|
||||
public:
|
||||
gdal_featureset(GDALDataset & dataset, int band, gdal_query q,
|
||||
mapnik::box2d<double> extent, double width, double height, int nbands,
|
||||
double dx, double dy, double filter_factor);
|
||||
gdal_featureset(GDALDataset& dataset,
|
||||
int band,
|
||||
gdal_query q,
|
||||
mapnik::box2d<double> extent,
|
||||
double width,
|
||||
double height,
|
||||
int nbands,
|
||||
double dx,
|
||||
double dy,
|
||||
double filter_factor);
|
||||
virtual ~gdal_featureset();
|
||||
mapnik::feature_ptr next();
|
||||
private:
|
||||
|
|
Loading…
Add table
Reference in a new issue