1
/*****************************************************************************
3
* This file is part of Mapnik (c++ mapping toolkit)
5
* Copyright (C) 2006 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
*****************************************************************************/
30
#include <mapnik/envelope.hpp>
31
#include <mapnik/query.hpp>
33
using mapnik::Envelope;
36
template <typename filterT, typename IStream = std::ifstream>
40
static void query(const filterT& filter, IStream& file,std::vector<int>& pos);
44
ogr_index(const ogr_index&);
45
ogr_index& operator=(const ogr_index&);
46
static int read_ndr_integer(IStream & in);
47
static void read_envelope(IStream & in,Envelope<double> &envelope);
48
static void query_node(const filterT& filter,IStream & in,std::vector<int>& pos);
51
template <typename filterT,typename IStream>
52
void ogr_index<filterT, IStream>::query(const filterT& filter,IStream & file,std::vector<int>& pos)
54
file.seekg(16,std::ios::beg);
55
query_node(filter,file,pos);
58
template <typename filterT, typename IStream>
59
void ogr_index<filterT,IStream>::query_node(const filterT& filter,IStream & file,std::vector<int>& ids)
61
int offset=read_ndr_integer(file);
63
Envelope<double> node_ext;
64
read_envelope(file,node_ext);
66
int num_shapes=read_ndr_integer(file);
68
if (!filter.pass(node_ext))
70
file.seekg(offset+num_shapes*4+4,std::ios::cur);
74
for (int i=0;i<num_shapes;++i)
76
int id=read_ndr_integer(file);
80
int children=read_ndr_integer(file);
82
for (int j=0;j<children;++j)
84
query_node(filter,file,ids);
89
template <typename filterT,typename IStream>
90
int ogr_index<filterT,IStream>::read_ndr_integer(IStream & file)
94
return (b[0]&0xff) | (b[1]&0xff)<<8 | (b[2]&0xff)<<16 | (b[3]&0xff)<<24;
98
template <typename filterT,typename IStream>
99
void ogr_index<filterT,IStream>::read_envelope(IStream & file,Envelope<double>& envelope)
101
file.read(reinterpret_cast<char*>(&envelope),sizeof(envelope));
105
#endif //SHP_INDEX_HH