+ update raster.input

This commit is contained in:
Artem Pavlenko 2012-03-05 14:43:59 +00:00
parent a22cc87df7
commit 90323ffc74
2 changed files with 26 additions and 35 deletions

View file

@ -45,7 +45,7 @@ using mapnik::image_reader;
DATASOURCE_PLUGIN(raster_datasource)
raster_datasource::raster_datasource(const parameters& params, bool bind)
raster_datasource::raster_datasource(const parameters& params)
: datasource(params),
desc_(*params.get<std::string>("type"), "utf-8"),
extent_initialized_(false)
@ -54,6 +54,12 @@ raster_datasource::raster_datasource(const parameters& params, bool bind)
std::clog << "Raster Plugin: Initializing..." << std::endl;
#endif
this->init(params);
}
void raster_datasource::init(parameters const& params)
{
boost::optional<std::string> file = params.get<std::string>("file");
if (! file) throw datasource_exception("Raster Plugin: missing <file> parameter ");
@ -63,18 +69,19 @@ raster_datasource::raster_datasource(const parameters& params, bool bind)
else
filename_ = *file;
multi_tiles_ = *params_.get<bool>("multi", false);
tile_size_ = *params_.get<unsigned>("tile_size", 256);
tile_stride_ = *params_.get<unsigned>("tile_stride", 1);
multi_tiles_ = *params.get<bool>("multi", false);
tile_size_ = *params.get<unsigned>("tile_size", 256);
tile_stride_ = *params.get<unsigned>("tile_stride", 1);
format_ = *params_.get<std::string>("format","tiff");
boost::optional<double> lox = params_.get<double>("lox");
boost::optional<double> loy = params_.get<double>("loy");
boost::optional<double> hix = params_.get<double>("hix");
boost::optional<double> hiy = params_.get<double>("hiy");
boost::optional<std::string> ext = params_.get<std::string>("extent");
format_ = *params.get<std::string>("format","tiff");
boost::optional<double> lox = params.get<double>("lox");
boost::optional<double> loy = params.get<double>("loy");
boost::optional<double> hix = params.get<double>("hix");
boost::optional<double> hiy = params.get<double>("hiy");
boost::optional<std::string> ext = params.get<std::string>("extent");
if (lox && loy && hix && hiy)
{
extent_.init(*lox, *loy, *hix, *hiy);
@ -89,21 +96,11 @@ raster_datasource::raster_datasource(const parameters& params, bool bind)
{
throw datasource_exception("Raster Plugin: valid <extent> or <lox> <loy> <hix> <hiy> are required");
}
if (bind)
{
this->bind();
}
}
void raster_datasource::bind() const
{
if (is_bound_) return;
if (multi_tiles_)
{
boost::optional<unsigned> x_width = params_.get<unsigned>("x_width");
boost::optional<unsigned> y_width = params_.get<unsigned>("y_width");
boost::optional<unsigned> x_width = params.get<unsigned>("x_width");
boost::optional<unsigned> y_width = params.get<unsigned>("y_width");
if (! x_width)
{
@ -151,8 +148,6 @@ void raster_datasource::bind() const
#ifdef MAPNIK_DEBUG
std::clog << "Raster Plugin: RASTER SIZE(" << width_ << "," << height_ << ")" << std::endl;
#endif
is_bound_ = true;
}
raster_datasource::~raster_datasource()
@ -186,8 +181,6 @@ layer_descriptor raster_datasource::get_descriptor() const
featureset_ptr raster_datasource::features(query const& q) const
{
if (! is_bound_) bind();
mapnik::CoordTransform t(width_, height_, extent_, 0, 0);
mapnik::box2d<double> intersect = extent_.intersect(q.get_bbox());
mapnik::box2d<double> ext = t.forward(intersect);

View file

@ -31,7 +31,7 @@
class raster_datasource : public mapnik::datasource
{
public:
raster_datasource(const mapnik::parameters& params, bool bind=true);
raster_datasource(mapnik::parameters const& params);
virtual ~raster_datasource();
datasource::datasource_t type() const;
static std::string name();
@ -40,8 +40,8 @@ public:
mapnik::box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
mapnik::layer_descriptor get_descriptor() const;
void bind() const;
private:
void init(mapnik::parameters const& params);
mapnik::layer_descriptor desc_;
std::string filename_;
std::string format_;
@ -50,11 +50,9 @@ private:
bool multi_tiles_;
unsigned tile_size_;
unsigned tile_stride_;
mutable unsigned width_;
mutable unsigned height_;
//no copying
raster_datasource(const raster_datasource&);
raster_datasource& operator=(const raster_datasource&);
unsigned width_;
unsigned height_;
};
#endif // RASTER_DATASOURCE_HPP