2006-03-31 10:32:02 +00:00
|
|
|
/*****************************************************************************
|
2011-11-14 03:37:50 +00:00
|
|
|
*
|
2006-03-31 10:32:02 +00:00
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
2005-06-14 15:06:59 +00:00
|
|
|
*
|
2021-01-05 14:39:07 +00:00
|
|
|
* Copyright (C) 2021 Artem Pavlenko
|
2005-06-14 15:06:59 +00:00
|
|
|
*
|
2006-03-31 10:32:02 +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,
|
2005-06-14 15:06:59 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2006-03-31 10:32:02 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2005-06-14 15:06:59 +00:00
|
|
|
*
|
2006-03-31 10:32:02 +00:00
|
|
|
* 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-10-23 14:31:25 +00:00
|
|
|
|
2009-04-10 12:05:31 +00:00
|
|
|
#ifndef RASTER_FEATURESET_HPP
|
|
|
|
#define RASTER_FEATURESET_HPP
|
2005-06-14 15:06:59 +00:00
|
|
|
|
2005-09-21 20:27:37 +00:00
|
|
|
#include "raster_datasource.hpp"
|
|
|
|
#include "raster_info.hpp"
|
2005-06-14 15:06:59 +00:00
|
|
|
|
2012-04-08 00:20:56 +00:00
|
|
|
// mapnik
|
2013-01-04 17:23:06 +00:00
|
|
|
#include <mapnik/feature.hpp>
|
2012-04-08 00:20:56 +00:00
|
|
|
#include <mapnik/debug.hpp>
|
|
|
|
|
2011-10-23 14:31:25 +00:00
|
|
|
// stl
|
|
|
|
#include <vector>
|
|
|
|
|
2009-10-12 03:58:11 +00:00
|
|
|
// boost
|
2009-04-10 12:05:31 +00:00
|
|
|
#include <boost/utility.hpp>
|
2009-10-12 03:58:11 +00:00
|
|
|
|
2005-06-14 15:06:59 +00:00
|
|
|
class single_file_policy
|
|
|
|
{
|
2005-09-21 20:27:37 +00:00
|
|
|
raster_info info_;
|
2022-01-26 09:43:31 +00:00
|
|
|
|
|
|
|
public:
|
2005-06-14 15:06:59 +00:00
|
|
|
class const_iterator
|
|
|
|
{
|
2022-01-26 09:43:31 +00:00
|
|
|
enum iterator_e { start, end };
|
2006-09-12 14:29:22 +00:00
|
|
|
bool status_;
|
|
|
|
const single_file_policy* p_;
|
2022-01-26 09:43:31 +00:00
|
|
|
|
|
|
|
public:
|
2006-09-12 14:29:22 +00:00
|
|
|
explicit const_iterator(const single_file_policy* p)
|
2022-01-26 09:43:31 +00:00
|
|
|
: status_(start)
|
|
|
|
, p_(p)
|
|
|
|
{}
|
2006-09-12 14:29:22 +00:00
|
|
|
|
|
|
|
const_iterator()
|
2022-01-26 09:43:31 +00:00
|
|
|
: status_(end)
|
|
|
|
{}
|
2006-09-12 14:29:22 +00:00
|
|
|
|
|
|
|
const_iterator(const const_iterator& other)
|
2022-01-26 09:43:31 +00:00
|
|
|
: status_(other.status_)
|
|
|
|
, p_(other.p_)
|
|
|
|
{}
|
2006-09-12 14:29:22 +00:00
|
|
|
|
|
|
|
const_iterator& operator++()
|
|
|
|
{
|
2011-10-23 14:31:25 +00:00
|
|
|
status_ = end;
|
2006-09-12 14:29:22 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
const raster_info& operator*() const { return p_->info_; }
|
2006-09-12 14:29:22 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
const raster_info* operator->() const { return &(p_->info_); }
|
2006-09-12 14:29:22 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
bool operator!=(const const_iterator& itr) { return status_ != itr.status_; }
|
2005-06-14 15:06:59 +00:00
|
|
|
};
|
|
|
|
|
2005-09-21 20:27:37 +00:00
|
|
|
explicit single_file_policy(const raster_info& info)
|
2022-01-26 09:43:31 +00:00
|
|
|
: info_(info)
|
|
|
|
{}
|
2005-06-14 15:06:59 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
const_iterator begin() { return const_iterator(this); }
|
2005-06-14 15:06:59 +00:00
|
|
|
|
2009-12-16 20:02:06 +00:00
|
|
|
const_iterator query(const box2d<double>& box)
|
2005-06-14 15:06:59 +00:00
|
|
|
{
|
2006-09-12 14:29:22 +00:00
|
|
|
if (box.intersects(info_.envelope()))
|
|
|
|
{
|
|
|
|
return begin();
|
|
|
|
}
|
|
|
|
return end();
|
2005-06-14 15:06:59 +00:00
|
|
|
}
|
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
const_iterator end() { return const_iterator(); }
|
2011-10-12 00:08:03 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
inline int img_width(int reader_width) const { return reader_width; }
|
2011-10-12 00:08:03 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
inline int img_height(int reader_height) const { return reader_height; }
|
2011-10-12 00:08:03 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
inline box2d<double> transform(box2d<double>&) const { return box2d<double>(0, 0, 0, 0); }
|
2005-06-14 15:06:59 +00:00
|
|
|
};
|
|
|
|
|
2009-04-10 12:05:31 +00:00
|
|
|
class tiled_file_policy
|
|
|
|
{
|
2022-01-26 09:43:31 +00:00
|
|
|
public:
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2014-07-07 17:23:15 +00:00
|
|
|
using const_iterator = std::vector<raster_info>::const_iterator;
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2011-10-23 14:31:25 +00:00
|
|
|
tiled_file_policy(std::string const& file,
|
|
|
|
std::string const& format,
|
|
|
|
unsigned tile_size,
|
2013-03-14 09:33:59 +00:00
|
|
|
box2d<double> const& extent,
|
|
|
|
box2d<double> const& bbox,
|
2011-10-23 14:31:25 +00:00
|
|
|
unsigned width,
|
|
|
|
unsigned height)
|
|
|
|
{
|
|
|
|
double lox = extent.minx();
|
|
|
|
double loy = extent.miny();
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2011-10-23 14:31:25 +00:00
|
|
|
int max_x = int(std::ceil(double(width) / double(tile_size)));
|
|
|
|
int max_y = int(std::ceil(double(height) / double(tile_size)));
|
2009-04-10 12:05:31 +00:00
|
|
|
|
2011-10-23 14:31:25 +00:00
|
|
|
double pixel_x = extent.width() / double(width);
|
|
|
|
double pixel_y = extent.height() / double(height);
|
2009-10-12 03:58:11 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
MAPNIK_LOG_DEBUG(raster) << "tiled_file_policy: Raster Plugin PIXEL SIZE(" << pixel_x << "," << pixel_y << ")";
|
2009-10-12 03:58:11 +00:00
|
|
|
|
2011-10-23 14:31:25 +00:00
|
|
|
box2d<double> e = bbox.intersect(extent);
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2011-10-23 14:31:25 +00:00
|
|
|
for (int x = 0; x < max_x; ++x)
|
|
|
|
{
|
|
|
|
for (int y = 0; y < max_y; ++y)
|
2009-04-10 12:05:31 +00:00
|
|
|
{
|
2011-10-23 14:31:25 +00:00
|
|
|
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;
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2011-10-23 14:31:25 +00:00
|
|
|
if (e.intersects(box2d<double>(x0, y0, x1, y1)))
|
|
|
|
{
|
2022-01-26 09:43:31 +00:00
|
|
|
box2d<double> tile_box = e.intersect(box2d<double>(x0, y0, x1, y1));
|
|
|
|
raster_info info(file, format, tile_box, tile_size, tile_size);
|
2011-10-23 14:31:25 +00:00
|
|
|
infos_.push_back(info);
|
|
|
|
}
|
2009-04-10 12:05:31 +00:00
|
|
|
}
|
2011-10-23 14:31:25 +00:00
|
|
|
}
|
2012-04-08 00:20:56 +00:00
|
|
|
|
2012-04-09 01:00:51 +00:00
|
|
|
MAPNIK_LOG_DEBUG(raster) << "tiled_file_policy: Raster Plugin INFO SIZE=" << infos_.size() << " " << file;
|
2011-10-23 14:31:25 +00:00
|
|
|
}
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
const_iterator begin() { return infos_.begin(); }
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
const_iterator end() { return infos_.end(); }
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
inline int img_width(int reader_width) const { return reader_width; }
|
2011-10-12 00:08:03 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
inline int img_height(int reader_height) const { return reader_height; }
|
2011-10-12 00:08:03 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
inline box2d<double> transform(box2d<double>&) const { return box2d<double>(0, 0, 0, 0); }
|
2011-10-12 00:08:03 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
private:
|
2009-04-10 12:05:31 +00:00
|
|
|
|
2011-10-23 14:31:25 +00:00
|
|
|
std::vector<raster_info> infos_;
|
2009-04-10 12:05:31 +00:00
|
|
|
};
|
|
|
|
|
2011-10-12 00:08:03 +00:00
|
|
|
class tiled_multi_file_policy
|
|
|
|
{
|
2022-01-26 09:43:31 +00:00
|
|
|
public:
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2014-07-07 17:23:15 +00:00
|
|
|
using const_iterator = std::vector<raster_info>::const_iterator;
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2011-10-23 14:31:25 +00:00
|
|
|
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)
|
2022-01-26 09:43:31 +00:00
|
|
|
: image_width_(width)
|
|
|
|
, image_height_(height)
|
|
|
|
, tile_size_(tile_size)
|
|
|
|
, tile_stride_(tile_stride)
|
2011-10-23 14:31:25 +00:00
|
|
|
{
|
|
|
|
double lox = extent.minx();
|
|
|
|
double loy = extent.miny();
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
// int max_x = int(std::ceil(double(width) / double(tile_size)));
|
|
|
|
// int max_y = int(std::ceil(double(height) / double(tile_size)));
|
2011-10-12 00:08:03 +00:00
|
|
|
|
2011-10-23 14:31:25 +00:00
|
|
|
double pixel_x = extent.width() / double(width);
|
|
|
|
double pixel_y = extent.height() / double(height);
|
2011-10-12 00:08:03 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
MAPNIK_LOG_DEBUG(raster) << "tiled_multi_file_policy: Raster Plugin PIXEL SIZE(" << pixel_x << "," << pixel_y
|
|
|
|
<< ")";
|
2011-10-12 00:08:03 +00:00
|
|
|
|
2011-10-23 14:31:25 +00:00
|
|
|
// intersection of query with extent => new query
|
|
|
|
box2d<double> e = bbox.intersect(extent);
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2011-10-23 14:31:25 +00:00
|
|
|
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)
|
2011-10-12 00:08:03 +00:00
|
|
|
{
|
2011-10-23 14:31:25 +00:00
|
|
|
// x0, y0, x1, y1 => projection-space image coordinates.
|
2022-01-26 09:43:31 +00:00
|
|
|
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;
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2011-10-23 14:31:25 +00:00
|
|
|
// check if it intersects the query
|
2022-01-26 09:43:31 +00:00
|
|
|
if (e.intersects(box2d<double>(x0, y0, x1, y1)))
|
2011-10-23 14:31:25 +00:00
|
|
|
{
|
|
|
|
// tile_box => intersection of tile with query in projection-space.
|
2022-01-26 09:43:31 +00:00
|
|
|
box2d<double> tile_box = e.intersect(box2d<double>(x0, y0, x1, y1));
|
2011-10-23 14:31:25 +00:00
|
|
|
std::string file = interpolate(file_pattern, x, y);
|
2022-01-26 09:43:31 +00:00
|
|
|
raster_info info(file, format, tile_box, tile_size, tile_size);
|
2011-10-23 14:31:25 +00:00
|
|
|
infos_.push_back(info);
|
|
|
|
}
|
2011-10-12 00:08:03 +00:00
|
|
|
}
|
2011-10-23 14:31:25 +00:00
|
|
|
}
|
2012-04-08 00:20:56 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
MAPNIK_LOG_DEBUG(raster) << "tiled_multi_file_policy: Raster Plugin INFO SIZE=" << infos_.size() << " "
|
|
|
|
<< file_pattern;
|
2011-10-23 14:31:25 +00:00
|
|
|
}
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
const_iterator begin() { return infos_.begin(); }
|
2011-10-23 14:31:25 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
const_iterator end() { return infos_.end(); }
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
inline int img_width(int) const { return image_width_; }
|
2011-10-23 14:31:25 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
inline int img_height(int) const { return image_height_; }
|
2011-10-23 14:31:25 +00:00
|
|
|
|
|
|
|
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_));
|
2022-01-26 09:43:31 +00:00
|
|
|
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());
|
2011-10-23 14:31:25 +00:00
|
|
|
return rem;
|
|
|
|
}
|
2011-10-12 00:08:03 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
private:
|
2011-10-12 00:08:03 +00:00
|
|
|
|
2011-10-23 14:31:25 +00:00
|
|
|
std::string interpolate(std::string const& pattern, int x, int y) const;
|
2011-10-12 00:08:03 +00:00
|
|
|
|
2011-10-23 14:31:25 +00:00
|
|
|
unsigned int image_width_, image_height_, tile_size_, tile_stride_;
|
|
|
|
std::vector<raster_info> infos_;
|
2011-10-12 00:08:03 +00:00
|
|
|
};
|
2009-04-10 12:05:31 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
template<typename LookupPolicy>
|
2007-03-16 10:11:37 +00:00
|
|
|
class raster_featureset : public mapnik::Featureset
|
2005-06-14 15:06:59 +00:00
|
|
|
{
|
2014-07-07 17:23:15 +00:00
|
|
|
using iterator_type = typename LookupPolicy::const_iterator;
|
2012-04-09 01:00:51 +00:00
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
public:
|
|
|
|
raster_featureset(LookupPolicy const& policy, box2d<double> const& exttent, mapnik::query const& q);
|
2012-04-09 01:00:51 +00:00
|
|
|
virtual ~raster_featureset();
|
|
|
|
mapnik::feature_ptr next();
|
|
|
|
|
2022-01-26 09:43:31 +00:00
|
|
|
private:
|
2011-10-23 14:31:25 +00:00
|
|
|
LookupPolicy policy_;
|
2012-12-20 03:24:52 +00:00
|
|
|
mapnik::value_integer feature_id_;
|
2012-01-16 14:51:31 +00:00
|
|
|
mapnik::context_ptr ctx_;
|
2011-10-23 14:31:25 +00:00
|
|
|
mapnik::box2d<double> extent_;
|
|
|
|
mapnik::box2d<double> bbox_;
|
|
|
|
iterator_type curIter_;
|
|
|
|
iterator_type endIter_;
|
2017-06-13 14:17:54 +00:00
|
|
|
double filter_factor_;
|
2005-06-14 15:06:59 +00:00
|
|
|
};
|
|
|
|
|
2011-10-23 14:31:25 +00:00
|
|
|
#endif // RASTER_FEATURESET_HPP
|