1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2006 Artem Pavlenko
*
* 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,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* 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
*
*****************************************************************************/
// mapnik
#include <mapnik/image_reader.hpp>
#include <mapnik/image_util.hpp>
#include "raster_featureset.hpp"
using mapnik::query;
using mapnik::CoordTransform;
using mapnik::ImageReader;
using mapnik::Feature;
using mapnik::feature_ptr;
using mapnik::ImageData32;
using mapnik::raster;
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())
{}
template <typename LookupPolicy>
raster_featureset<LookupPolicy>::~raster_featureset() {}
template <typename LookupPolicy>
feature_ptr raster_featureset<LookupPolicy>::next()
{
if (curIter_!=endIter_)
{
feature_ptr feature(new Feature(++id_));
try
{
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();
if (image_width>0 && image_height>0)
{
CoordTransform t(image_width,image_height,curIter_->envelope(),0,0);
Envelope<double> intersect=extent_.intersect(curIter_->envelope());
Envelope<double> ext=t.forward(intersect);
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)));
}
}
}
catch (...)
{
}
++curIter_;
return feature;
}
return feature_ptr();
}
template class raster_featureset<single_file_policy>;
|