2006-03-31 12:32:02 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
2005-06-14 17:06:59 +02:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
* Copyright (C) 2006 Artem Pavlenko
|
2005-06-14 17:06:59 +02:00
|
|
|
*
|
2006-03-31 12:32:02 +02: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 17:06:59 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2006-03-31 12:32:02 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2005-06-14 17:06:59 +02:00
|
|
|
*
|
2006-03-31 12:32:02 +02: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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2009-04-10 14:05:31 +02:00
|
|
|
#ifndef RASTER_FEATURESET_HPP
|
|
|
|
#define RASTER_FEATURESET_HPP
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2006-10-04 13:22:18 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2005-09-21 22:27:37 +02:00
|
|
|
#include "raster_datasource.hpp"
|
|
|
|
#include "raster_info.hpp"
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2009-04-10 14:05:31 +02:00
|
|
|
#include <boost/utility.hpp>
|
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
class single_file_policy
|
|
|
|
{
|
2005-09-21 22:27:37 +02:00
|
|
|
raster_info info_;
|
2005-06-14 17:06:59 +02:00
|
|
|
public:
|
|
|
|
class const_iterator
|
|
|
|
{
|
2007-03-16 11:11:37 +01:00
|
|
|
enum iterator_e {start,end};
|
2006-09-12 16:29:22 +02:00
|
|
|
bool status_;
|
|
|
|
const single_file_policy* p_;
|
2005-06-14 17:06:59 +02:00
|
|
|
public:
|
2006-09-12 16:29:22 +02:00
|
|
|
explicit const_iterator(const single_file_policy* p)
|
|
|
|
:status_(start),
|
|
|
|
p_(p) {}
|
|
|
|
|
|
|
|
const_iterator()
|
|
|
|
:status_(end){}
|
|
|
|
|
|
|
|
const_iterator(const const_iterator& other)
|
|
|
|
:status_(other.status_),
|
|
|
|
p_(other.p_) {}
|
|
|
|
|
|
|
|
const_iterator& operator++()
|
|
|
|
{
|
|
|
|
status_=end;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
const raster_info& operator*() const
|
|
|
|
{
|
|
|
|
return p_->info_;
|
|
|
|
}
|
|
|
|
|
|
|
|
const raster_info* operator->() const
|
|
|
|
{
|
|
|
|
return &(p_->info_);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const const_iterator& itr)
|
|
|
|
{
|
|
|
|
return status_!=itr.status_;
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
};
|
|
|
|
|
2005-09-21 22:27:37 +02:00
|
|
|
explicit single_file_policy(const raster_info& info)
|
2006-09-12 16:29:22 +02:00
|
|
|
:info_(info) {}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
|
|
|
const_iterator begin()
|
|
|
|
{
|
2006-09-12 16:29:22 +02:00
|
|
|
return const_iterator(this);
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const_iterator query(const Envelope<double>& box)
|
|
|
|
{
|
2006-09-12 16:29:22 +02:00
|
|
|
if (box.intersects(info_.envelope()))
|
|
|
|
{
|
|
|
|
return begin();
|
|
|
|
}
|
|
|
|
return end();
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const_iterator end()
|
|
|
|
{
|
2006-09-12 16:29:22 +02:00
|
|
|
return const_iterator();
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-04-10 14:05:31 +02:00
|
|
|
class tiled_file_policy
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef std::vector<raster_info>::const_iterator const_iterator;
|
|
|
|
|
|
|
|
tiled_file_policy(std::string const& file, std::string const& format, unsigned tile_size,
|
|
|
|
Envelope<double> extent, Envelope<double> bbox,unsigned width, unsigned height)
|
|
|
|
{
|
|
|
|
|
|
|
|
double lox = extent.minx();
|
|
|
|
double loy = extent.miny();
|
|
|
|
|
|
|
|
int max_x = int(ceil(double(width)/double(tile_size)));
|
|
|
|
int max_y = int(ceil(double(height)/double(tile_size)));
|
|
|
|
|
|
|
|
double pixel_x = extent.width()/double(width);
|
|
|
|
double pixel_y = extent.height()/double(height);
|
|
|
|
std::cout << "PIXEL SIZE("<< pixel_x << "," << pixel_y << ")\n";
|
|
|
|
|
|
|
|
Envelope<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(Envelope<double>(x0,y0,x1,y1)))
|
|
|
|
{
|
|
|
|
Envelope<double> tile_box = e.intersect(Envelope<double>(x0,y0,x1,y1));
|
|
|
|
raster_info info(file,format,tile_box,tile_size,tile_size);
|
|
|
|
infos_.push_back(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cout << "INFO SIZE=" << infos_.size() << " " << file << "\n";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const_iterator begin()
|
|
|
|
{
|
|
|
|
return infos_.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
const_iterator end()
|
|
|
|
{
|
|
|
|
return infos_.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
std::vector<raster_info> infos_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
template <typename LookupPolicy>
|
2007-03-16 11:11:37 +01:00
|
|
|
class raster_featureset : public mapnik::Featureset
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
2009-04-10 14:05:31 +02:00
|
|
|
typedef typename LookupPolicy::const_iterator iterator_type;
|
|
|
|
LookupPolicy policy_;
|
|
|
|
size_t id_;
|
|
|
|
mapnik::Envelope<double> extent_;
|
|
|
|
mapnik::Envelope<double> bbox_;
|
|
|
|
iterator_type curIter_;
|
|
|
|
iterator_type endIter_;
|
2005-06-14 17:06:59 +02:00
|
|
|
public:
|
2009-04-10 14:05:31 +02:00
|
|
|
raster_featureset(LookupPolicy const& policy,Envelope<double> const& exttent, mapnik::query const& q);
|
|
|
|
virtual ~raster_featureset();
|
|
|
|
mapnik::feature_ptr next();
|
2005-06-14 17:06:59 +02:00
|
|
|
};
|
|
|
|
|
2009-04-10 14:05:31 +02:00
|
|
|
#endif //RASTER_FEATURESET_HPP
|