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

« back to all changes in this revision

Viewing changes to utils/shapeindex/shapeindex.cpp

  • 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:
26
26
#include <vector>
27
27
#include <string>
28
28
 
29
 
 
30
29
#include <boost/tokenizer.hpp>
31
30
#include <boost/algorithm/string.hpp>
 
31
#include <boost/filesystem/operations.hpp>
32
32
#include <boost/program_options.hpp>
33
33
#include "quadtree.hpp"
34
34
#include "shapefile.hpp"
47
47
    using std::string;
48
48
    using std::vector;
49
49
    using std::clog;
 
50
    using std::endl;
50
51
    
51
52
    bool verbose=false;
52
53
    unsigned int depth=DEFAULT_DEPTH;
79
80
 
80
81
        if (vm.count("help")) 
81
82
        {
82
 
            clog << desc << "\n";
 
83
            clog << desc << endl;
83
84
            return 1;
84
85
        }
85
86
        if (vm.count("depth"))
98
99
    }
99
100
    catch (...)
100
101
    {
101
 
        clog << "Exception of unknown type!"<<std::endl;
 
102
        clog << "Exception of unknown type!" << endl;
102
103
        return -1;
103
104
    }
104
105
    
105
 
    std::clog<<"max tree depth:"<<depth<<std::endl;
106
 
    std::clog<<"split ratio:"<<ratio<<std::endl;
 
106
    clog << "max tree depth:" << depth << endl;
 
107
    clog << "split ratio:" << ratio << endl;
107
108
  
108
 
    vector<string>::const_iterator itr=shape_files.begin();
109
 
    if (itr==shape_files.end())
 
109
    vector<string>::const_iterator itr = shape_files.begin();
 
110
    if (itr == shape_files.end())
110
111
    {
111
 
        std::clog << "no shape files to index"<<std::endl;
 
112
        clog << "no shape files to index" << endl;
112
113
        return 0;
113
114
    }
114
115
    while (itr != shape_files.end())
115
116
    {
116
 
        std::clog<<"processing "<<*itr << std::endl;
 
117
        clog << "processing " << *itr << endl;
117
118
        //shape_file shp;
118
 
        std::string shapename(*itr++);
119
 
        shape_file shp(shapename+".shp");
120
 
 
121
 
        if (!shp.is_open()) {
122
 
            std::clog<<"error : cannot open "<< (shapename+".shp") <<"\n";
 
119
        std::string shapename (*itr++);
 
120
        std::string shapename_full (shapename+".shp");
 
121
 
 
122
        if (! boost::filesystem::exists (shapename_full))
 
123
        {
 
124
            clog << "error : file " << shapename_full << " doesn't exists" << endl;
 
125
            continue;
 
126
        }
 
127
 
 
128
        shape_file shp (shapename_full);
 
129
 
 
130
        if (! shp.is_open()) {
 
131
            clog << "error : cannot open " << shapename_full << endl;
123
132
            continue;
124
133
        }
125
134
        
126
135
        int code = shp.read_xdr_integer(); //file_code == 9994
127
 
        std::clog << code << "\n";
 
136
        clog << code << endl;
128
137
        shp.skip(5*4); 
129
138
        
130
139
        int file_length=shp.read_xdr_integer();
134
143
        shp.read_envelope(extent);
135
144
        
136
145
        
137
 
        std::clog<<"length="<<file_length<<std::endl;
138
 
        std::clog<<"version="<<version<<std::endl;
139
 
        std::clog<<"type="<<shape_type<<std::endl;
140
 
        std::clog<<"extent:"<<extent<<std::endl;
 
146
        clog << "length=" << file_length << endl;
 
147
        clog << "version=" << version << endl;
 
148
        clog << "type=" << shape_type << endl;
 
149
        clog << "extent:" << extent << endl;
141
150
          
142
151
        int pos=50;
143
152
        shp.seek(pos*2);  
188
197
            
189
198
            tree.insert(offset,item_ext);
190
199
            if (verbose) {
191
 
                std::clog<<"record number "<<record_number<<" box="<<item_ext<<std::endl;
 
200
                clog << "record number " << record_number << " box=" << item_ext << endl;
192
201
            }
193
202
 
194
203
            pos+=4+content_length;
200
209
        } 
201
210
        shp.close();
202
211
  
203
 
        std::clog<<" number shapes="<<count<<std::endl;  
 
212
        clog << " number shapes=" << count << endl;  
204
213
    
205
214
        std::fstream file((shapename+".index").c_str(),
206
215
                          std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary);
207
216
        if (!file) {
208
 
            std::clog << "cannot open index file for writing file \""
209
 
                      <<(shapename+".index")<<"\""<<std::endl;
 
217
            clog << "cannot open index file for writing file \"" 
 
218
                 << (shapename+".index") << "\"" << endl;
210
219
        } else {
211
220
            tree.trim();
212
221
            std::clog<<" number nodes="<<tree.count()<<std::endl;
216
225
            file.close();
217
226
        }
218
227
    }
219
 
    std::clog<<"done!"<<std::endl;
 
228
    
 
229
    clog << "done!" << endl;
220
230
    return 0;
221
231
}
 
232