~ubuntu-branches/ubuntu/trusty/mapnik/trusty-proposed

« back to all changes in this revision

Viewing changes to plugins/input/ogr/ogr_index.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Sauthier
  • Date: 2009-08-27 00:28:37 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090827002837-ztqzfg2rmclfh4i9
Tags: 0.6.1-0ubuntu1
* New upstream release.
* Change usr/lib to usr/lib* to enable build on 64 bits systems due to new
  configuration in SConstruct in :
  - debian/libmapnik-dev.install
  - debian/libmapnik0.6.install
  - debian/mapnik-plugin-base

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 * 
 
3
 * This file is part of Mapnik (c++ mapping toolkit)
 
4
 *
 
5
 * Copyright (C) 2006 Artem Pavlenko
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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
 
20
 *
 
21
 *****************************************************************************/
 
22
 
 
23
#ifndef OGR_INDEX_HH
 
24
#define OGR_INDEX_HH
 
25
 
 
26
// st
 
27
#include <fstream>
 
28
#include <vector>
 
29
// mapnik
 
30
#include <mapnik/envelope.hpp>
 
31
#include <mapnik/query.hpp>
 
32
 
 
33
using mapnik::Envelope;
 
34
using mapnik::query;
 
35
 
 
36
template <typename filterT, typename IStream = std::ifstream>
 
37
class ogr_index
 
38
{
 
39
public:
 
40
    static void query(const filterT& filter, IStream& file,std::vector<int>& pos);
 
41
private:
 
42
    ogr_index();
 
43
    ~ogr_index();
 
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);
 
49
};
 
50
 
 
51
template <typename filterT,typename IStream>
 
52
void ogr_index<filterT, IStream>::query(const filterT& filter,IStream & file,std::vector<int>& pos)
 
53
{
 
54
    file.seekg(16,std::ios::beg);
 
55
    query_node(filter,file,pos);
 
56
}
 
57
 
 
58
template <typename filterT, typename IStream>
 
59
void ogr_index<filterT,IStream>::query_node(const filterT& filter,IStream &  file,std::vector<int>& ids)
 
60
{
 
61
    int offset=read_ndr_integer(file);
 
62
 
 
63
    Envelope<double> node_ext;
 
64
    read_envelope(file,node_ext);
 
65
 
 
66
    int num_shapes=read_ndr_integer(file);
 
67
 
 
68
    if (!filter.pass(node_ext))
 
69
    {
 
70
        file.seekg(offset+num_shapes*4+4,std::ios::cur);
 
71
        return;
 
72
    }
 
73
    
 
74
    for (int i=0;i<num_shapes;++i)
 
75
    {
 
76
        int id=read_ndr_integer(file);
 
77
        ids.push_back(id);
 
78
    }
 
79
 
 
80
    int children=read_ndr_integer(file);
 
81
 
 
82
    for (int j=0;j<children;++j)
 
83
    {
 
84
        query_node(filter,file,ids);
 
85
    }
 
86
}
 
87
 
 
88
 
 
89
template <typename filterT,typename IStream>
 
90
int ogr_index<filterT,IStream>::read_ndr_integer(IStream & file)
 
91
{
 
92
    char b[4];
 
93
    file.read(b,4);
 
94
    return (b[0]&0xff) | (b[1]&0xff)<<8 | (b[2]&0xff)<<16 | (b[3]&0xff)<<24;
 
95
}
 
96
 
 
97
 
 
98
template <typename filterT,typename IStream>
 
99
void ogr_index<filterT,IStream>::read_envelope(IStream & file,Envelope<double>& envelope)
 
100
{
 
101
    file.read(reinterpret_cast<char*>(&envelope),sizeof(envelope));
 
102
}
 
103
 
 
104
 
 
105
#endif //SHP_INDEX_HH