source: subversion/applications/utils/export/cgimap/src/temp_tables.cpp @ 17459

Last change on this file since 17459 was 14977, checked in by zere, 11 years ago

Ported cgimap to API 0.6 and postgres backend. Bumped version to 0.0.2.

File size: 1.7 KB
Line 
1#include <stdexcept>
2#include <sstream>
3#include <iostream>
4#include "temp_tables.hpp"
5#include "quad_tile.hpp"
6
7using std::set;
8using std::runtime_error;
9using std::stringstream;
10using std::cerr;
11using std::endl;
12
13tmp_nodes::tmp_nodes(pqxx::work &w,
14                     const bbox &bounds)
15  : work(w) {
16  const set<unsigned int> tiles = 
17    tiles_for_area(bounds.minlat, bounds.minlon, 
18                   bounds.maxlat, bounds.maxlon);
19 
20  stringstream query;
21  query << "create temporary table tmp_nodes as "
22        << "select id from current_nodes where ((";
23  unsigned int first_id = 0, last_id = 0;
24  for (set<unsigned int>::const_iterator itr = tiles.begin();
25       itr != tiles.end(); ++itr) {
26    if (first_id == 0) {
27      last_id = first_id = *itr;
28    } else if (*itr == last_id + 1) {
29      ++last_id;
30    } else {
31      if (last_id == first_id) {
32        query << "tile = " << last_id << " or ";
33      } else {
34        query << "tile between " << first_id
35              << " and " << last_id << " or ";
36      }
37      last_id = first_id = *itr;
38    }
39  }
40  if (last_id == first_id) {
41    query << "tile = " << last_id << ") ";
42  } else {
43    query << "tile between " << first_id
44          << " and " << last_id << ") ";
45  }
46  query << "and latitude between " << int(bounds.minlat * SCALE) 
47        << " and " << int(bounds.maxlat * SCALE)
48        << " and longitude between " << int(bounds.minlon * SCALE) 
49        << " and " << int(bounds.maxlon * SCALE)
50        << ") and (visible = true)";
51 
52  // assume this throws if it fails?
53  work.exec(query);
54}
55
56tmp_ways::tmp_ways(pqxx::work &w) 
57  : work(w) {
58  work.exec("create temporary table tmp_ways as "
59            "select distinct wn.id from current_way_nodes wn "
60            "join tmp_nodes tn on wn.node_id = tn.id");
61  work.exec("create index tmp_ways_idx on tmp_ways(id)");
62}
63
Note: See TracBrowser for help on using the repository browser.