2005-06-14 17:06:59 +02:00
|
|
|
/* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
* Copyright (C) 2005 Artem Pavlenko
|
|
|
|
*
|
|
|
|
* Mapnik is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2005-09-21 22:27:37 +02:00
|
|
|
#include "raster_featureset.hpp"
|
|
|
|
#include "image_reader.hpp"
|
|
|
|
#include "image_util.hpp"
|
2005-06-14 17:06:59 +02:00
|
|
|
|
|
|
|
template <typename LookupPolicy>
|
2005-09-21 22:27:37 +02:00
|
|
|
raster_featureset<LookupPolicy>::raster_featureset(LookupPolicy const& policy,query const& q)
|
2005-06-14 17:06:59 +02:00
|
|
|
: policy_(policy),
|
|
|
|
id_(1),
|
2005-09-21 22:27:37 +02:00
|
|
|
extent_(q.get_bbox()),
|
|
|
|
t_(q.get_width(),q.get_height(),extent_),
|
|
|
|
curIter_(policy_.query(extent_)),
|
2005-06-14 17:06:59 +02:00
|
|
|
endIter_(policy_.end())
|
|
|
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
template <typename LookupPolicy>
|
2005-09-21 22:27:37 +02:00
|
|
|
raster_featureset<LookupPolicy>::~raster_featureset() {}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
|
|
|
template <typename LookupPolicy>
|
2005-09-21 22:27:37 +02:00
|
|
|
feature_ptr raster_featureset<LookupPolicy>::next()
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
|
|
|
if (curIter_!=endIter_)
|
|
|
|
{
|
2005-09-21 22:27:37 +02:00
|
|
|
feature_ptr feature(new Feature(+id_));
|
2005-06-14 17:06:59 +02:00
|
|
|
try
|
|
|
|
{
|
2006-03-19 22:53:47 +01:00
|
|
|
std::clog<<"raster_featureset "<<curIter_->format()<<" "<<curIter_->file()<<std::endl;
|
2005-06-14 17:06:59 +02:00
|
|
|
std::auto_ptr<ImageReader> reader(get_image_reader(curIter_->format(),curIter_->file()));
|
2006-03-19 22:53:47 +01:00
|
|
|
std::clog<<reader.get()<<std::endl;
|
2005-06-14 17:06:59 +02:00
|
|
|
if (reader.get())
|
|
|
|
{
|
|
|
|
int image_width=reader->width();
|
|
|
|
int image_height=reader->height();
|
|
|
|
if (image_width>0 && image_height>0)
|
|
|
|
{
|
|
|
|
CoordTransform t(image_width,image_height,curIter_->envelope());
|
|
|
|
Envelope<double> intersect=extent_.intersect(curIter_->envelope());
|
|
|
|
Envelope<double> ext=t.forward(intersect);
|
|
|
|
|
|
|
|
Envelope<double> image_ext=t_.forward(intersect);
|
|
|
|
|
|
|
|
ImageData32 image((int)ext.width(),(int)ext.height());
|
|
|
|
reader->read((int)ext.minx(),(int)ext.miny(),image);
|
2005-09-21 22:27:37 +02:00
|
|
|
|
|
|
|
ImageData32 target((int)(image_ext.width()+0.5),(int)(image_ext.height()+0.5));
|
2005-06-14 17:06:59 +02:00
|
|
|
scale_image<ImageData32>(target,image);
|
2005-09-21 22:27:37 +02:00
|
|
|
feature->set_raster(raster_ptr(new raster(int(image_ext.minx()+0.5),int(image_ext.miny()+0.5),target)));
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
++curIter_;
|
2005-09-21 22:27:37 +02:00
|
|
|
return feature;
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
2005-12-12 14:15:33 +01:00
|
|
|
return feature_ptr();
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-21 22:27:37 +02:00
|
|
|
template class raster_featureset<single_file_policy>;
|
|
|
|
//template raster_featureset<os_name_policy>;
|