mapnik/plugins/input/raster/raster_featureset.cpp

87 lines
2.9 KiB
C++
Raw Normal View History

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.
*
* 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
2005-06-14 17:06:59 +02:00
*
2006-03-31 12:32:02 +02:00
*****************************************************************************/
// mapnik
#include <mapnik/image_reader.hpp>
#include <mapnik/image_util.hpp>
2005-09-21 22:27:37 +02:00
#include "raster_featureset.hpp"
2005-06-14 17:06:59 +02:00
using mapnik::query;
using mapnik::CoordTransform;
using mapnik::ImageReader;
using mapnik::Feature;
using mapnik::feature_ptr;
using mapnik::ImageData32;
using mapnik::raster;
2005-06-14 17:06:59 +02:00
template <typename LookupPolicy>
raster_featureset<LookupPolicy>::raster_featureset(LookupPolicy const& policy,
query const& q)
: policy_(policy),
id_(1),
extent_(q.get_bbox()),
curIter_(policy_.query(extent_)),
endIter_(policy_.end())
2005-06-14 17:06:59 +02:00
{}
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_)
{
2007-04-30 22:08:49 +02:00
feature_ptr feature(new Feature(++id_));
try
{
2008-01-07 11:20:05 +01:00
std::auto_ptr<ImageReader> reader(mapnik::get_image_reader(curIter_->file(),curIter_->format()));
std::cout << "READER = " << curIter_->format() << " " << curIter_->file() << "\n";
if (reader.get())
{
int image_width=reader->width();
int image_height=reader->height();
2008-01-07 11:20:05 +01:00
if (image_width>0 && image_height>0)
2005-06-14 17:06:59 +02:00
{
CoordTransform t(image_width,image_height,curIter_->envelope(),0,0);
Envelope<double> intersect=extent_.intersect(curIter_->envelope());
Envelope<double> ext=t.forward(intersect);
2005-06-14 17:06:59 +02:00
ImageData32 image((int)ext.width(),(int)ext.height());
reader->read((int)ext.minx(),(int)ext.miny(),image);
feature->set_raster(mapnik::raster_ptr(new raster(intersect,image)));
2005-06-14 17:06:59 +02:00
}
}
}
catch (...)
{
}
++curIter_;
return feature;
}
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>;