- modified coding style in raster plugin

This commit is contained in:
kunitoki 2011-10-23 16:31:25 +02:00
parent eb13c8c6be
commit 78cfd88ac4
6 changed files with 380 additions and 341 deletions

View file

@ -2,7 +2,7 @@
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2006 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
@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
//$Id: raster_datasource.cc 44 2005-04-22 18:53:54Z pavlenko $
// boost
#include <boost/lexical_cast.hpp>
@ -33,12 +32,6 @@
#include "raster_info.hpp"
#include "raster_datasource.hpp"
using mapnik::datasource;
using mapnik::parameters;
using mapnik::image_reader;
DATASOURCE_PLUGIN(raster_datasource)
using boost::lexical_cast;
using boost::bad_lexical_cast;
using mapnik::layer_descriptor;
@ -46,11 +39,16 @@ using mapnik::featureset_ptr;
using mapnik::query;
using mapnik::coord2d;
using mapnik::datasource_exception;
using mapnik::datasource;
using mapnik::parameters;
using mapnik::image_reader;
DATASOURCE_PLUGIN(raster_datasource)
raster_datasource::raster_datasource(const parameters& params, bool bind)
: datasource(params),
desc_(*params.get<std::string>("type"),"utf-8"),
extent_initialized_(false)
: datasource(params),
desc_(*params.get<std::string>("type"), "utf-8"),
extent_initialized_(false)
{
#ifdef MAPNIK_DEBUG
std::clog << "Raster Plugin: Initializing..." << std::endl;
@ -69,7 +67,7 @@ raster_datasource::raster_datasource(const parameters& params, bool bind)
tile_size_ = *params_.get<unsigned>("tile_size", 256);
tile_stride_ = *params_.get<unsigned>("tile_stride", 1);
format_=*params_.get<std::string>("format","tiff");
format_ = *params_.get<std::string>("format","tiff");
boost::optional<double> lox = params_.get<double>("lox");
boost::optional<double> loy = params_.get<double>("loy");
@ -88,7 +86,9 @@ raster_datasource::raster_datasource(const parameters& params, bool bind)
}
if (! extent_initialized_)
{
throw datasource_exception("Raster Plugin: valid <extent> or <lox> <loy> <hix> <hiy> are required");
}
if (bind)
{
@ -102,42 +102,46 @@ void raster_datasource::bind() const
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)
throw datasource_exception("Raster Plugin: x-width parameter not supplied for multi-tiled data source.");
if (! x_width)
{
throw datasource_exception("Raster Plugin: x-width parameter not supplied for multi-tiled data source.");
}
if (!y_width)
throw datasource_exception("Raster Plugin: y-width parameter not supplied for multi-tiled data source.");
if (! y_width)
{
throw datasource_exception("Raster Plugin: y-width parameter not supplied for multi-tiled data source.");
}
width_ = x_width.get() * tile_size_;
height_ = y_width.get() * tile_size_;
width_ = x_width.get() * tile_size_;
height_ = y_width.get() * tile_size_;
}
else
{
if (! boost::filesystem::exists(filename_))
throw datasource_exception("Raster Plugin: " + filename_ + " does not exist");
if (! boost::filesystem::exists(filename_))
{
throw datasource_exception("Raster Plugin: " + filename_ + " does not exist");
}
try
{
std::auto_ptr<image_reader> reader(mapnik::get_image_reader(filename_, format_));
if (reader.get())
{
width_ = reader->width();
height_ = reader->height();
}
}
catch (mapnik::image_reader_exception const& ex)
{
std::cerr << "Raster Plugin: image reader exception caught: " << ex.what() << std::endl;
throw;
}
catch (...)
{
std::cerr << "Raster Plugin: exception caught" << std::endl;
throw;
}
try
{
std::auto_ptr<image_reader> reader(mapnik::get_image_reader(filename_, format_));
if (reader.get())
{
width_ = reader->width();
height_ = reader->height();
}
}
catch (mapnik::image_reader_exception const& ex)
{
throw datasource_exception("Raster Plugin: image reader exception: " + std::string(ex.what()));
}
catch (...)
{
throw datasource_exception("Raster Plugin: image reader unknown exception caught");
}
}
#ifdef MAPNIK_DEBUG
@ -193,6 +197,7 @@ featureset_ptr raster_datasource::features(query const& q) const
#endif
tiled_multi_file_policy policy(filename_, format_, tile_size_, extent_, q.get_bbox(), width_, height_, tile_stride_);
return boost::make_shared<raster_featureset<tiled_multi_file_policy> >(policy, extent_, q);
}
else if (width * height > 512*512)
@ -202,6 +207,7 @@ featureset_ptr raster_datasource::features(query const& q) const
#endif
tiled_file_policy policy(filename_, format_, 256, extent_, q.get_bbox(), width_, height_);
return boost::make_shared<raster_featureset<tiled_file_policy> >(policy, extent_, q);
}
else
@ -212,13 +218,16 @@ featureset_ptr raster_datasource::features(query const& q) const
raster_info info(filename_, format_, extent_, width_, height_);
single_file_policy policy(info);
return boost::make_shared<raster_featureset<single_file_policy> >(policy, extent_, q);
}
}
featureset_ptr raster_datasource::features_at_point(coord2d const&) const
{
std::clog << "Raster Plugin: ##WARNING: feature_at_point not supported for raster.input" << std::endl;
#ifdef MAPNIK_DEBUG
std::clog << "Raster Plugin: feature_at_point not supported for raster.input" << std::endl;
#endif
return featureset_ptr();
}

View file

@ -2,7 +2,7 @@
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2006 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
@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
//$Id: raster_datasource.hh 44 2005-04-22 18:53:54Z pavlenko $
#ifndef RASTER_DATASOURCE_HPP
#define RASTER_DATASOURCE_HPP
@ -31,31 +30,30 @@
class raster_datasource : public mapnik::datasource
{
private:
mapnik::layer_descriptor desc_;
std::string filename_;
std::string format_;
mapnik::box2d<double> extent_;
bool extent_initialized_;
bool multi_tiles_;
unsigned tile_size_;
unsigned tile_stride_;
mutable unsigned width_;
mutable unsigned height_;
public:
raster_datasource(const mapnik::parameters& params, bool bind=true);
virtual ~raster_datasource();
int type() const;
static std::string name();
mapnik::featureset_ptr features(const mapnik::query& 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:
//no copying
raster_datasource(const raster_datasource&);
raster_datasource& operator=(const raster_datasource&);
public:
raster_datasource(const mapnik::parameters& params, bool bind=true);
virtual ~raster_datasource();
int type() const;
static std::string name();
mapnik::featureset_ptr features(const mapnik::query& 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:
mapnik::layer_descriptor desc_;
std::string filename_;
std::string format_;
mapnik::box2d<double> extent_;
bool extent_initialized_;
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&);
};
#endif //RASTER_DATASOURCE_HPP
#endif // RASTER_DATASOURCE_HPP

View file

@ -2,7 +2,7 @@
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2006 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
@ -25,10 +25,11 @@
#include <mapnik/image_util.hpp>
#include <mapnik/feature_factory.hpp>
#include "raster_featureset.hpp"
// boost
#include <boost/algorithm/string/replace.hpp>
#include "raster_featureset.hpp"
using mapnik::query;
using mapnik::CoordTransform;
using mapnik::image_reader;
@ -42,101 +43,108 @@ template <typename LookupPolicy>
raster_featureset<LookupPolicy>::raster_featureset(LookupPolicy const& policy,
box2d<double> const& extent,
query const& q)
: policy_(policy),
feature_id_(1),
extent_(extent),
bbox_(q.get_bbox()),
curIter_(policy_.begin()),
endIter_(policy_.end())
{}
: policy_(policy),
feature_id_(1),
extent_(extent),
bbox_(q.get_bbox()),
curIter_(policy_.begin()),
endIter_(policy_.end())
{
}
template <typename LookupPolicy>
raster_featureset<LookupPolicy>::~raster_featureset() {}
raster_featureset<LookupPolicy>::~raster_featureset()
{
}
template <typename LookupPolicy>
feature_ptr raster_featureset<LookupPolicy>::next()
{
if (curIter_!=endIter_)
{
feature_ptr feature(feature_factory::create(feature_id_));
++feature_id_;
try
{
std::auto_ptr<image_reader> reader(mapnik::get_image_reader(curIter_->file(),curIter_->format()));
if (curIter_ != endIter_)
{
feature_ptr feature(feature_factory::create(feature_id_));
++feature_id_;
try
{
std::auto_ptr<image_reader> reader(mapnik::get_image_reader(curIter_->file(),curIter_->format()));
#ifdef MAPNIK_DEBUG
std::clog << "Raster Plugin: READER = " << curIter_->format() << " " << curIter_->file()
<< " size(" << curIter_->width() << "," << curIter_->height() << ")" << std::endl;
std::clog << "Raster Plugin: READER = " << curIter_->format() << " " << curIter_->file()
<< " size(" << curIter_->width() << "," << curIter_->height() << ")" << std::endl;
#endif
if (reader.get())
{
int image_width = policy_.img_width(reader->width());
int image_height = policy_.img_height(reader->height());
if (image_width>0 && image_height>0)
if (reader.get())
{
CoordTransform t(image_width,image_height,extent_,0,0);
box2d<double> intersect=bbox_.intersect(curIter_->envelope());
box2d<double> ext=t.forward(intersect);
box2d<double> rem=policy_.transform(ext);
if ( ext.width()>0.5 && ext.height()>0.5 )
{
//select minimum raster containing whole ext
int x_off = static_cast<int>(floor(ext.minx()));
int y_off = static_cast<int>(floor(ext.miny()));
int end_x = static_cast<int>(ceil(ext.maxx()));
int end_y = static_cast<int>(ceil(ext.maxy()));
//clip to available data
if (x_off < 0)
x_off = 0;
if (y_off < 0)
y_off = 0;
if (end_x > image_width)
end_x = image_width;
if (end_y > image_height)
end_y = image_height;
int width = end_x - x_off;
int height = end_y - y_off;
//calculate actual box2d of returned raster
box2d<double> feature_raster_extent(rem.minx() + x_off, rem.miny() + y_off,
rem.maxx() + x_off + width, rem.maxy() + y_off + height);
intersect = t.backward(feature_raster_extent);
int image_width = policy_.img_width(reader->width());
int image_height = policy_.img_height(reader->height());
if (image_width > 0 && image_height > 0)
{
CoordTransform t(image_width, image_height, extent_, 0, 0);
box2d<double> intersect = bbox_.intersect(curIter_->envelope());
box2d<double> ext = t.forward(intersect);
box2d<double> rem = policy_.transform(ext);
if (ext.width() > 0.5 && ext.height() > 0.5 )
{
// select minimum raster containing whole ext
int x_off = static_cast<int>(floor(ext.minx()));
int y_off = static_cast<int>(floor(ext.miny()));
int end_x = static_cast<int>(ceil(ext.maxx()));
int end_y = static_cast<int>(ceil(ext.maxy()));
image_data_32 image(width,height);
reader->read(x_off,y_off,image);
feature->set_raster(boost::make_shared<raster>(intersect,image));
}
// clip to available data
if (x_off < 0)
x_off = 0;
if (y_off < 0)
y_off = 0;
if (end_x > image_width)
end_x = image_width;
if (end_y > image_height)
end_y = image_height;
int width = end_x - x_off;
int height = end_y - y_off;
// calculate actual box2d of returned raster
box2d<double> feature_raster_extent(rem.minx() + x_off,
rem.miny() + y_off,
rem.maxx() + x_off + width,
rem.maxy() + y_off + height);
intersect = t.backward(feature_raster_extent);
image_data_32 image(width,height);
reader->read(x_off, y_off, image);
feature->set_raster(boost::make_shared<raster>(intersect, image));
}
}
}
}
}
catch (mapnik::image_reader_exception const& ex)
{
std::cerr << "Raster Plugin: image reader exception caught:" << ex.what() << std::endl;
}
catch (...)
{
std::cerr << "Raster Plugin: exception caught" << std::endl;
}
}
catch (mapnik::image_reader_exception const& ex)
{
std::cerr << "Raster Plugin: image reader exception caught:" << ex.what() << std::endl;
}
catch (...)
{
std::cerr << "Raster Plugin: exception caught" << std::endl;
}
++curIter_;
return feature;
}
return feature_ptr();
++curIter_;
return feature;
}
return feature_ptr();
}
std::string
tiled_multi_file_policy::interpolate(std::string const &pattern, int x, int y) const
std::string tiled_multi_file_policy::interpolate(std::string const& pattern, int x, int y) const
{
// TODO: make from some sort of configurable interpolation
int tms_y = tile_stride_ * ((image_height_ / tile_size_) - y - 1);
int tms_x = tile_stride_ * x;
std::string xs = (boost::format("%03d/%03d/%03d") % (tms_x / 1000000) % ((tms_x / 1000) % 1000) % (tms_x % 1000)).str();
std::string ys = (boost::format("%03d/%03d/%03d") % (tms_y / 1000000) % ((tms_y / 1000) % 1000) % (tms_y % 1000)).str();
std::string rv(pattern);
boost::algorithm::replace_all(rv, "${x}", xs);
boost::algorithm::replace_all(rv, "${y}", ys);
return rv;
// TODO: make from some sort of configurable interpolation
int tms_y = tile_stride_ * ((image_height_ / tile_size_) - y - 1);
int tms_x = tile_stride_ * x;
std::string xs = (boost::format("%03d/%03d/%03d") % (tms_x / 1000000) % ((tms_x / 1000) % 1000) % (tms_x % 1000)).str();
std::string ys = (boost::format("%03d/%03d/%03d") % (tms_y / 1000000) % ((tms_y / 1000) % 1000) % (tms_y % 1000)).str();
std::string rv(pattern);
boost::algorithm::replace_all(rv, "${x}", xs);
boost::algorithm::replace_all(rv, "${y}", ys);
return rv;
}
template class raster_featureset<single_file_policy>;

View file

@ -2,7 +2,7 @@
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2006 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
@ -19,14 +19,16 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef RASTER_FEATURESET_HPP
#define RASTER_FEATURESET_HPP
#include <vector>
#include "raster_datasource.hpp"
#include "raster_info.hpp"
// stl
#include <vector>
// boost
#include <boost/utility.hpp>
#include <boost/format.hpp>
@ -42,19 +44,19 @@ public:
const single_file_policy* p_;
public:
explicit const_iterator(const single_file_policy* p)
:status_(start),
p_(p) {}
: status_(start),
p_(p) {}
const_iterator()
:status_(end){}
: status_(end) {}
const_iterator(const const_iterator& other)
:status_(other.status_),
p_(other.p_) {}
: status_(other.status_),
p_(other.p_) {}
const_iterator& operator++()
{
status_=end;
status_ = end;
return *this;
}
@ -70,12 +72,12 @@ public:
bool operator!=(const const_iterator& itr)
{
return status_!=itr.status_;
return status_ != itr.status_;
}
};
explicit single_file_policy(const raster_info& info)
:info_(info) {}
: info_(info) {}
const_iterator begin()
{
@ -96,213 +98,226 @@ public:
return const_iterator();
}
inline int img_width(int reader_width) const
{
return reader_width;
}
inline int img_width(int reader_width) const
{
return reader_width;
}
inline int img_height(int reader_height) const
{
return reader_height;
}
inline int img_height(int reader_height) const
{
return reader_height;
}
inline box2d<double> transform(box2d<double> &) const
{
return box2d<double>(0, 0, 0, 0);
}
inline box2d<double> transform(box2d<double> &) const
{
return box2d<double>(0, 0, 0, 0);
}
};
class tiled_file_policy
{
public:
typedef std::vector<raster_info>::const_iterator const_iterator;
typedef std::vector<raster_info>::const_iterator const_iterator;
tiled_file_policy(std::string const& file, std::string const& format, unsigned tile_size,
box2d<double> extent, box2d<double> bbox,unsigned width, unsigned height)
{
double lox = extent.minx();
double loy = extent.miny();
tiled_file_policy(std::string const& file,
std::string const& format,
unsigned tile_size,
box2d<double> extent,
box2d<double> bbox,
unsigned width,
unsigned height)
{
double lox = extent.minx();
double loy = extent.miny();
int max_x = int(std::ceil(double(width)/double(tile_size)));
int max_y = int(std::ceil(double(height)/double(tile_size)));
int max_x = int(std::ceil(double(width) / double(tile_size)));
int max_y = int(std::ceil(double(height) / double(tile_size)));
double pixel_x = extent.width()/double(width);
double pixel_y = extent.height()/double(height);
double pixel_x = extent.width() / double(width);
double pixel_y = extent.height() / double(height);
#ifdef MAPNIK_DEBUG
std::clog << "Raster Plugin: PIXEL SIZE("<< pixel_x << "," << pixel_y << ")" << std::endl;
std::clog << "Raster Plugin: PIXEL SIZE("<< pixel_x << "," << pixel_y << ")" << std::endl;
#endif
box2d<double> e = bbox.intersect(extent);
box2d<double> e = bbox.intersect(extent);
for (int x = 0 ; x < max_x ; ++x)
{
for (int y = 0 ; y < max_y ; ++y)
{
double x0 = lox + x*tile_size*pixel_x;
double y0 = loy + y*tile_size*pixel_y;
double x1 = x0 + tile_size*pixel_x;
double y1 = y0 + tile_size*pixel_y;
if (e.intersects(box2d<double>(x0,y0,x1,y1)))
for (int x = 0; x < max_x; ++x)
{
for (int y = 0; y < max_y; ++y)
{
box2d<double> tile_box = e.intersect(box2d<double>(x0,y0,x1,y1));
raster_info info(file,format,tile_box,tile_size,tile_size);
infos_.push_back(info);
double x0 = lox + x * tile_size * pixel_x;
double y0 = loy + y * tile_size * pixel_y;
double x1 = x0 + tile_size * pixel_x;
double y1 = y0 + tile_size * pixel_y;
if (e.intersects(box2d<double>(x0, y0, x1, y1)))
{
box2d<double> tile_box = e.intersect(box2d<double>(x0,y0,x1,y1));
raster_info info(file,format,tile_box,tile_size,tile_size);
infos_.push_back(info);
}
}
}
}
}
#ifdef MAPNIK_DEBUG
std::clog << "Raster Plugin: INFO SIZE=" << infos_.size() << " " << file << std::endl;
std::clog << "Raster Plugin: INFO SIZE=" << infos_.size() << " " << file << std::endl;
#endif
}
}
const_iterator begin()
{
return infos_.begin();
}
const_iterator begin()
{
return infos_.begin();
}
const_iterator end()
{
return infos_.end();
}
const_iterator end()
{
return infos_.end();
}
inline int img_width(int reader_width) const
{
return reader_width;
}
inline int img_width(int reader_width) const
{
return reader_width;
}
inline int img_height(int reader_height) const
{
return reader_height;
}
inline int img_height(int reader_height) const
{
return reader_height;
}
inline box2d<double> transform(box2d<double> &) const
{
return box2d<double>(0, 0, 0, 0);
}
inline box2d<double> transform(box2d<double>&) const
{
return box2d<double>(0, 0, 0, 0);
}
private:
std::vector<raster_info> infos_;
std::vector<raster_info> infos_;
};
class tiled_multi_file_policy
{
public:
typedef std::vector<raster_info>::const_iterator const_iterator;
typedef std::vector<raster_info>::const_iterator const_iterator;
tiled_multi_file_policy(std::string const& file_pattern, std::string const& format, unsigned tile_size,
box2d<double> extent, box2d<double> bbox,unsigned width, unsigned height,
unsigned tile_stride)
: image_width_(width), image_height_(height), tile_size_(tile_size), tile_stride_(tile_stride)
{
double lox = extent.minx();
double loy = extent.miny();
tiled_multi_file_policy(std::string const& file_pattern,
std::string const& format,
unsigned tile_size,
box2d<double> extent,
box2d<double> bbox,
unsigned width,
unsigned height,
unsigned tile_stride)
: image_width_(width),
image_height_(height),
tile_size_(tile_size),
tile_stride_(tile_stride)
{
double lox = extent.minx();
double loy = extent.miny();
int max_x = int(std::ceil(double(width)/double(tile_size)));
int max_y = int(std::ceil(double(height)/double(tile_size)));
//int max_x = int(std::ceil(double(width) / double(tile_size)));
//int max_y = int(std::ceil(double(height) / double(tile_size)));
double pixel_x = extent.width()/double(width);
double pixel_y = extent.height()/double(height);
double pixel_x = extent.width() / double(width);
double pixel_y = extent.height() / double(height);
#ifdef MAPNIK_DEBUG
std::clog << "Raster Plugin: PIXEL SIZE("<< pixel_x << "," << pixel_y << ")" << std::endl;
std::clog << "Raster Plugin: PIXEL SIZE("<< pixel_x << "," << pixel_y << ")" << std::endl;
#endif
// intersection of query with extent => new query
box2d<double> e = bbox.intersect(extent);
// intersection of query with extent => new query
box2d<double> e = bbox.intersect(extent);
const int x_min = int(std::floor((e.minx() - lox) / (tile_size * pixel_x)));
const int y_min = int(std::floor((e.miny() - loy) / (tile_size * pixel_y)));
const int x_max = int(std::ceil((e.maxx() - lox) / (tile_size * pixel_x)));
const int y_max = int(std::ceil((e.maxy() - loy) / (tile_size * pixel_y)));
const int x_min = int(std::floor((e.minx() - lox) / (tile_size * pixel_x)));
const int y_min = int(std::floor((e.miny() - loy) / (tile_size * pixel_y)));
const int x_max = int(std::ceil((e.maxx() - lox) / (tile_size * pixel_x)));
const int y_max = int(std::ceil((e.maxy() - loy) / (tile_size * pixel_y)));
for (int x = x_min ; x < x_max ; ++x)
{
for (int y = y_min ; y < y_max ; ++y)
{
// x0, y0, x1, y1 => projection-space image coordinates.
double x0 = lox + x*tile_size*pixel_x;
double y0 = loy + y*tile_size*pixel_y;
double x1 = x0 + tile_size*pixel_x;
double y1 = y0 + tile_size*pixel_y;
// check if it intersects the query
if (e.intersects(box2d<double>(x0,y0,x1,y1)))
for (int x = x_min; x < x_max; ++x)
{
for (int y = y_min; y < y_max; ++y)
{
// tile_box => intersection of tile with query in projection-space.
box2d<double> tile_box = e.intersect(box2d<double>(x0,y0,x1,y1));
std::string file = interpolate(file_pattern, x, y);
raster_info info(file,format,tile_box,tile_size,tile_size);
infos_.push_back(info);
// x0, y0, x1, y1 => projection-space image coordinates.
double x0 = lox + x*tile_size*pixel_x;
double y0 = loy + y*tile_size*pixel_y;
double x1 = x0 + tile_size*pixel_x;
double y1 = y0 + tile_size*pixel_y;
// check if it intersects the query
if (e.intersects(box2d<double>(x0,y0,x1,y1)))
{
// tile_box => intersection of tile with query in projection-space.
box2d<double> tile_box = e.intersect(box2d<double>(x0,y0,x1,y1));
std::string file = interpolate(file_pattern, x, y);
raster_info info(file,format,tile_box,tile_size,tile_size);
infos_.push_back(info);
}
}
}
}
}
#ifdef MAPNIK_DEBUG
std::clog << "Raster Plugin: INFO SIZE=" << infos_.size() << " " << file_pattern << std::endl;
std::clog << "Raster Plugin: INFO SIZE=" << infos_.size() << " " << file_pattern << std::endl;
#endif
}
}
const_iterator begin()
{
return infos_.begin();
}
const_iterator end()
{
return infos_.end();
}
const_iterator begin()
{
return infos_.begin();
}
const_iterator end()
{
return infos_.end();
}
inline int img_width(int) const
{
return image_width_;
}
inline int img_width(int) const
{
return image_width_;
}
inline int img_height(int) const
{
return image_height_;
}
inline int img_height(int) const
{
return image_height_;
}
inline box2d<double> transform(box2d<double> &box) const
{
int x_offset = int(std::floor(box.minx() / tile_size_));
int y_offset = int(std::floor(box.miny() / tile_size_));
box2d<double> rem(x_offset * tile_size_, y_offset * tile_size_,
x_offset * tile_size_, y_offset * tile_size_);
box.init(box.minx() - rem.minx(),
box.miny() - rem.miny(),
box.maxx() - rem.maxx(),
box.maxy() - rem.maxy());
return rem;
}
inline box2d<double> transform(box2d<double>& box) const
{
int x_offset = int(std::floor(box.minx() / tile_size_));
int y_offset = int(std::floor(box.miny() / tile_size_));
box2d<double> rem(x_offset * tile_size_,
y_offset * tile_size_,
x_offset * tile_size_,
y_offset * tile_size_);
box.init(box.minx() - rem.minx(),
box.miny() - rem.miny(),
box.maxx() - rem.maxx(),
box.maxy() - rem.maxy());
return rem;
}
private:
std::string interpolate(std::string const &pattern, int x, int y) const;
std::string interpolate(std::string const& pattern, int x, int y) const;
unsigned int image_width_, image_height_, tile_size_, tile_stride_;
std::vector<raster_info> infos_;
unsigned int image_width_, image_height_, tile_size_, tile_stride_;
std::vector<raster_info> infos_;
};
template <typename LookupPolicy>
class raster_featureset : public mapnik::Featureset
{
typedef typename LookupPolicy::const_iterator iterator_type;
LookupPolicy policy_;
int feature_id_;
mapnik::box2d<double> extent_;
mapnik::box2d<double> bbox_;
iterator_type curIter_;
iterator_type endIter_;
typedef typename LookupPolicy::const_iterator iterator_type;
LookupPolicy policy_;
int feature_id_;
mapnik::box2d<double> extent_;
mapnik::box2d<double> bbox_;
iterator_type curIter_;
iterator_type endIter_;
public:
raster_featureset(LookupPolicy const& policy,box2d<double> const& exttent, mapnik::query const& q);
virtual ~raster_featureset();
mapnik::feature_ptr next();
raster_featureset(LookupPolicy const& policy,box2d<double> const& exttent, mapnik::query const& q);
virtual ~raster_featureset();
mapnik::feature_ptr next();
};
#endif //RASTER_FEATURESET_HPP
#endif // RASTER_FEATURESET_HPP

View file

@ -2,7 +2,7 @@
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2006 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
@ -19,32 +19,38 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
//$Id: raster_info.cc 17 2005-03-08 23:58:43Z pavlenko $
#include "raster_info.hpp"
raster_info::raster_info(std::string const& file, std::string const& format,
mapnik::box2d<double> const& extent, unsigned width, unsigned height)
:file_(file),
format_(format),
extent_(extent),
width_(width),
height_(height) {}
raster_info::raster_info(std::string const& file,
std::string const& format,
mapnik::box2d<double> const& extent,
unsigned width,
unsigned height)
: file_(file),
format_(format),
extent_(extent),
width_(width),
height_(height)
{
}
raster_info::raster_info(const raster_info& rhs)
:file_(rhs.file_),
format_(rhs.format_),
extent_(rhs.extent_),
width_(rhs.width_),
height_(rhs.height_) {}
: file_(rhs.file_),
format_(rhs.format_),
extent_(rhs.extent_),
width_(rhs.width_),
height_(rhs.height_)
{
}
void raster_info::swap(raster_info& other) throw()
{
file_=other.file_;
format_=other.format_;
extent_=other.extent_;
width_=other.width_;
height_=other.height_;
file_ = other.file_;
format_ = other.format_;
extent_ = other.extent_;
width_ = other.width_;
height_ = other.height_;
}
@ -54,6 +60,3 @@ raster_info& raster_info::operator=(const raster_info& rhs)
swap(tmp);
return *this;
}

View file

@ -2,7 +2,7 @@
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2006 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
@ -19,25 +19,25 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
//$Id: raster_info.hh 17 2005-03-08 23:58:43Z pavlenko $
#ifndef RASTER_INFO_HPP
#define RASTER_INFO_HPP
#include "raster_datasource.hpp"
// stl
#include <string>
using mapnik::box2d;
class raster_info
{
std::string file_;
std::string format_;
box2d<double> extent_;
unsigned width_;
unsigned height_;
public:
raster_info(const std::string& file,const std::string& format, const box2d<double>& extent, unsigned width, unsigned height);
raster_info(const std::string& file,
const std::string& format,
const box2d<double>& extent,
unsigned width,
unsigned height);
raster_info(const raster_info& rhs);
raster_info& operator=(const raster_info& rhs);
inline box2d<double> const& envelope() const {return extent_;}
@ -48,6 +48,12 @@ public:
private:
void swap(raster_info& other) throw();
std::string file_;
std::string format_;
box2d<double> extent_;
unsigned width_;
unsigned height_;
};
#endif //RASTER_INFO_HPP
#endif // RASTER_INFO_HPP