mirror of
https://github.com/mapnik/mapnik.git
synced 2026-02-01 17:36:36 +00:00
+ fixed a problem in getting GetColorEntry in RGB datasets
+ cosmetics
This commit is contained in:
parent
973aaf1247
commit
68cbb51814
@ -41,7 +41,6 @@ using mapnik::layer_descriptor;
|
||||
using mapnik::datasource_exception;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Opens a GDALDataset and returns a pointer to it.
|
||||
* Caller is responsible for calling GDALClose on it
|
||||
@ -72,7 +71,6 @@ gdal_datasource::gdal_datasource(parameters const& params, bool bind)
|
||||
desc_(*params.get<std::string>("type"),"utf-8"),
|
||||
filter_factor_(*params_.get<double>("filter_factor",0.0))
|
||||
{
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "\nGDAL Plugin: Initializing...\n";
|
||||
#endif
|
||||
@ -142,7 +140,9 @@ void gdal_datasource::bind() const
|
||||
is_bound_ = true;
|
||||
}
|
||||
|
||||
gdal_datasource::~gdal_datasource() {}
|
||||
gdal_datasource::~gdal_datasource()
|
||||
{
|
||||
}
|
||||
|
||||
int gdal_datasource::type() const
|
||||
{
|
||||
|
||||
@ -24,35 +24,40 @@
|
||||
#ifndef GDAL_DATASOURCE_HPP
|
||||
#define GDAL_DATASOURCE_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/datasource.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
// gdal
|
||||
#include <gdal_priv.h>
|
||||
|
||||
class gdal_datasource : public mapnik::datasource
|
||||
{
|
||||
public:
|
||||
gdal_datasource(mapnik::parameters const& params, bool bind=true);
|
||||
virtual ~gdal_datasource ();
|
||||
int type() const;
|
||||
static std::string name();
|
||||
mapnik::featureset_ptr features( mapnik::query const& q) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const;
|
||||
mapnik::box2d<double> envelope() const;
|
||||
mapnik::layer_descriptor get_descriptor() const;
|
||||
void bind() const;
|
||||
private:
|
||||
mutable mapnik::box2d<double> extent_;
|
||||
std::string dataset_name_;
|
||||
mutable int band_;
|
||||
mapnik::layer_descriptor desc_;
|
||||
mutable unsigned width_;
|
||||
mutable unsigned height_;
|
||||
mutable double dx_;
|
||||
mutable double dy_;
|
||||
mutable int nbands_;
|
||||
mutable bool shared_dataset_;
|
||||
double filter_factor_;
|
||||
inline GDALDataset *open_dataset() const;
|
||||
public:
|
||||
gdal_datasource(mapnik::parameters const& params, bool bind=true);
|
||||
virtual ~gdal_datasource ();
|
||||
int type() const;
|
||||
static std::string name();
|
||||
mapnik::featureset_ptr features( mapnik::query const& q) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const;
|
||||
mapnik::box2d<double> envelope() const;
|
||||
mapnik::layer_descriptor get_descriptor() const;
|
||||
void bind() const;
|
||||
private:
|
||||
mutable mapnik::box2d<double> extent_;
|
||||
std::string dataset_name_;
|
||||
mutable int band_;
|
||||
mapnik::layer_descriptor desc_;
|
||||
mutable unsigned width_;
|
||||
mutable unsigned height_;
|
||||
mutable double dx_;
|
||||
mutable double dy_;
|
||||
mutable int nbands_;
|
||||
mutable bool shared_dataset_;
|
||||
double filter_factor_;
|
||||
inline GDALDataset *open_dataset() const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -50,7 +50,9 @@ gdal_featureset::gdal_featureset(GDALDataset & dataset, int band, gdal_query q,
|
||||
dy_(dy),
|
||||
nbands_(nbands),
|
||||
filter_factor_(filter_factor),
|
||||
first_(true) {}
|
||||
first_(true)
|
||||
{
|
||||
}
|
||||
|
||||
gdal_featureset::~gdal_featureset()
|
||||
{
|
||||
@ -185,10 +187,10 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
||||
#endif
|
||||
typedef std::vector<int,int> pallete;
|
||||
|
||||
if (band_>0) // we are querying a single band
|
||||
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());
|
||||
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_);
|
||||
band->RasterIO(GF_Read, x_off, y_off, width, height,
|
||||
@ -255,10 +257,10 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "GDAL Plugin: Color Table count = " << count << "\n";
|
||||
#endif
|
||||
for ( int i = 0; i < count; i++ )
|
||||
for (int j = 0; j < count; j++)
|
||||
{
|
||||
const GDALColorEntry *ce = color_table->GetColorEntry ( i );
|
||||
if (!ce ) continue;
|
||||
const GDALColorEntry *ce = color_table->GetColorEntry (j);
|
||||
if (! ce) continue;
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "GDAL Plugin: Color entry RGB (" << ce->c1 << "," <<ce->c2 << "," << ce->c3 << ")\n";
|
||||
#endif
|
||||
@ -327,8 +329,8 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
||||
|
||||
feature_ptr gdal_featureset::get_feature_at_point(mapnik::coord2d const& pt)
|
||||
{
|
||||
if (band_>0) {
|
||||
|
||||
if (band_ > 0)
|
||||
{
|
||||
unsigned raster_xsize = dataset_.GetRasterXSize();
|
||||
unsigned raster_ysize = dataset_.GetRasterYSize();
|
||||
|
||||
@ -344,7 +346,8 @@ feature_ptr gdal_featureset::get_feature_at_point(mapnik::coord2d const& pt)
|
||||
double det2 = gt[2]*Y + gt[5]*X;
|
||||
unsigned x = det2/det, y = det1/det;
|
||||
|
||||
if(x<raster_xsize && y<raster_ysize) {
|
||||
if (x < raster_xsize && y < raster_ysize)
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << boost::format("GDAL Plugin: pt.x=%f pt.y=%f\n") % pt.x % pt.y;
|
||||
std::clog << boost::format("GDAL Plugin: x=%f y=%f\n") % x % y;
|
||||
@ -354,7 +357,9 @@ feature_ptr gdal_featureset::get_feature_at_point(mapnik::coord2d const& pt)
|
||||
double nodata = band->GetNoDataValue(&hasNoData);
|
||||
double value;
|
||||
band->RasterIO(GF_Read, x, y, 1, 1, &value, 1, 1, GDT_Float64, 0, 0);
|
||||
if(!hasNoData || value!=nodata) {
|
||||
|
||||
if (! hasNoData || value != nodata)
|
||||
{
|
||||
// construct feature
|
||||
feature_ptr feature(new Feature(1));
|
||||
geometry_type * point = new geometry_type(mapnik::Point);
|
||||
|
||||
@ -24,7 +24,10 @@
|
||||
#ifndef GDAL_FEATURESET_HPP
|
||||
#define GDAL_FEATURESET_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/datasource.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/variant.hpp>
|
||||
|
||||
class GDALDataset;
|
||||
@ -34,28 +37,27 @@ 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);
|
||||
virtual ~gdal_featureset();
|
||||
mapnik::feature_ptr next();
|
||||
private:
|
||||
mapnik::feature_ptr get_feature(mapnik::query const& q);
|
||||
mapnik::feature_ptr get_feature_at_point(mapnik::coord2d const& p);
|
||||
void get_overview_meta(GDALRasterBand * band);
|
||||
GDALDataset & dataset_;
|
||||
int band_;
|
||||
gdal_query gquery_;
|
||||
mapnik::box2d<double> raster_extent_;
|
||||
unsigned raster_width_;
|
||||
unsigned raster_height_;
|
||||
double dx_;
|
||||
double dy_;
|
||||
int nbands_;
|
||||
double filter_factor_;
|
||||
bool first_;
|
||||
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);
|
||||
virtual ~gdal_featureset();
|
||||
mapnik::feature_ptr next();
|
||||
private:
|
||||
mapnik::feature_ptr get_feature(mapnik::query const& q);
|
||||
mapnik::feature_ptr get_feature_at_point(mapnik::coord2d const& p);
|
||||
void get_overview_meta(GDALRasterBand * band);
|
||||
GDALDataset & dataset_;
|
||||
int band_;
|
||||
gdal_query gquery_;
|
||||
mapnik::box2d<double> raster_extent_;
|
||||
unsigned raster_width_;
|
||||
unsigned raster_height_;
|
||||
double dx_;
|
||||
double dy_;
|
||||
int nbands_;
|
||||
double filter_factor_;
|
||||
bool first_;
|
||||
};
|
||||
|
||||
#endif // GDAL_FEATURESET_HPP
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user