1
/*****************************************************************************
3
* This file is part of Mapnik (c++ mapping toolkit)
5
* Copyright (C) 2007 Artem Pavlenko
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
*****************************************************************************/
25
#include <mapnik/global.hpp>
26
#include <mapnik/datasource.hpp>
27
#include <mapnik/envelope.hpp>
28
#include <mapnik/geometry.hpp>
29
#include <mapnik/feature.hpp>
30
#include <mapnik/feature_layer_desc.hpp>
31
#include <mapnik/wkb.hpp>
32
#include <mapnik/unicode.hpp>
35
#include <boost/iostreams/stream.hpp>
36
#include <boost/iostreams/device/file.hpp>
37
#include <boost/iostreams/device/mapped_file.hpp>
40
#include "ogr_index_featureset.hpp"
41
#include "ogr_converter.hpp"
42
#include "ogr_index.hpp"
43
#include "ogr_feature_ptr.hpp"
49
using mapnik::Envelope;
50
using mapnik::CoordTransform;
51
using mapnik::Feature;
52
using mapnik::feature_ptr;
53
using mapnik::geometry_utils;
54
using mapnik::transcoder;
56
using namespace boost::iostreams;
59
template <typename filterT>
60
ogr_index_featureset<filterT>::ogr_index_featureset(OGRDataSource & dataset,
62
const filterT& filter,
63
const std::string& index_file,
64
const std::string& encoding,
65
const bool multiple_geometries)
68
layerdef_(layer.GetLayerDefn()),
70
tr_(new transcoder(encoding)),
71
fidcolumn_(layer_.GetFIDColumn ()),
72
multiple_geometries_(multiple_geometries),
75
stream<mapped_file_source> file (index_file);
78
ogr_index<filterT,stream<mapped_file_source> >::query(filter,file,ids_);
81
std::sort(ids_.begin(),ids_.end());
84
std::clog<< "query size=" << ids_.size() << "\n";
90
layer_.ResetReading();
93
template <typename filterT>
94
ogr_index_featureset<filterT>::~ogr_index_featureset() {}
96
template <typename filterT>
97
feature_ptr ogr_index_featureset<filterT>::next()
99
if (itr_ != ids_.end())
102
layer_.SetNextByIndex (pos);
104
ogr_feature_ptr feat (layer_.GetNextFeature());
107
OGRGeometry* geom=(*feat)->GetGeometryRef();
108
if (!geom->IsEmpty())
110
feature_ptr feature(new Feature((*feat)->GetFID()));
112
ogr_converter::convert_geometry (geom, feature, multiple_geometries_);
115
int fld_count = layerdef_->GetFieldCount();
116
for (int i = 0; i < fld_count; i++)
118
OGRFieldDefn* fld = layerdef_->GetFieldDefn (i);
119
OGRFieldType type_oid = fld->GetType ();
120
std::string fld_name = fld->GetNameRef ();
126
boost::put(*feature,fld_name,(*feat)->GetFieldAsInteger (i));
132
boost::put(*feature,fld_name,(*feat)->GetFieldAsDouble (i));
137
case OFTWideString: // deprecated !
139
UnicodeString ustr = tr_->transcode((*feat)->GetFieldAsString (i));
140
boost::put(*feature,fld_name,ustr);
147
case OFTWideStringList: // deprecated !
150
clog << "unhandled type_oid=" << type_oid << endl;
158
clog << "unhandled type_oid=" << type_oid << endl;
160
//boost::put(*feature,name,feat->GetFieldAsBinary (i, size));
166
case OFTDateTime: // unhandled !
169
clog << "unhandled type_oid=" << type_oid << endl;
177
clog << "unknown type_oid=" << type_oid << endl;
190
clog << count_ << " features" << endl;
192
return feature_ptr();
195
template class ogr_index_featureset<mapnik::filter_in_box>;
196
template class ogr_index_featureset<mapnik::filter_at_point>;