|
|
1 | /** |
|
|
2 | * ZANavi, Zoff Android Navigation system. |
|
|
3 | * Copyright (C) 2011-2012 Zoff <zoff@zoff.cc> |
|
|
4 | * |
|
|
5 | * This program is free software; you can redistribute it and/or |
|
|
6 | * modify it under the terms of the GNU General Public License |
|
|
7 | * version 2 as published by the Free Software Foundation. |
|
|
8 | * |
|
|
9 | * This program is distributed in the hope that it will be useful, |
|
|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
12 | * GNU General Public License for more details. |
|
|
13 | * |
|
|
14 | * You should have received a copy of the GNU General Public License |
|
|
15 | * along with this program; if not, write to the |
|
|
16 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
|
17 | * Boston, MA 02110-1301, USA. |
|
|
18 | */ |
|
|
19 | |
1 | /** |
20 | /** |
2 | * Navit, a modular navigation system. |
21 | * Navit, a modular navigation system. |
3 | * Copyright (C) 2005-2011 Navit Team |
22 | * Copyright (C) 2005-2011 Navit Team |
4 | * |
23 | * |
5 | * This program is free software; you can redistribute it and/or |
24 | * This program is free software; you can redistribute it and/or |
… | |
… | |
15 | * along with this program; if not, write to the |
34 | * along with this program; if not, write to the |
16 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
35 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | * Boston, MA 02110-1301, USA. |
36 | * Boston, MA 02110-1301, USA. |
18 | */ |
37 | */ |
19 | |
38 | |
20 | |
|
|
21 | #define _FILE_OFFSET_BITS 64 |
39 | #define _FILE_OFFSET_BITS 64 |
22 | #define _LARGEFILE_SOURCE |
40 | #define _LARGEFILE_SOURCE |
23 | #define _LARGEFILE64_SOURCE |
41 | #define _LARGEFILE64_SOURCE |
24 | #include <stdlib.h> |
42 | #include <stdlib.h> |
|
|
43 | #include <time.h> |
|
|
44 | #include <sys/resource.h> |
25 | #include <glib.h> |
45 | #include <glib.h> |
26 | #include <assert.h> |
46 | #include <assert.h> |
27 | #include <string.h> |
47 | #include <string.h> |
28 | #include <signal.h> |
48 | #include <signal.h> |
29 | #include <stdio.h> |
49 | #include <stdio.h> |
… | |
… | |
31 | #include <getopt.h> |
51 | #include <getopt.h> |
32 | #include <unistd.h> |
52 | #include <unistd.h> |
33 | #include <fcntl.h> |
53 | #include <fcntl.h> |
34 | #include <sys/stat.h> |
54 | #include <sys/stat.h> |
35 | #include <zlib.h> |
55 | #include <zlib.h> |
|
|
56 | |
|
|
57 | // pthreads |
|
|
58 | #include <pthread.h> |
|
|
59 | // pthreads |
|
|
60 | |
|
|
61 | #include "version_maptool.h" |
|
|
62 | |
36 | #include "file.h" |
63 | #include "file.h" |
37 | #include "item.h" |
64 | #include "item.h" |
38 | #include "map.h" |
65 | #include "map.h" |
39 | #include "zipfile.h" |
66 | #include "zipfile.h" |
40 | #include "main.h" |
67 | #include "main.h" |
… | |
… | |
42 | #include "linguistics.h" |
69 | #include "linguistics.h" |
43 | #include "plugin.h" |
70 | #include "plugin.h" |
44 | #include "util.h" |
71 | #include "util.h" |
45 | #include "maptool.h" |
72 | #include "maptool.h" |
46 | |
73 | |
47 | long long slice_size=1024*1024*1024; |
74 | void *sql_thread(void *ptr); |
|
|
75 | |
|
|
76 | time_t start_tt, end_tt; |
|
|
77 | double diff_tt; |
|
|
78 | double diff2_tt; |
|
|
79 | |
|
|
80 | time_t global_start_tt, global_end_tt; |
|
|
81 | double global_diff_tt; |
|
|
82 | |
|
|
83 | long long slice_size = 50 * 1024 * 1024; // default to 50 MByte |
48 | int attr_debug_level=1; |
84 | int attr_debug_level = 1; |
49 | int ignore_unkown = 0; |
85 | int ignore_unkown = 0; |
|
|
86 | int border_only_map = 0; |
|
|
87 | int border_only_map_as_xml = 0; |
|
|
88 | int coastline_only_map = 0; |
50 | GHashTable *dedupe_ways_hash; |
89 | // GHashTable *dedupe_ways_hash; |
51 | int phase; |
90 | int phase; |
52 | int slices; |
91 | int slices; |
53 | struct buffer node_buffer = { |
92 | int unknown_country; |
54 | 64*1024*1024, |
93 | int doway2poi = 0; |
55 | }; |
94 | char ch_suffix[] = "r"; /* Used to make compiler happy due to Bug 35903 in gcc */ |
|
|
95 | int experimental = 0; |
|
|
96 | int use_global_fixed_country_id = 0; |
|
|
97 | int verbose_mode = 0; |
|
|
98 | int global_fixed_country_id = 999; |
|
|
99 | long long dummy_town_id = -2; |
56 | |
100 | |
|
|
101 | int cur_thread_num = 0; |
|
|
102 | int threads = 1; |
|
|
103 | int max_threads = MAX_THREADS; |
|
|
104 | int thread_is_working_[MAX_THREADS]; |
|
|
105 | const char* sqlite_db_dir_extra = "./db/"; |
|
|
106 | char *sqlite_db_dir = "./"; |
|
|
107 | int sqlite_temp_dir = 0; |
|
|
108 | |
|
|
109 | char ib_buffer_array[MAX_THREADS][800000]; |
|
|
110 | |
|
|
111 | // char ib_buffer_2[800000]; // --> this would be a independent buffer |
|
|
112 | // char *ib_buffer_2; // = ib_buffer_array[0]; |
|
|
113 | |
|
|
114 | struct buffer node_buffer[MAX_THREADS]; // buffer for nodes // ARRAY (max max_threads) |
|
|
115 | struct buffer waytag_buffer = { 64 * 1024 * 1024, }; // buffer for relations // extend in 64MBytes steps |
|
|
116 | |
|
|
117 | GHashTable *node_hash[MAX_THREADS]; // ARRAY (max max_threads) |
|
|
118 | cfuhash_table_t *node_hash_cfu[MAX_THREADS]; |
|
|
119 | |
|
|
120 | struct item_bin *item_bin_2 = (struct item_bin *) &ib_buffer_array[0]; |
|
|
121 | |
|
|
122 | pthread_t sqlite_thread001; |
|
|
123 | |
|
|
124 | #ifdef MAPTOOL_USE_SQL |
|
|
125 | sqlite3 *sql_handle; |
|
|
126 | sqlite3 *sql_handle002a; |
|
|
127 | sqlite3 *sql_handle003a; |
|
|
128 | sqlite3 *sql_handle002b; |
|
|
129 | sqlite3 *sql_handle003b; |
|
|
130 | sqlite3 *sql_handle004; |
|
|
131 | sqlite3 *sql_handle005; |
|
|
132 | sqlite3 *sql_handle006; |
|
|
133 | sqlite3 *sql_handle007; |
|
|
134 | #else |
|
|
135 | void *sql_handle; |
|
|
136 | void *sql_handle002a; |
|
|
137 | void *sql_handle003a; |
|
|
138 | void *sql_handle002b; |
|
|
139 | void *sql_handle003b; |
|
|
140 | void *sql_handle004; |
|
|
141 | void *sql_handle005; |
|
|
142 | void *sql_handle006; |
|
|
143 | void *sql_handle007; |
|
|
144 | #endif |
|
|
145 | |
57 | int processed_nodes, processed_nodes_out, processed_ways, processed_relations, processed_tiles; |
146 | int processed_nodes, processed_nodes_out, processed_ways, processed_relations, processed_tiles = 0; |
58 | |
147 | |
59 | int overlap=1; |
148 | int overlap = 1; |
60 | |
149 | |
61 | int bytes_read; |
150 | int bytes_read; |
62 | |
151 | |
63 | |
|
|
64 | |
|
|
65 | void |
|
|
66 | sig_alrm(int sig) |
152 | void sig_alrm(int sig) |
67 | { |
153 | { |
68 | #ifndef _WIN32 |
154 | #ifndef _WIN32 |
69 | signal(SIGALRM, sig_alrm); |
155 | signal(SIGALRM, sig_alrm); |
70 | alarm(30); |
156 | alarm(60); |
71 | #endif |
157 | #endif |
|
|
158 | //if (verbose_mode) |
72 | fprintf(stderr,"PROGRESS%d: Processed %d nodes (%d out) %d ways %d relations %d tiles\n", phase, processed_nodes, processed_nodes_out, processed_ways, processed_relations, processed_tiles); |
159 | // fprintf(stderr, "PROGRESS%d: Processed %d nodes (%d out) %d ways %d relations %d tiles\n", phase, processed_nodes, processed_nodes_out, processed_ways, processed_relations, processed_tiles); |
|
|
160 | |
|
|
161 | print_mem(); |
73 | } |
162 | } |
74 | |
163 | |
75 | void |
|
|
76 | sig_alrm_end(void) |
164 | void sig_alrm_end(void) |
77 | { |
165 | { |
78 | #ifndef _WIN32 |
166 | #ifndef _WIN32 |
79 | alarm(0); |
167 | alarm(0); |
80 | #endif |
168 | #endif |
81 | } |
169 | } |
82 | |
170 | |
|
|
171 | print_mem() |
|
|
172 | { |
|
|
173 | struct rusage usage; |
|
|
174 | int ret; |
|
|
175 | char outstring2[200]; |
|
|
176 | long i1, i2, i3; |
|
|
177 | FILE *f1; |
|
|
178 | char c[10]; |
|
|
179 | |
|
|
180 | long all_bytes = (long) sysconf(_SC_PHYS_PAGES) * (long) sysconf(_SC_PAGE_SIZE); |
|
|
181 | fprintf(stderr, "#+MEM+#all:%ld\n", all_bytes); |
|
|
182 | convert_to_human_bytes2((long long) all_bytes, outstring2); |
|
|
183 | fprintf(stderr, "#+MEM+#H#all: %s\n", outstring2); |
|
|
184 | |
|
|
185 | long free_bytes = (long) sysconf(_SC_AVPHYS_PAGES) * (long) sysconf(_SC_PAGE_SIZE); |
|
|
186 | fprintf(stderr, "#+MEM+#free:%ld\n", free_bytes); |
|
|
187 | convert_to_human_bytes2((long long) free_bytes, outstring2); |
|
|
188 | fprintf(stderr, "#+MEM+#H#free: %s\n", outstring2); |
|
|
189 | |
|
|
190 | #if 0 |
|
|
191 | ret = getrusage(RUSAGE_SELF, &usage); |
|
|
192 | if (ret == 0) |
|
|
193 | { |
|
|
194 | // long ru_maxrss; /* maximum resident set size */ |
|
|
195 | // long ru_ixrss; /* integral shared memory size */ |
|
|
196 | // long ru_idrss; /* integral unshared data size */ |
|
|
197 | // long ru_isrss; /* integral unshared stack size */ |
|
|
198 | fprintf(stderr, "#+MEM+#used1:%ld\n", usage.ru_maxrss * (long) 1024); |
|
|
199 | fprintf(stderr, "#+MEM+#used2:%ld\n", usage.ru_ixrss * (long) 1024); |
|
|
200 | fprintf(stderr, "#+MEM+#used3:%ld\n", usage.ru_idrss * (long) 1024); |
|
|
201 | fprintf(stderr, "#+MEM+#used4:%ld\n", usage.ru_isrss * (long) 1024); |
|
|
202 | convert_to_human_bytes2((long long) (usage.ru_maxrss * (long) 1024), outstring2); |
|
|
203 | fprintf(stderr, "#+MEM+#H#used1: %s\n", outstring2); |
|
|
204 | } |
|
|
205 | #endif |
|
|
206 | |
|
|
207 | int ps = getpagesize(); |
|
|
208 | //fprintf(stderr, "ps=%d\n", ps); |
|
|
209 | |
|
|
210 | f1 = fopen("/proc/self/statm", "r"); |
|
|
211 | fscanf(f1, "%ld\t%ld\t%ld\t", &i1, &i2, &i3); |
|
|
212 | fclose(f1); |
|
|
213 | |
|
|
214 | fprintf(stderr, "#+MEM+#VIRT:%ld\n", (long) (i1 * ps)); |
|
|
215 | fprintf(stderr, "#+MEM+#RES :%ld\n", (long) (i2 * ps)); |
|
|
216 | |
|
|
217 | convert_to_human_bytes2((long long) (i1 * ps), outstring2); |
|
|
218 | fprintf(stderr, "#+MEM+#H#VIRT: %s\n", outstring2); |
|
|
219 | convert_to_human_bytes2((long long) (i2 * ps), outstring2); |
|
|
220 | fprintf(stderr, "#+MEM+#H#RES : %s\n", outstring2); |
|
|
221 | } |
|
|
222 | |
83 | static struct plugins *plugins; |
223 | static struct plugins *plugins; |
84 | |
224 | |
85 | static void add_plugin(char *path) |
225 | static void add_plugin(char *path) |
86 | { |
226 | { |
87 | struct attr **attrs; |
227 | struct attr **attrs; |
88 | |
228 | |
89 | if (! plugins) |
229 | if (!plugins) |
|
|
230 | { |
|
|
231 | // file_init(); // must define some CACHE thingy first!! |
90 | plugins=plugins_new(); |
232 | plugins = plugins_new(); |
91 | attrs=(struct attr*[]){&(struct attr){attr_path,{path}},NULL}; |
233 | } |
92 | plugin_new(&(struct attr){attr_plugins,.u.plugins=plugins}, attrs); |
234 | attrs = (struct attr*[]) |
93 | } |
235 | { &(struct attr) |
|
|
236 | { attr_path, |
|
|
237 | { path}},NULL}; |
|
|
238 | plugin_new(&(struct attr) |
|
|
239 | { attr_plugins,.u.plugins=plugins}, attrs); |
|
|
240 | } |
94 | |
241 | |
95 | static void |
|
|
96 | maptool_init(FILE* rule_file) |
242 | static void maptool_init(FILE* rule_file) |
97 | { |
243 | { |
98 | if (plugins) |
244 | if (plugins) |
|
|
245 | { |
99 | plugins_init(plugins); |
246 | plugins_init(plugins); |
|
|
247 | } |
100 | osm_init(rule_file); |
248 | osm_init(rule_file); |
101 | } |
249 | } |
102 | |
250 | |
103 | static void |
251 | void my_sleep(int delay) |
104 | usage(FILE *f) |
|
|
105 | { |
252 | { |
106 | /* DEVELOPPERS : don't forget to update the manpage if you modify theses options */ |
253 | clock_t t1 = clock(), t2; |
|
|
254 | double elapsed; |
|
|
255 | |
|
|
256 | do |
|
|
257 | { |
|
|
258 | t2 = clock(); |
|
|
259 | elapsed = ((double) (t2 - t1)) / CLOCKS_PER_SEC; |
|
|
260 | |
|
|
261 | } |
|
|
262 | while ((elapsed) < delay); |
|
|
263 | } |
|
|
264 | |
|
|
265 | void convert_to_human_time(long long seconds, char *outstring) |
|
|
266 | { |
|
|
267 | if (seconds < 1) |
|
|
268 | { |
|
|
269 | sprintf(outstring, "0s"); |
|
|
270 | return; |
|
|
271 | } |
|
|
272 | |
|
|
273 | int days = (int) seconds / 86400; |
|
|
274 | int hours = (int) (seconds / 3600) - (days * 24); |
|
|
275 | int mins = (int) (seconds / 60) - (days * 1440) - (hours * 60); |
|
|
276 | int secs = (int) seconds % 60; |
|
|
277 | |
|
|
278 | if (days > 0) |
|
|
279 | { |
|
|
280 | sprintf(outstring, "%dd %dh %dm %ds", days, hours, mins, secs); |
|
|
281 | } |
|
|
282 | else if (hours > 0) |
|
|
283 | { |
|
|
284 | sprintf(outstring, "%dh %dm %ds", hours, mins, secs); |
|
|
285 | } |
|
|
286 | else |
|
|
287 | { |
|
|
288 | sprintf(outstring, "%dm %ds", mins, secs); |
|
|
289 | } |
|
|
290 | } |
|
|
291 | |
|
|
292 | void convert_to_human_bytes(long long bytes, char *outstring) |
|
|
293 | { |
|
|
294 | if (bytes < 1) |
|
|
295 | { |
|
|
296 | sprintf(outstring, "0b"); |
|
|
297 | return; |
|
|
298 | } |
|
|
299 | |
|
|
300 | unsigned long g_ = bytes / (1024 * 1024 * 1024); |
|
|
301 | int m_ = (bytes / (1024 * 1024)) - (g_ * 1024); |
|
|
302 | int k_ = (bytes / 1024) - (g_ * (1024 * 1024)) - (m_ * 1024); |
|
|
303 | int b_ = bytes % 1024; |
|
|
304 | |
|
|
305 | if (g_ > 0) |
|
|
306 | { |
|
|
307 | sprintf(outstring, "%luGb", g_); |
|
|
308 | } |
|
|
309 | else if (m_ > 0) |
|
|
310 | { |
|
|
311 | sprintf(outstring, "%dMb", m_); |
|
|
312 | } |
|
|
313 | else if (k_ > 0) |
|
|
314 | { |
|
|
315 | sprintf(outstring, "%dkb", k_); |
|
|
316 | } |
|
|
317 | else |
|
|
318 | { |
|
|
319 | sprintf(outstring, "%db", b_); |
|
|
320 | } |
|
|
321 | } |
|
|
322 | |
|
|
323 | void convert_to_human_bytes2(long long bytes, char *outstring) |
|
|
324 | { |
|
|
325 | if (bytes < 1) |
|
|
326 | { |
|
|
327 | sprintf(outstring, "0b"); |
|
|
328 | return; |
|
|
329 | } |
|
|
330 | |
|
|
331 | int m_ = (bytes / (1024 * 1024)); |
|
|
332 | int k_ = (bytes / 1024) - (m_ * 1024); |
|
|
333 | int b_ = bytes % 1024; |
|
|
334 | |
|
|
335 | if (m_ > 0) |
|
|
336 | { |
|
|
337 | sprintf(outstring, "%dMb", m_); |
|
|
338 | } |
|
|
339 | else if (k_ > 0) |
|
|
340 | { |
|
|
341 | sprintf(outstring, "%dkb", k_); |
|
|
342 | } |
|
|
343 | else |
|
|
344 | { |
|
|
345 | sprintf(outstring, "%db", b_); |
|
|
346 | } |
|
|
347 | } |
|
|
348 | |
|
|
349 | void sql_db_open() |
|
|
350 | { |
|
|
351 | #ifdef MAPTOOL_USE_SQL |
|
|
352 | |
|
|
353 | int retval; |
|
|
354 | |
|
|
355 | fprintf(stderr, "SQL: -- INIT --\n"); |
|
|
356 | |
|
|
357 | #ifdef MAPTOOL_USE_ASYNC_SQL |
|
|
358 | retval = sqlite3async_initialize(NULL, 1); |
|
|
359 | if (retval) |
|
|
360 | { |
|
|
361 | fprintf(stderr, "SQL ASYNC module init failed\n"); |
|
|
362 | } |
|
|
363 | |
|
|
364 | fprintf(stderr, "SQL: -- INIT 1 --\n"); |
|
|
365 | |
|
|
366 | retval = sqlite3async_control(SQLITEASYNC_DELAY, 0); |
|
|
367 | if (retval) |
|
|
368 | { |
|
|
369 | fprintf(stderr, "SQL ASYNC module config 1 failed\n"); |
|
|
370 | } |
|
|
371 | |
|
|
372 | retval = sqlite3async_control(SQLITEASYNC_HALT, SQLITEASYNC_HALT_NEVER); |
|
|
373 | if (retval) |
|
|
374 | { |
|
|
375 | fprintf(stderr, "SQL ASYNC module config 3 failed\n"); |
|
|
376 | } |
|
|
377 | |
|
|
378 | retval = sqlite3async_control(SQLITEASYNC_LOCKFILES, 0); |
|
|
379 | if (retval) |
|
|
380 | { |
|
|
381 | fprintf(stderr, "SQL ASYNC module config 2 failed\n"); |
|
|
382 | } |
|
|
383 | |
|
|
384 | fprintf(stderr, "SQL: -- INIT 2 --\n"); |
|
|
385 | pthread_create(&sqlite_thread001, NULL, sql_thread, NULL); |
|
|
386 | fprintf(stderr, "SQL: -- INIT 3 --\n"); |
|
|
387 | #endif |
|
|
388 | |
|
|
389 | sql_handle = NULL; |
|
|
390 | retval = sqlite3_open(g_strdup_printf("%stemp_data.db",sqlite_db_dir), &sql_handle); |
|
|
391 | // If connection failed, sql_handle returns NULL |
|
|
392 | if (retval) |
|
|
393 | { |
|
|
394 | fprintf(stderr, "SQL Database connection failed\n"); |
|
|
395 | return -1; |
|
|
396 | } |
|
|
397 | |
|
|
398 | sql_handle002a = NULL; |
|
|
399 | |
|
|
400 | retval = sqlite3_open(g_strdup_printf("%stemp_data002a.db",sqlite_db_dir), &sql_handle002a); |
|
|
401 | // If connection failed, sql_handle returns NULL |
|
|
402 | if (retval) |
|
|
403 | { |
|
|
404 | fprintf(stderr, "SQL Database connection002 failed\n"); |
|
|
405 | return -1; |
|
|
406 | } |
|
|
407 | |
|
|
408 | #ifdef MAPTOOL_SPLIT_NODE_DB_MORE |
|
|
409 | sql_handle003a = NULL; |
|
|
410 | |
|
|
411 | retval = sqlite3_open(g_strdup_printf("%stemp_data003a.db",sqlite_db_dir), &sql_handle003a); |
|
|
412 | // If connection failed, sql_handle returns NULL |
|
|
413 | if (retval) |
|
|
414 | { |
|
|
415 | fprintf(stderr, "SQL Database connection003 failed\n"); |
|
|
416 | return -1; |
|
|
417 | } |
|
|
418 | #else |
|
|
419 | sql_handle003a = sql_handle002a; |
|
|
420 | #endif |
|
|
421 | |
|
|
422 | sql_handle002b = NULL; |
|
|
423 | |
|
|
424 | retval = sqlite3_open(g_strdup_printf("%stemp_data002b.db",sqlite_db_dir), &sql_handle002b); |
|
|
425 | // If connection failed, sql_handle returns NULL |
|
|
426 | if (retval) |
|
|
427 | { |
|
|
428 | fprintf(stderr, "SQL Database connection002 failed\n"); |
|
|
429 | return -1; |
|
|
430 | } |
|
|
431 | |
|
|
432 | #ifdef MAPTOOL_SPLIT_NODE_DB_MORE |
|
|
433 | sql_handle003b = NULL; |
|
|
434 | |
|
|
435 | retval = sqlite3_open(g_strdup_printf("%stemp_data003b.db",sqlite_db_dir), &sql_handle003b); |
|
|
436 | // If connection failed, sql_handle returns NULL |
|
|
437 | if (retval) |
|
|
438 | { |
|
|
439 | fprintf(stderr, "SQL Database connection003 failed\n"); |
|
|
440 | return -1; |
|
|
441 | } |
|
|
442 | #else |
|
|
443 | sql_handle003b = sql_handle002b; |
|
|
444 | #endif |
|
|
445 | |
|
|
446 | sql_handle004 = NULL; |
|
|
447 | |
|
|
448 | retval = sqlite3_open(g_strdup_printf("%stemp_data004.db",sqlite_db_dir), &sql_handle004); |
|
|
449 | // If connection failed, sql_handle returns NULL |
|
|
450 | if (retval) |
|
|
451 | { |
|
|
452 | fprintf(stderr, "SQL Database connection004 failed\n"); |
|
|
453 | return -1; |
|
|
454 | } |
|
|
455 | |
|
|
456 | sql_handle005 = NULL; |
|
|
457 | |
|
|
458 | retval = sqlite3_open(g_strdup_printf("%stemp_data005.db",sqlite_db_dir), &sql_handle005); |
|
|
459 | // If connection failed, sql_handle returns NULL |
|
|
460 | if (retval) |
|
|
461 | { |
|
|
462 | fprintf(stderr, "SQL Database connection005 failed\n"); |
|
|
463 | return -1; |
|
|
464 | } |
|
|
465 | |
|
|
466 | sql_handle006 = NULL; |
|
|
467 | retval = sqlite3_open(g_strdup_printf("%stemp_data006.db",sqlite_db_dir), &sql_handle006); |
|
|
468 | // If connection failed, sql_handle returns NULL |
|
|
469 | if (retval) |
|
|
470 | { |
|
|
471 | fprintf(stderr, "SQL Database connection006 failed\n"); |
|
|
472 | return -1; |
|
|
473 | } |
|
|
474 | |
|
|
475 | sql_handle007 = NULL; |
|
|
476 | retval = sqlite3_open(g_strdup_printf("%stemp_data007.db",sqlite_db_dir), &sql_handle007); |
|
|
477 | // If connection failed, sql_handle returns NULL |
|
|
478 | if (retval) |
|
|
479 | { |
|
|
480 | fprintf(stderr, "SQL Database connection007 failed\n"); |
|
|
481 | return -1; |
|
|
482 | } |
|
|
483 | |
|
|
484 | // char* errorMessage2; |
|
|
485 | //sqlite3_exec(sql_handle004, "PRAGMA page_size = 4096", NULL, NULL, &errorMessage2); |
|
|
486 | //sqlite3_exec(sql_handle005, "PRAGMA page_size = 4096", NULL, NULL, &errorMessage2); |
|
|
487 | //sqlite3_exec(sql_handle006, "PRAGMA page_size = 4096", NULL, NULL, &errorMessage2); |
|
|
488 | //sqlite3_exec(sql_handle007, "PRAGMA page_size = 4096", NULL, NULL, &errorMessage2); |
|
|
489 | |
|
|
490 | //sqlite3_exec(sql_handle004, "PRAGMA max_page_count = 2073741823", NULL, NULL, &errorMessage2); |
|
|
491 | //sqlite3_exec(sql_handle005, "PRAGMA max_page_count = 2073741823", NULL, NULL, &errorMessage2); |
|
|
492 | //sqlite3_exec(sql_handle006, "PRAGMA max_page_count = 2073741823", NULL, NULL, &errorMessage2); |
|
|
493 | //sqlite3_exec(sql_handle007, "PRAGMA max_page_count = 2073741823", NULL, NULL, &errorMessage2); |
|
|
494 | |
|
|
495 | |
|
|
496 | char* errorMessage; |
|
|
497 | |
|
|
498 | if (sqlite_temp_dir == 1) |
|
|
499 | { |
|
|
500 | sqlite3_exec(sql_handle, g_strdup_printf("PRAGMA temp_store_directory = '%s/'", sqlite_db_dir), NULL, NULL, &errorMessage); |
|
|
501 | |
|
|
502 | sqlite3_exec(sql_handle004, g_strdup_printf("PRAGMA temp_store_directory = '%s/'", sqlite_db_dir), NULL, NULL, &errorMessage); |
|
|
503 | sqlite3_exec(sql_handle005, g_strdup_printf("PRAGMA temp_store_directory = '%s/'", sqlite_db_dir), NULL, NULL, &errorMessage); |
|
|
504 | sqlite3_exec(sql_handle006, g_strdup_printf("PRAGMA temp_store_directory = '%s/'", sqlite_db_dir), NULL, NULL, &errorMessage); |
|
|
505 | sqlite3_exec(sql_handle007, g_strdup_printf("PRAGMA temp_store_directory = '%s/'", sqlite_db_dir), NULL, NULL, &errorMessage); |
|
|
506 | |
|
|
507 | sqlite3_exec(sql_handle002a, g_strdup_printf("PRAGMA temp_store_directory = '%s/'", sqlite_db_dir), NULL, NULL, &errorMessage); |
|
|
508 | sqlite3_exec(sql_handle002b, g_strdup_printf("PRAGMA temp_store_directory = '%s/'", sqlite_db_dir), NULL, NULL, &errorMessage); |
|
|
509 | sqlite3_exec(sql_handle003a, g_strdup_printf("PRAGMA temp_store_directory = '%s/'", sqlite_db_dir), NULL, NULL, &errorMessage); |
|
|
510 | sqlite3_exec(sql_handle003b, g_strdup_printf("PRAGMA temp_store_directory = '%s/'", sqlite_db_dir), NULL, NULL, &errorMessage); |
|
|
511 | } |
|
|
512 | else |
|
|
513 | { |
|
|
514 | sqlite3_exec(sql_handle, "PRAGMA temp_store_directory = '.'", NULL, NULL, &errorMessage); |
|
|
515 | |
|
|
516 | sqlite3_exec(sql_handle004, "PRAGMA temp_store_directory = '.'", NULL, NULL, &errorMessage); |
|
|
517 | sqlite3_exec(sql_handle005, "PRAGMA temp_store_directory = '.'", NULL, NULL, &errorMessage); |
|
|
518 | sqlite3_exec(sql_handle006, "PRAGMA temp_store_directory = '.'", NULL, NULL, &errorMessage); |
|
|
519 | sqlite3_exec(sql_handle007, "PRAGMA temp_store_directory = '.'", NULL, NULL, &errorMessage); |
|
|
520 | |
|
|
521 | sqlite3_exec(sql_handle002a, "PRAGMA temp_store_directory = '.'", NULL, NULL, &errorMessage); |
|
|
522 | sqlite3_exec(sql_handle002b, "PRAGMA temp_store_directory = '.'", NULL, NULL, &errorMessage); |
|
|
523 | sqlite3_exec(sql_handle003a, "PRAGMA temp_store_directory = '.'", NULL, NULL, &errorMessage); |
|
|
524 | sqlite3_exec(sql_handle003b, "PRAGMA temp_store_directory = '.'", NULL, NULL, &errorMessage); |
|
|
525 | } |
|
|
526 | |
|
|
527 | sqlite3_busy_timeout(sql_handle, 50000); // wait for 5 seconds |
|
|
528 | sqlite3_busy_timeout(sql_handle002a, 50000); // wait for 5 seconds |
|
|
529 | sqlite3_busy_timeout(sql_handle003a, 50000); // wait for 5 seconds |
|
|
530 | sqlite3_busy_timeout(sql_handle002b, 50000); // wait for 5 seconds |
|
|
531 | sqlite3_busy_timeout(sql_handle003b, 50000); // wait for 5 seconds |
|
|
532 | sqlite3_busy_timeout(sql_handle004, 50000); // wait for 5 seconds |
|
|
533 | sqlite3_busy_timeout(sql_handle005, 50000); // wait for 5 seconds |
|
|
534 | sqlite3_busy_timeout(sql_handle006, 50000); // wait for 5 seconds |
|
|
535 | sqlite3_busy_timeout(sql_handle007, 50000); // wait for 5 seconds |
|
|
536 | |
|
|
537 | fprintf(stderr, "SQL Connection successful\n"); |
|
|
538 | #endif |
|
|
539 | } |
|
|
540 | |
|
|
541 | void sql_db_close() |
|
|
542 | { |
|
|
543 | #ifdef MAPTOOL_USE_SQL |
|
|
544 | int retval; |
|
|
545 | |
|
|
546 | sql_counter = 0; |
|
|
547 | sql_counter2 = 0; |
|
|
548 | sql_counter3 = 0; |
|
|
549 | sql_counter4 = 0; |
|
|
550 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
551 | sqlite3_exec(sql_handle002a, "COMMIT", 0, 0, 0); |
|
|
552 | sqlite3_exec(sql_handle003a, "COMMIT", 0, 0, 0); |
|
|
553 | sqlite3_exec(sql_handle002b, "COMMIT", 0, 0, 0); |
|
|
554 | sqlite3_exec(sql_handle003b, "COMMIT", 0, 0, 0); |
|
|
555 | sqlite3_exec(sql_handle004, "COMMIT", 0, 0, 0); |
|
|
556 | sqlite3_exec(sql_handle005, "COMMIT", 0, 0, 0); |
|
|
557 | sqlite3_exec(sql_handle006, "COMMIT", 0, 0, 0); |
|
|
558 | sqlite3_exec(sql_handle007, "COMMIT", 0, 0, 0); |
|
|
559 | |
|
|
560 | retval = sqlite3_finalize(stmt_nodea); |
|
|
561 | fprintf(stderr, "fin:%d\n", retval); |
|
|
562 | retval = sqlite3_finalize(stmt_node__2a); |
|
|
563 | fprintf(stderr, "fin:%d\n", retval); |
|
|
564 | |
|
|
565 | retval = sqlite3_finalize(stmt_nodeb); |
|
|
566 | fprintf(stderr, "fin:%d\n", retval); |
|
|
567 | retval = sqlite3_finalize(stmt_node__2b); |
|
|
568 | fprintf(stderr, "fin:%d\n", retval); |
|
|
569 | |
|
|
570 | retval = sqlite3_finalize(stmt_nodei); |
|
|
571 | fprintf(stderr, "fin:%d\n", retval); |
|
|
572 | retval = sqlite3_finalize(stmt_way); |
|
|
573 | fprintf(stderr, "fin:%d\n", retval); |
|
|
574 | //retval = sqlite3_finalize(stmt_way2); |
|
|
575 | //fprintf(stderr, "fin:%d\n", retval); |
|
|
576 | retval = sqlite3_finalize(stmt_way_node); |
|
|
577 | fprintf(stderr, "fin:%d\n", retval); |
|
|
578 | retval = sqlite3_finalize(stmt_way_node__2); |
|
|
579 | fprintf(stderr, "fin:%d\n", retval); |
|
|
580 | retval = sqlite3_finalize(stmt_way_nodeb); |
|
|
581 | fprintf(stderr, "fin:%d\n", retval); |
|
|
582 | retval = sqlite3_finalize(stmt_way_node__2b); |
|
|
583 | fprintf(stderr, "fin:%d\n", retval); |
|
|
584 | |
|
|
585 | retval = sqlite3_finalize(stmt_sel001); |
|
|
586 | fprintf(stderr, "fin:%d\n", retval); |
|
|
587 | retval = sqlite3_finalize(stmt_sel001__2); |
|
|
588 | fprintf(stderr, "fin:%d\n", retval); |
|
|
589 | retval = sqlite3_finalize(stmt_sel001b); |
|
|
590 | fprintf(stderr, "fin:%d\n", retval); |
|
|
591 | retval = sqlite3_finalize(stmt_sel001__2b); |
|
|
592 | fprintf(stderr, "fin:%d\n", retval); |
|
|
593 | |
|
|
594 | retval = sqlite3_finalize(stmt_sel002a); |
|
|
595 | fprintf(stderr, "fin:%d\n", retval); |
|
|
596 | retval = sqlite3_finalize(stmt_sel002__2a); |
|
|
597 | fprintf(stderr, "fin:%d\n", retval); |
|
|
598 | |
|
|
599 | retval = sqlite3_finalize(stmt_sel002b); |
|
|
600 | fprintf(stderr, "fin:%d\n", retval); |
|
|
601 | retval = sqlite3_finalize(stmt_sel002__2b); |
|
|
602 | fprintf(stderr, "fin:%d\n", retval); |
|
|
603 | |
|
|
604 | retval = sqlite3_finalize(stmt_town); |
|
|
605 | fprintf(stderr, "fin:%d\n", retval); |
|
|
606 | |
|
|
607 | retval = sqlite3_finalize(stmt_town_sel001); |
|
|
608 | fprintf(stderr, "fin:%d\n", retval); |
|
|
609 | retval = sqlite3_finalize(stmt_way3); |
|
|
610 | fprintf(stderr, "fin:%d\n", retval); |
|
|
611 | retval = sqlite3_finalize(stmt_way3a); |
|
|
612 | fprintf(stderr, "fin:%d\n", retval); |
|
|
613 | retval = sqlite3_finalize(stmt_way3b); |
|
|
614 | fprintf(stderr, "fin:%d\n", retval); |
|
|
615 | retval = sqlite3_finalize(stmt_town_sel002); |
|
|
616 | fprintf(stderr, "fin:%d\n", retval); |
|
|
617 | retval = sqlite3_finalize(stmt_town_sel005); |
|
|
618 | fprintf(stderr, "fin:%d\n", retval); |
|
|
619 | retval = sqlite3_finalize(stmt_town_sel006); |
|
|
620 | fprintf(stderr, "fin:%d\n", retval); |
|
|
621 | retval = sqlite3_finalize(stmt_town_sel007); |
|
|
622 | fprintf(stderr, "fin:%d\n", retval); |
|
|
623 | retval = sqlite3_finalize(stmt_town_sel008); |
|
|
624 | fprintf(stderr, "fin:%d\n", retval); |
|
|
625 | |
|
|
626 | retval = sqlite3_finalize(stmt_bd_001); |
|
|
627 | fprintf(stderr, "fin:%d\n", retval); |
|
|
628 | retval = sqlite3_finalize(stmt_bd_002); |
|
|
629 | fprintf(stderr, "fin:%d\n", retval); |
|
|
630 | retval = sqlite3_finalize(stmt_bd_003); |
|
|
631 | fprintf(stderr, "fin:%d\n", retval); |
|
|
632 | retval = sqlite3_finalize(stmt_bd_004); |
|
|
633 | fprintf(stderr, "fin:%d\n", retval); |
|
|
634 | retval = sqlite3_finalize(stmt_bd_005); |
|
|
635 | fprintf(stderr, "fin:%d\n", retval); |
|
|
636 | |
|
|
637 | retval = sqlite3_finalize(stmt_sel003); |
|
|
638 | fprintf(stderr, "fin:%d\n", retval); |
|
|
639 | retval = sqlite3_finalize(stmt_sel003u); |
|
|
640 | fprintf(stderr, "fin:%d\n", retval); |
|
|
641 | retval = sqlite3_finalize(stmt_sel004); |
|
|
642 | fprintf(stderr, "fin:%d\n", retval); |
|
|
643 | |
|
|
644 | // set temp_store back to default |
|
|
645 | // sqlite3_exec(sql_handle, "PRAGMA temp_store=DEFAULT", NULL, NULL, &errorMessage); |
|
|
646 | |
|
|
647 | // close sql file |
|
|
648 | retval = sqlite3_close(sql_handle); |
|
|
649 | fprintf(stderr, "close:%d\n", retval); |
|
|
650 | |
|
|
651 | retval = sqlite3_close(sql_handle002a); |
|
|
652 | fprintf(stderr, "close002a:%d\n", retval); |
|
|
653 | retval = sqlite3_close(sql_handle003a); |
|
|
654 | fprintf(stderr, "close003a:%d\n", retval); |
|
|
655 | |
|
|
656 | retval = sqlite3_close(sql_handle002b); |
|
|
657 | fprintf(stderr, "close002b:%d\n", retval); |
|
|
658 | retval = sqlite3_close(sql_handle003b); |
|
|
659 | fprintf(stderr, "close003b:%d\n", retval); |
|
|
660 | |
|
|
661 | retval = sqlite3_close(sql_handle004); |
|
|
662 | fprintf(stderr, "close004:%d\n", retval); |
|
|
663 | retval = sqlite3_close(sql_handle005); |
|
|
664 | fprintf(stderr, "close005:%d\n", retval); |
|
|
665 | retval = sqlite3_close(sql_handle006); |
|
|
666 | fprintf(stderr, "close006:%d\n", retval); |
|
|
667 | retval = sqlite3_close(sql_handle007); |
|
|
668 | fprintf(stderr, "close007:%d\n", retval); |
|
|
669 | |
|
|
670 | #ifdef MAPTOOL_USE_ASYNC_SQL |
|
|
671 | |
|
|
672 | retval = sqlite3async_control(SQLITEASYNC_HALT, SQLITEASYNC_HALT_IDLE); |
|
|
673 | if (retval) |
|
|
674 | { |
|
|
675 | fprintf(stderr, "SQL ASYNC module config 3a failed\n"); |
|
|
676 | } |
|
|
677 | |
|
|
678 | sqlite3async_shutdown(); |
|
|
679 | |
|
|
680 | //int st = pthread_cancel(sqlite_thread001); |
|
|
681 | //if (st != 0) |
|
|
682 | //{ |
|
|
683 | // fprintf(stderr, "cancel async:%d\n", st); |
|
|
684 | //} |
|
|
685 | |
|
|
686 | fprintf(stderr, "close async 002:%d\n", retval); |
|
|
687 | if (sqlite_thread001) |
|
|
688 | { |
|
|
689 | fprintf(stderr, "close async 002.1:%d\n", retval); |
|
|
690 | pthread_join(sqlite_thread001, NULL); |
|
|
691 | } |
|
|
692 | fprintf(stderr, "close async 003:%d\n", retval); |
|
|
693 | |
|
|
694 | fprintf(stderr, "close async 001:%d\n", retval); |
|
|
695 | #endif |
|
|
696 | |
|
|
697 | #endif |
|
|
698 | } |
|
|
699 | |
|
|
700 | void sql_create_index001() |
|
|
701 | { |
|
|
702 | #ifdef MAPTOOL_USE_SQL |
|
|
703 | int retval; |
|
|
704 | char* errorMessage; |
|
|
705 | |
|
|
706 | sqlite3_exec(sql_handle004, "PRAGMA temp_store=FILE", NULL, NULL, &errorMessage); |
|
|
707 | sqlite3_exec(sql_handle004, "PRAGMA cache_size = -16000", NULL, NULL, &errorMessage); |
|
|
708 | sqlite3_exec(sql_handle005, "PRAGMA temp_store=FILE", NULL, NULL, &errorMessage); |
|
|
709 | sqlite3_exec(sql_handle005, "PRAGMA cache_size = -16000", NULL, NULL, &errorMessage); |
|
|
710 | sqlite3_exec(sql_handle006, "PRAGMA temp_store=FILE", NULL, NULL, &errorMessage); |
|
|
711 | sqlite3_exec(sql_handle006, "PRAGMA cache_size = -16000", NULL, NULL, &errorMessage); |
|
|
712 | sqlite3_exec(sql_handle007, "PRAGMA temp_store=FILE", NULL, NULL, &errorMessage); |
|
|
713 | sqlite3_exec(sql_handle007, "PRAGMA cache_size = -16000", NULL, NULL, &errorMessage); |
|
|
714 | //sqlite3_exec(sql_handle004, "PRAGMA journal_mode=PERSIST", NULL, NULL, &errorMessage); |
|
|
715 | //sqlite3_exec(sql_handle005, "PRAGMA journal_mode=PERSIST", NULL, NULL, &errorMessage); |
|
|
716 | //sqlite3_exec(sql_handle006, "PRAGMA journal_mode=PERSIST", NULL, NULL, &errorMessage); |
|
|
717 | //sqlite3_exec(sql_handle007, "PRAGMA journal_mode=PERSIST", NULL, NULL, &errorMessage); |
|
|
718 | |
|
|
719 | |
|
|
720 | //sqlite3_exec(sql_handle, "PRAGMA journal_mode=PERSIST", NULL, NULL, &errorMessage); |
|
|
721 | sqlite3_exec(sql_handle, "PRAGMA temp_store=FILE", NULL, NULL, &errorMessage); |
|
|
722 | sqlite3_exec(sql_handle, "PRAGMA cache_size = -9000", NULL, NULL, &errorMessage); |
|
|
723 | |
|
|
724 | char create_table5[100] = "CREATE index wn1 on way_node(way_id)"; |
|
|
725 | retval = sqlite3_exec(sql_handle004, create_table5, 0, 0, 0); |
|
|
726 | fprintf(stderr, "index:%d\n", retval); |
|
|
727 | retval = sqlite3_exec(sql_handle005, create_table5, 0, 0, 0); |
|
|
728 | fprintf(stderr, "index:%d\n", retval); |
|
|
729 | retval = sqlite3_exec(sql_handle006, create_table5, 0, 0, 0); |
|
|
730 | fprintf(stderr, "index:%d\n", retval); |
|
|
731 | retval = sqlite3_exec(sql_handle007, create_table5, 0, 0, 0); |
|
|
732 | fprintf(stderr, "index:%d\n", retval); |
|
|
733 | |
|
|
734 | /* |
|
|
735 | char create_table5a[100] = "alter table way_node rename to way_node2"; |
|
|
736 | char create_table5b[100] = "CREATE TABLE way_node (way_id integer,node_id integer,s integer)"; |
|
|
737 | char create_table5c[100] = "CREATE index way_node_i01 on way_node (way_id)"; |
|
|
738 | char create_table5d[100] = "insert into way_node select * from way_node2"; |
|
|
739 | char create_table5e[100] = "drop table way_node2"; |
|
|
740 | |
|
|
741 | retval = sqlite3_exec(sql_handle004, create_table5a, 0, 0, 0); |
|
|
742 | fprintf(stderr, "index:%d\n", retval); |
|
|
743 | retval = sqlite3_exec(sql_handle004, create_table5b, 0, 0, 0); |
|
|
744 | fprintf(stderr, "index:%d\n", retval); |
|
|
745 | retval = sqlite3_exec(sql_handle004, create_table5c, 0, 0, 0); |
|
|
746 | fprintf(stderr, "index:%d\n", retval); |
|
|
747 | retval = sqlite3_exec(sql_handle004, create_table5d, 0, 0, 0); |
|
|
748 | fprintf(stderr, "index:%d\n", retval); |
|
|
749 | retval = sqlite3_exec(sql_handle004, create_table5e, 0, 0, 0); |
|
|
750 | fprintf(stderr, "index:%d\n", retval); |
|
|
751 | |
|
|
752 | retval = sqlite3_exec(sql_handle005, create_table5a, 0, 0, 0); |
|
|
753 | fprintf(stderr, "index:%d\n", retval); |
|
|
754 | retval = sqlite3_exec(sql_handle005, create_table5b, 0, 0, 0); |
|
|
755 | fprintf(stderr, "index:%d\n", retval); |
|
|
756 | retval = sqlite3_exec(sql_handle005, create_table5c, 0, 0, 0); |
|
|
757 | fprintf(stderr, "index:%d\n", retval); |
|
|
758 | retval = sqlite3_exec(sql_handle005, create_table5d, 0, 0, 0); |
|
|
759 | fprintf(stderr, "index:%d\n", retval); |
|
|
760 | retval = sqlite3_exec(sql_handle005, create_table5e, 0, 0, 0); |
|
|
761 | fprintf(stderr, "index:%d\n", retval); |
|
|
762 | |
|
|
763 | retval = sqlite3_exec(sql_handle006, create_table5a, 0, 0, 0); |
|
|
764 | fprintf(stderr, "index:%d\n", retval); |
|
|
765 | retval = sqlite3_exec(sql_handle006, create_table5b, 0, 0, 0); |
|
|
766 | fprintf(stderr, "index:%d\n", retval); |
|
|
767 | retval = sqlite3_exec(sql_handle006, create_table5c, 0, 0, 0); |
|
|
768 | fprintf(stderr, "index:%d\n", retval); |
|
|
769 | retval = sqlite3_exec(sql_handle006, create_table5d, 0, 0, 0); |
|
|
770 | fprintf(stderr, "index:%d\n", retval); |
|
|
771 | retval = sqlite3_exec(sql_handle006, create_table5e, 0, 0, 0); |
|
|
772 | fprintf(stderr, "index:%d\n", retval); |
|
|
773 | |
|
|
774 | retval = sqlite3_exec(sql_handle007, create_table5a, 0, 0, 0); |
|
|
775 | fprintf(stderr, "index:%d\n", retval); |
|
|
776 | retval = sqlite3_exec(sql_handle007, create_table5b, 0, 0, 0); |
|
|
777 | fprintf(stderr, "index:%d\n", retval); |
|
|
778 | retval = sqlite3_exec(sql_handle007, create_table5c, 0, 0, 0); |
|
|
779 | fprintf(stderr, "index:%d\n", retval); |
|
|
780 | retval = sqlite3_exec(sql_handle007, create_table5d, 0, 0, 0); |
|
|
781 | fprintf(stderr, "index:%d\n", retval); |
|
|
782 | retval = sqlite3_exec(sql_handle007, create_table5e, 0, 0, 0); |
|
|
783 | fprintf(stderr, "index:%d\n", retval); |
|
|
784 | */ |
|
|
785 | |
|
|
786 | //char create_table10[100] = "CREATE index w2 on way(lat)"; |
|
|
787 | //retval = sqlite3_exec(sql_handle, create_table10, 0, 0, 0); |
|
|
788 | //fprintf(stderr, "index:%d\n", retval); |
|
|
789 | |
|
|
790 | //char create_table11[100] = "CREATE index w3 on way(lon)"; |
|
|
791 | //retval = sqlite3_exec(sql_handle, create_table11, 0, 0, 0); |
|
|
792 | //fprintf(stderr, "index:%d\n", retval); |
|
|
793 | |
|
|
794 | //char create_table4[100] = "CREATE index w1 on way(town_id)"; |
|
|
795 | //retval = sqlite3_exec(sql_handle,create_table4,0,0,0); |
|
|
796 | //fprintf(stderr, "index:%d\n", retval); |
|
|
797 | |
|
|
798 | char create_table11[100] = "create index w5 on way(town_id,lat,lon)"; |
|
|
799 | retval = sqlite3_exec(sql_handle,create_table11,0,0,0); |
|
|
800 | fprintf(stderr, "index:%d\n", retval); |
|
|
801 | |
|
|
802 | char create_table12[100] = "CREATE index w4 on way(id)"; |
|
|
803 | retval = sqlite3_exec(sql_handle, create_table12, 0, 0, 0); |
|
|
804 | fprintf(stderr, "index:%d\n", retval); |
|
|
805 | |
|
|
806 | //char create_table13[100] = "create index w6 on way(ind)"; |
|
|
807 | //retval = sqlite3_exec(sql_handle,create_table13,0,0,0); |
|
|
808 | //fprintf(stderr, "index:%d\n", retval); |
|
|
809 | |
|
|
810 | char create_table14[100] = "create index w8 on way(name_fold,town_id,ind)"; |
|
|
811 | retval = sqlite3_exec(sql_handle,create_table14,0,0,0); |
|
|
812 | fprintf(stderr, "index:%d\n", retval); |
|
|
813 | |
|
|
814 | //char create_table15[100] = "create index w9 on way(name_fold)"; |
|
|
815 | //retval = sqlite3_exec(sql_handle,create_table15,0,0,0); |
|
|
816 | //fprintf(stderr, "index:%d\n", retval); |
|
|
817 | |
|
|
818 | char create_table16[100] = "create index w10 on way(town_id,ind)"; |
|
|
819 | retval = sqlite3_exec(sql_handle,create_table16,0,0,0); |
|
|
820 | fprintf(stderr, "index:%d\n", retval); |
|
|
821 | |
|
|
822 | char create_table17[100] = "create index w11 on way(ind,name_fold)"; |
|
|
823 | retval = sqlite3_exec(sql_handle,create_table17,0,0,0); |
|
|
824 | fprintf(stderr, "index:%d\n", retval); |
|
|
825 | |
|
|
826 | retval = sqlite3_exec(sql_handle, "analyze;", NULL, NULL, &errorMessage); |
|
|
827 | fprintf(stderr, "index:%d\n", retval); |
|
|
828 | retval = sqlite3_exec(sql_handle004, "analyze;", NULL, NULL, &errorMessage); |
|
|
829 | fprintf(stderr, "index:%d\n", retval); |
|
|
830 | retval = sqlite3_exec(sql_handle005, "analyze;", NULL, NULL, &errorMessage); |
|
|
831 | fprintf(stderr, "index:%d\n", retval); |
|
|
832 | retval = sqlite3_exec(sql_handle006, "analyze;", NULL, NULL, &errorMessage); |
|
|
833 | fprintf(stderr, "index:%d\n", retval); |
|
|
834 | retval = sqlite3_exec(sql_handle007, "analyze;", NULL, NULL, &errorMessage); |
|
|
835 | fprintf(stderr, "index:%d\n", retval); |
|
|
836 | |
|
|
837 | sqlite3_exec(sql_handle004, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
838 | sqlite3_exec(sql_handle004, "PRAGMA cache_size = -30000", NULL, NULL, &errorMessage); |
|
|
839 | sqlite3_exec(sql_handle005, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
840 | sqlite3_exec(sql_handle005, "PRAGMA cache_size = -30000", NULL, NULL, &errorMessage); |
|
|
841 | sqlite3_exec(sql_handle006, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
842 | sqlite3_exec(sql_handle006, "PRAGMA cache_size = -30000", NULL, NULL, &errorMessage); |
|
|
843 | sqlite3_exec(sql_handle007, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
844 | sqlite3_exec(sql_handle007, "PRAGMA cache_size = -30000", NULL, NULL, &errorMessage); |
|
|
845 | |
|
|
846 | sqlite3_exec(sql_handle004, "PRAGMA journal_mode=OFF", NULL, NULL, &errorMessage); |
|
|
847 | sqlite3_exec(sql_handle005, "PRAGMA journal_mode=OFF", NULL, NULL, &errorMessage); |
|
|
848 | sqlite3_exec(sql_handle006, "PRAGMA journal_mode=OFF", NULL, NULL, &errorMessage); |
|
|
849 | sqlite3_exec(sql_handle007, "PRAGMA journal_mode=OFF", NULL, NULL, &errorMessage); |
|
|
850 | |
|
|
851 | sqlite3_exec(sql_handle, "PRAGMA journal_mode=OFF", NULL, NULL, &errorMessage); |
|
|
852 | |
|
|
853 | sqlite3_exec(sql_handle, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
854 | sqlite3_exec(sql_handle, "PRAGMA cache_size = -30000", NULL, NULL, &errorMessage); |
|
|
855 | |
|
|
856 | #endif |
|
|
857 | } |
|
|
858 | |
|
|
859 | void sql_create_index002() |
|
|
860 | { |
|
|
861 | #ifdef MAPTOOL_USE_SQL |
|
|
862 | int retval; |
|
|
863 | char* errorMessage; |
|
|
864 | |
|
|
865 | sqlite3_exec(sql_handle004, "PRAGMA temp_store=FILE", NULL, NULL, &errorMessage); |
|
|
866 | sqlite3_exec(sql_handle004, "PRAGMA cache_size = -10000", NULL, NULL, &errorMessage); |
|
|
867 | sqlite3_exec(sql_handle005, "PRAGMA temp_store=FILE", NULL, NULL, &errorMessage); |
|
|
868 | sqlite3_exec(sql_handle005, "PRAGMA cache_size = -10000", NULL, NULL, &errorMessage); |
|
|
869 | sqlite3_exec(sql_handle006, "PRAGMA temp_store=FILE", NULL, NULL, &errorMessage); |
|
|
870 | sqlite3_exec(sql_handle006, "PRAGMA cache_size = -10000", NULL, NULL, &errorMessage); |
|
|
871 | sqlite3_exec(sql_handle007, "PRAGMA temp_store=FILE", NULL, NULL, &errorMessage); |
|
|
872 | sqlite3_exec(sql_handle007, "PRAGMA cache_size = -10000", NULL, NULL, &errorMessage); |
|
|
873 | |
|
|
874 | sqlite3_exec(sql_handle, "PRAGMA temp_store=FILE", NULL, NULL, &errorMessage); |
|
|
875 | sqlite3_exec(sql_handle, "PRAGMA cache_size = -10000", NULL, NULL, &errorMessage); |
|
|
876 | |
|
|
877 | char create_table9[100] = "CREATE index twn1 on town(country_id)"; |
|
|
878 | retval = sqlite3_exec(sql_handle, create_table9, 0, 0, 0); |
|
|
879 | fprintf(stderr, "index:%d\n", retval); |
|
|
880 | char create_table12[100] = "CREATE index twn2 on town(size)"; |
|
|
881 | retval = sqlite3_exec(sql_handle, create_table12, 0, 0, 0); |
|
|
882 | fprintf(stderr, "index:%d\n", retval); |
|
|
883 | char create_table13[100] = "CREATE index twn3 on town(lat)"; |
|
|
884 | retval = sqlite3_exec(sql_handle, create_table13, 0, 0, 0); |
|
|
885 | fprintf(stderr, "index:%d\n", retval); |
|
|
886 | char create_table14[100] = "CREATE index twn4 on town(lon)"; |
|
|
887 | retval = sqlite3_exec(sql_handle, create_table14, 0, 0, 0); |
|
|
888 | fprintf(stderr, "index:%d\n", retval); |
|
|
889 | char create_table15[100] = "CREATE index twn5 on town(done)"; |
|
|
890 | retval = sqlite3_exec(sql_handle, create_table15, 0, 0, 0); |
|
|
891 | fprintf(stderr, "index:%d\n", retval); |
|
|
892 | |
|
|
893 | retval = sqlite3_exec(sql_handle, "analyze;", NULL, NULL, &errorMessage); |
|
|
894 | fprintf(stderr, "index:%d\n", retval); |
|
|
895 | retval = sqlite3_exec(sql_handle004, "analyze;", NULL, NULL, &errorMessage); |
|
|
896 | fprintf(stderr, "index:%d\n", retval); |
|
|
897 | retval = sqlite3_exec(sql_handle005, "analyze;", NULL, NULL, &errorMessage); |
|
|
898 | fprintf(stderr, "index:%d\n", retval); |
|
|
899 | retval = sqlite3_exec(sql_handle006, "analyze;", NULL, NULL, &errorMessage); |
|
|
900 | fprintf(stderr, "index:%d\n", retval); |
|
|
901 | retval = sqlite3_exec(sql_handle007, "analyze;", NULL, NULL, &errorMessage); |
|
|
902 | fprintf(stderr, "index:%d\n", retval); |
|
|
903 | |
|
|
904 | sqlite3_exec(sql_handle004, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
905 | sqlite3_exec(sql_handle004, "PRAGMA cache_size = -30000", NULL, NULL, &errorMessage); |
|
|
906 | sqlite3_exec(sql_handle005, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
907 | sqlite3_exec(sql_handle005, "PRAGMA cache_size = -30000", NULL, NULL, &errorMessage); |
|
|
908 | sqlite3_exec(sql_handle006, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
909 | sqlite3_exec(sql_handle006, "PRAGMA cache_size = -30000", NULL, NULL, &errorMessage); |
|
|
910 | sqlite3_exec(sql_handle007, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
911 | sqlite3_exec(sql_handle007, "PRAGMA cache_size = -30000", NULL, NULL, &errorMessage); |
|
|
912 | |
|
|
913 | sqlite3_exec(sql_handle, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
914 | sqlite3_exec(sql_handle, "PRAGMA cache_size = -30000", NULL, NULL, &errorMessage); |
|
|
915 | |
|
|
916 | #endif |
|
|
917 | } |
|
|
918 | |
|
|
919 | void sql_create_index003() |
|
|
920 | { |
|
|
921 | #ifdef MAPTOOL_USE_SQL |
|
|
922 | int retval; |
|
|
923 | char* errorMessage; |
|
|
924 | |
|
|
925 | /* |
|
|
926 | sqlite3_exec(sql_handle002a, "PRAGMA temp_store=FILE", NULL, NULL, &errorMessage); |
|
|
927 | sqlite3_exec(sql_handle002a, "PRAGMA cache_size = -10000", NULL, NULL, &errorMessage); |
|
|
928 | sqlite3_exec(sql_handle003a, "PRAGMA temp_store=FILE", NULL, NULL, &errorMessage); |
|
|
929 | sqlite3_exec(sql_handle003a, "PRAGMA cache_size = -10000", NULL, NULL, &errorMessage); |
|
|
930 | sqlite3_exec(sql_handle002b, "PRAGMA temp_store=FILE", NULL, NULL, &errorMessage); |
|
|
931 | sqlite3_exec(sql_handle002b, "PRAGMA cache_size = -10000", NULL, NULL, &errorMessage); |
|
|
932 | sqlite3_exec(sql_handle003b, "PRAGMA temp_store=FILE", NULL, NULL, &errorMessage); |
|
|
933 | sqlite3_exec(sql_handle003b, "PRAGMA cache_size = -10000", NULL, NULL, &errorMessage); |
|
|
934 | */ |
|
|
935 | |
|
|
936 | // char create_table9[100] = "CREATE index nd01 on node(id)"; |
|
|
937 | /* |
|
|
938 | retval = sqlite3_exec(sql_handle002a, create_table9, 0, 0, 0); |
|
|
939 | fprintf(stderr, "index:%d\n", retval); |
|
|
940 | retval = sqlite3_exec(sql_handle003a, create_table9, 0, 0, 0); |
|
|
941 | fprintf(stderr, "index:%d\n", retval); |
|
|
942 | retval = sqlite3_exec(sql_handle002b, create_table9, 0, 0, 0); |
|
|
943 | fprintf(stderr, "index:%d\n", retval); |
|
|
944 | retval = sqlite3_exec(sql_handle003b, create_table9, 0, 0, 0); |
|
|
945 | fprintf(stderr, "index:%d\n", retval); |
|
|
946 | */ |
|
|
947 | |
|
|
948 | retval = sqlite3_exec(sql_handle002a, "analyze;", NULL, NULL, &errorMessage); |
|
|
949 | fprintf(stderr, "index:%d\n", retval); |
|
|
950 | retval = sqlite3_exec(sql_handle003a, "analyze;", NULL, NULL, &errorMessage); |
|
|
951 | fprintf(stderr, "index:%d\n", retval); |
|
|
952 | retval = sqlite3_exec(sql_handle002b, "analyze;", NULL, NULL, &errorMessage); |
|
|
953 | fprintf(stderr, "index:%d\n", retval); |
|
|
954 | retval = sqlite3_exec(sql_handle003b, "analyze;", NULL, NULL, &errorMessage); |
|
|
955 | fprintf(stderr, "index:%d\n", retval); |
|
|
956 | |
|
|
957 | /* |
|
|
958 | sqlite3_exec(sql_handle002a, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
959 | sqlite3_exec(sql_handle002a, "PRAGMA cache_size = -30000", NULL, NULL, &errorMessage); |
|
|
960 | sqlite3_exec(sql_handle003a, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
961 | sqlite3_exec(sql_handle003a, "PRAGMA cache_size = -30000", NULL, NULL, &errorMessage); |
|
|
962 | sqlite3_exec(sql_handle002b, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
963 | sqlite3_exec(sql_handle002b, "PRAGMA cache_size = -30000", NULL, NULL, &errorMessage); |
|
|
964 | sqlite3_exec(sql_handle003b, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
965 | sqlite3_exec(sql_handle003b, "PRAGMA cache_size = -30000", NULL, NULL, &errorMessage); |
|
|
966 | */ |
|
|
967 | |
|
|
968 | #endif |
|
|
969 | } |
|
|
970 | |
|
|
971 | void sql_db_init(int startup) |
|
|
972 | { |
|
|
973 | #ifdef MAPTOOL_USE_SQL |
|
|
974 | int retval; |
|
|
975 | |
|
|
976 | if (startup == 1) |
|
|
977 | { |
|
|
978 | // Create the SQL query for creating a table |
|
|
979 | //char create_table1[200] = "CREATE TABLE IF NOT EXISTS way (id integer primary key asc, town_id integer, lat real,lon real, name text)"; |
|
|
980 | char create_table1[200] = "CREATE TABLE IF NOT EXISTS way (id integer, town_id integer, ind integer, lat real,lon real, name text, name_fold text)"; |
|
|
981 | retval = sqlite3_exec(sql_handle, create_table1, 0, 0, 0); |
|
|
982 | |
|
|
983 | char create_table2[200] = "CREATE TABLE IF NOT EXISTS way_node(way_id integer,node_id integer, s integer)"; |
|
|
984 | retval = sqlite3_exec(sql_handle004, create_table2, 0, 0, 0); |
|
|
985 | fprintf(stderr, "table:%d\n", retval); |
|
|
986 | retval = sqlite3_exec(sql_handle005, create_table2, 0, 0, 0); |
|
|
987 | fprintf(stderr, "table:%d\n", retval); |
|
|
988 | retval = sqlite3_exec(sql_handle006, create_table2, 0, 0, 0); |
|
|
989 | fprintf(stderr, "table:%d\n", retval); |
|
|
990 | retval = sqlite3_exec(sql_handle007, create_table2, 0, 0, 0); |
|
|
991 | fprintf(stderr, "table:%d\n", retval); |
|
|
992 | |
|
|
993 | char create_table15[200] = "CREATE TABLE IF NOT EXISTS boundary(rel_id integer primary key asc,admin_level integer, done integer, parent_rel_id integer, country_id integer, lat real, lon real, name text)"; |
|
|
994 | retval = sqlite3_exec(sql_handle, create_table15, 0, 0, 0); |
|
|
995 | fprintf(stderr, "table:%d\n", retval); |
|
|
996 | |
|
|
997 | char create_table3[200] = "CREATE TABLE IF NOT EXISTS node(id integer primary key asc,lat real,lon real)"; |
|
|
998 | //char create_table3[200] = "CREATE TABLE IF NOT EXISTS node(id integer ,lat real,lon real)"; |
|
|
999 | retval = sqlite3_exec(sql_handle002a, create_table3, 0, 0, 0); |
|
|
1000 | fprintf(stderr, "table:%d\n", retval); |
|
|
1001 | retval = sqlite3_exec(sql_handle003a, create_table3, 0, 0, 0); |
|
|
1002 | fprintf(stderr, "table:%d\n", retval); |
|
|
1003 | retval = sqlite3_exec(sql_handle002b, create_table3, 0, 0, 0); |
|
|
1004 | fprintf(stderr, "table:%d\n", retval); |
|
|
1005 | retval = sqlite3_exec(sql_handle003b, create_table3, 0, 0, 0); |
|
|
1006 | fprintf(stderr, "table:%d\n", retval); |
|
|
1007 | |
|
|
1008 | //char create_table7[200] = "CREATE TABLE IF NOT EXISTS nodei(id integer primary key asc,lat integer,lon integer)"; |
|
|
1009 | //retval = sqlite3_exec(sql_handle002, create_table7, 0, 0, 0); |
|
|
1010 | |
|
|
1011 | char create_table8[200] = "CREATE TABLE IF NOT EXISTS town(id integer primary key asc, country_id integer,size integer, lat real, lon real, postal text, name text, done integer, border_id integer)"; |
|
|
1012 | retval = sqlite3_exec(sql_handle, create_table8, 0, 0, 0); |
|
|
1013 | |
|
|
1014 | char create_table88[200] = "CREATE TABLE IF NOT EXISTS town2(id integer primary key asc, border_id integer, admin_level integer)"; |
|
|
1015 | retval = sqlite3_exec(sql_handle, create_table88, 0, 0, 0); |
|
|
1016 | |
|
|
1017 | char create_table4[100] = "CREATE index w1 on way(town_id)"; |
|
|
1018 | //retval = sqlite3_exec(sql_handle,create_table4,0,0,0); |
|
|
1019 | |
|
|
1020 | char create_table5[100] = "CREATE index wn1 on way_node(way_id)"; |
|
|
1021 | //retval = sqlite3_exec(sql_handle004, create_table5, 0, 0, 0); |
|
|
1022 | //retval = sqlite3_exec(sql_handle005, create_table5, 0, 0, 0); |
|
|
1023 | //retval = sqlite3_exec(sql_handle006, create_table5, 0, 0, 0); |
|
|
1024 | //retval = sqlite3_exec(sql_handle007, create_table5, 0, 0, 0); |
|
|
1025 | |
|
|
1026 | //char create_table6[100] = "CREATE index n1 on node(id)"; |
|
|
1027 | //retval = sqlite3_exec(sql_handle002,create_table6,0,0,0); |
|
|
1028 | |
|
|
1029 | char create_table10[100] = "CREATE index w2 on way(lat)"; |
|
|
1030 | //retval = sqlite3_exec(sql_handle, create_table10, 0, 0, 0); |
|
|
1031 | char create_table11[100] = "CREATE index w3 on way(lon)"; |
|
|
1032 | //retval = sqlite3_exec(sql_handle, create_table11, 0, 0, 0); |
|
|
1033 | |
|
|
1034 | |
|
|
1035 | char create_table9[100] = "CREATE index twn1 on town(country_id)"; |
|
|
1036 | //retval = sqlite3_exec(sql_handle, create_table9, 0, 0, 0); |
|
|
1037 | char create_table12[100] = "CREATE index twn2 on town(size)"; |
|
|
1038 | //retval = sqlite3_exec(sql_handle, create_table12, 0, 0, 0); |
|
|
1039 | char create_table13[100] = "CREATE index twn1 on town(lat)"; |
|
|
1040 | //retval = sqlite3_exec(sql_handle, create_table13, 0, 0, 0); |
|
|
1041 | char create_table14[100] = "CREATE index twn1 on town(lon)"; |
|
|
1042 | //retval = sqlite3_exec(sql_handle, create_table14, 0, 0, 0); |
|
|
1043 | } |
|
|
1044 | |
|
|
1045 | char* errorMessage; |
|
|
1046 | |
|
|
1047 | // WAYS and TOWNS ------- |
|
|
1048 | sqlite3_exec(sql_handle, "PRAGMA synchronous=OFF", NULL, NULL, &errorMessage); |
|
|
1049 | sqlite3_exec(sql_handle, "PRAGMA count_changes=OFF", NULL, NULL, &errorMessage); |
|
|
1050 | |
|
|
1051 | //sqlite3_exec(sql_handle, "PRAGMA journal_mode=MEMORY", NULL, NULL, &errorMessage); |
|
|
1052 | //sqlite3_exec(sql_handle, "PRAGMA journal_mode=PERSIST", NULL, NULL, &errorMessage); |
|
|
1053 | sqlite3_exec(sql_handle, "PRAGMA journal_mode=OFF", NULL, NULL, &errorMessage); |
|
|
1054 | |
|
|
1055 | sqlite3_exec(sql_handle, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
1056 | sqlite3_exec(sql_handle, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, &errorMessage); |
|
|
1057 | sqlite3_exec(sql_handle, "PRAGMA cache_size = -40000", NULL, NULL, &errorMessage); |
|
|
1058 | // WAYS and TOWNS ------- |
|
|
1059 | |
|
|
1060 | |
|
|
1061 | // NODE ------- |
|
|
1062 | sqlite3_exec(sql_handle002a, "PRAGMA synchronous=OFF", NULL, NULL, &errorMessage); |
|
|
1063 | sqlite3_exec(sql_handle002a, "PRAGMA count_changes=OFF", NULL, NULL, &errorMessage); |
|
|
1064 | |
|
|
1065 | //sqlite3_exec(sql_handle002a, "PRAGMA journal_mode=MEMORY", NULL, NULL, &errorMessage); |
|
|
1066 | //sqlite3_exec(sql_handle002a, "PRAGMA journal_mode=PERSIST", NULL, NULL, &errorMessage); |
|
|
1067 | sqlite3_exec(sql_handle002a, "PRAGMA journal_mode=OFF", NULL, NULL, &errorMessage); |
|
|
1068 | |
|
|
1069 | sqlite3_exec(sql_handle002a, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
1070 | sqlite3_exec(sql_handle002a, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, &errorMessage); |
|
|
1071 | sqlite3_exec(sql_handle002a, "PRAGMA cache_size = -80000", NULL, NULL, &errorMessage); |
|
|
1072 | |
|
|
1073 | sqlite3_exec(sql_handle002b, "PRAGMA synchronous=OFF", NULL, NULL, &errorMessage); |
|
|
1074 | sqlite3_exec(sql_handle002b, "PRAGMA count_changes=OFF", NULL, NULL, &errorMessage); |
|
|
1075 | |
|
|
1076 | //sqlite3_exec(sql_handle002b, "PRAGMA journal_mode=MEMORY", NULL, NULL, &errorMessage); |
|
|
1077 | //sqlite3_exec(sql_handle002b, "PRAGMA journal_mode=PERSIST", NULL, NULL, &errorMessage); |
|
|
1078 | sqlite3_exec(sql_handle002b, "PRAGMA journal_mode=OFF", NULL, NULL, &errorMessage); |
|
|
1079 | |
|
|
1080 | sqlite3_exec(sql_handle002b, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
1081 | sqlite3_exec(sql_handle002b, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, &errorMessage); |
|
|
1082 | sqlite3_exec(sql_handle002b, "PRAGMA cache_size = -80000", NULL, NULL, &errorMessage); |
|
|
1083 | // NODE ------- |
|
|
1084 | |
|
|
1085 | |
|
|
1086 | // NODE ------- |
|
|
1087 | sqlite3_exec(sql_handle003a, "PRAGMA synchronous=OFF", NULL, NULL, &errorMessage); |
|
|
1088 | sqlite3_exec(sql_handle003a, "PRAGMA count_changes=OFF", NULL, NULL, &errorMessage); |
|
|
1089 | |
|
|
1090 | //sqlite3_exec(sql_handle003a, "PRAGMA journal_mode=MEMORY", NULL, NULL, &errorMessage); |
|
|
1091 | //sqlite3_exec(sql_handle003a, "PRAGMA journal_mode=PERSIST", NULL, NULL, &errorMessage); |
|
|
1092 | sqlite3_exec(sql_handle003a, "PRAGMA journal_mode=OFF", NULL, NULL, &errorMessage); |
|
|
1093 | |
|
|
1094 | sqlite3_exec(sql_handle003a, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
1095 | sqlite3_exec(sql_handle003a, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, &errorMessage); |
|
|
1096 | sqlite3_exec(sql_handle003a, "PRAGMA cache_size = -80000", NULL, NULL, &errorMessage); |
|
|
1097 | |
|
|
1098 | sqlite3_exec(sql_handle003b, "PRAGMA synchronous=OFF", NULL, NULL, &errorMessage); |
|
|
1099 | sqlite3_exec(sql_handle003b, "PRAGMA count_changes=OFF", NULL, NULL, &errorMessage); |
|
|
1100 | |
|
|
1101 | //sqlite3_exec(sql_handle003b, "PRAGMA journal_mode=MEMORY", NULL, NULL, &errorMessage); |
|
|
1102 | //sqlite3_exec(sql_handle003b, "PRAGMA journal_mode=PERSIST", NULL, NULL, &errorMessage); |
|
|
1103 | sqlite3_exec(sql_handle003b, "PRAGMA journal_mode=OFF", NULL, NULL, &errorMessage); |
|
|
1104 | |
|
|
1105 | sqlite3_exec(sql_handle003b, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
1106 | sqlite3_exec(sql_handle003b, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, &errorMessage); |
|
|
1107 | sqlite3_exec(sql_handle003b, "PRAGMA cache_size = -80000", NULL, NULL, &errorMessage); |
|
|
1108 | // NODE ------- |
|
|
1109 | |
|
|
1110 | |
|
|
1111 | // WAY NODE ------- |
|
|
1112 | sqlite3_exec(sql_handle004, "PRAGMA synchronous=OFF", NULL, NULL, &errorMessage); |
|
|
1113 | sqlite3_exec(sql_handle004, "PRAGMA count_changes=OFF", NULL, NULL, &errorMessage); |
|
|
1114 | |
|
|
1115 | //sqlite3_exec(sql_handle004, "PRAGMA journal_mode=MEMORY", NULL, NULL, &errorMessage); |
|
|
1116 | //sqlite3_exec(sql_handle004, "PRAGMA journal_mode=PERSIST", NULL, NULL, &errorMessage); |
|
|
1117 | sqlite3_exec(sql_handle004, "PRAGMA journal_mode=OFF", NULL, NULL, &errorMessage); |
|
|
1118 | |
|
|
1119 | sqlite3_exec(sql_handle004, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
1120 | sqlite3_exec(sql_handle004, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, &errorMessage); |
|
|
1121 | sqlite3_exec(sql_handle004, "PRAGMA cache_size = -100000", NULL, NULL, &errorMessage); |
|
|
1122 | // WAY NODE ------- |
|
|
1123 | |
|
|
1124 | |
|
|
1125 | // WAY NODE ------- |
|
|
1126 | sqlite3_exec(sql_handle005, "PRAGMA synchronous=OFF", NULL, NULL, &errorMessage); |
|
|
1127 | sqlite3_exec(sql_handle005, "PRAGMA count_changes=OFF", NULL, NULL, &errorMessage); |
|
|
1128 | |
|
|
1129 | //sqlite3_exec(sql_handle005, "PRAGMA journal_mode=MEMORY", NULL, NULL, &errorMessage); |
|
|
1130 | //sqlite3_exec(sql_handle005, "PRAGMA journal_mode=PERSIST", NULL, NULL, &errorMessage); |
|
|
1131 | sqlite3_exec(sql_handle005, "PRAGMA journal_mode=OFF", NULL, NULL, &errorMessage); |
|
|
1132 | |
|
|
1133 | sqlite3_exec(sql_handle005, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
1134 | sqlite3_exec(sql_handle005, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, &errorMessage); |
|
|
1135 | sqlite3_exec(sql_handle005, "PRAGMA cache_size = -100000", NULL, NULL, &errorMessage); |
|
|
1136 | // WAY NODE ------- |
|
|
1137 | |
|
|
1138 | |
|
|
1139 | // WAY NODE ------- |
|
|
1140 | sqlite3_exec(sql_handle006, "PRAGMA synchronous=OFF", NULL, NULL, &errorMessage); |
|
|
1141 | sqlite3_exec(sql_handle006, "PRAGMA count_changes=OFF", NULL, NULL, &errorMessage); |
|
|
1142 | |
|
|
1143 | //sqlite3_exec(sql_handle006, "PRAGMA journal_mode=MEMORY", NULL, NULL, &errorMessage); |
|
|
1144 | //sqlite3_exec(sql_handle006, "PRAGMA journal_mode=PERSIST", NULL, NULL, &errorMessage); |
|
|
1145 | sqlite3_exec(sql_handle006, "PRAGMA journal_mode=OFF", NULL, NULL, &errorMessage); |
|
|
1146 | |
|
|
1147 | sqlite3_exec(sql_handle006, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
1148 | sqlite3_exec(sql_handle006, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, &errorMessage); |
|
|
1149 | sqlite3_exec(sql_handle006, "PRAGMA cache_size = -100000", NULL, NULL, &errorMessage); |
|
|
1150 | // WAY NODE ------- |
|
|
1151 | |
|
|
1152 | |
|
|
1153 | // WAY NODE ------- |
|
|
1154 | sqlite3_exec(sql_handle007, "PRAGMA synchronous=OFF", NULL, NULL, &errorMessage); |
|
|
1155 | sqlite3_exec(sql_handle007, "PRAGMA count_changes=OFF", NULL, NULL, &errorMessage); |
|
|
1156 | |
|
|
1157 | //sqlite3_exec(sql_handle007, "PRAGMA journal_mode=MEMORY", NULL, NULL, &errorMessage); |
|
|
1158 | //sqlite3_exec(sql_handle007, "PRAGMA journal_mode=PERSIST", NULL, NULL, &errorMessage); |
|
|
1159 | sqlite3_exec(sql_handle007, "PRAGMA journal_mode=OFF", NULL, NULL, &errorMessage); |
|
|
1160 | |
|
|
1161 | sqlite3_exec(sql_handle007, "PRAGMA temp_store=MEMORY", NULL, NULL, &errorMessage); |
|
|
1162 | sqlite3_exec(sql_handle007, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, &errorMessage); |
|
|
1163 | sqlite3_exec(sql_handle007, "PRAGMA cache_size = -100000", NULL, NULL, &errorMessage); |
|
|
1164 | // WAY NODE ------- |
|
|
1165 | |
|
|
1166 | |
|
|
1167 | retval = sqlite3_prepare_v2(sql_handle002a, "INSERT INTO node (id, lat, lon) VALUES (?,?,?);", -1, &stmt_nodea, NULL); |
|
|
1168 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1169 | retval = sqlite3_prepare_v2(sql_handle003a, "INSERT INTO node (id, lat, lon) VALUES (?,?,?);", -1, &stmt_node__2a, NULL); |
|
|
1170 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1171 | |
|
|
1172 | retval = sqlite3_prepare_v2(sql_handle002b, "INSERT INTO node (id, lat, lon) VALUES (?,?,?);", -1, &stmt_nodeb, NULL); |
|
|
1173 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1174 | retval = sqlite3_prepare_v2(sql_handle003b, "INSERT INTO node (id, lat, lon) VALUES (?,?,?);", -1, &stmt_node__2b, NULL); |
|
|
1175 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1176 | |
|
|
1177 | //retval = sqlite3_prepare_v2(sql_handle002, "INSERT INTO nodei (id, lat, lon) VALUES (?,?,?);", -1, &stmt_nodei, NULL); |
|
|
1178 | //fprintf(stderr, "prep:%d\n", retval); |
|
|
1179 | retval = sqlite3_prepare_v2(sql_handle, "INSERT INTO way (id, name, town_id, lat, lon, name_fold, ind) VALUES (?,?,?,?,?,?,0);", -1, &stmt_way, NULL); |
|
|
1180 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1181 | retval = sqlite3_prepare_v2(sql_handle004, "INSERT INTO way_node (way_id, node_id,s) VALUES (?,?,?);", -1, &stmt_way_node, NULL); |
|
|
1182 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1183 | retval = sqlite3_prepare_v2(sql_handle005, "INSERT INTO way_node (way_id, node_id,s) VALUES (?,?,?);", -1, &stmt_way_node__2, NULL); |
|
|
1184 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1185 | retval = sqlite3_prepare_v2(sql_handle006, "INSERT INTO way_node (way_id, node_id,s) VALUES (?,?,?);", -1, &stmt_way_nodeb, NULL); |
|
|
1186 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1187 | retval = sqlite3_prepare_v2(sql_handle007, "INSERT INTO way_node (way_id, node_id,s) VALUES (?,?,?);", -1, &stmt_way_node__2b, NULL); |
|
|
1188 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1189 | |
|
|
1190 | retval = sqlite3_prepare_v2(sql_handle004, "select node_id from way_node where way_id=? order by s;", -1, &stmt_sel001, NULL); |
|
|
1191 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1192 | retval = sqlite3_prepare_v2(sql_handle005, "select node_id from way_node where way_id=? order by s;", -1, &stmt_sel001__2, NULL); |
|
|
1193 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1194 | retval = sqlite3_prepare_v2(sql_handle006, "select node_id from way_node where way_id=? order by s;", -1, &stmt_sel001b, NULL); |
|
|
1195 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1196 | retval = sqlite3_prepare_v2(sql_handle007, "select node_id from way_node where way_id=? order by s;", -1, &stmt_sel001__2b, NULL); |
|
|
1197 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1198 | |
|
|
1199 | retval = sqlite3_prepare_v2(sql_handle002a, "select lat,lon from node where id=?;", -1, &stmt_sel002a, NULL); |
|
|
1200 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1201 | retval = sqlite3_prepare_v2(sql_handle003a, "select lat,lon from node where id=?;", -1, &stmt_sel002__2a, NULL); |
|
|
1202 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1203 | |
|
|
1204 | retval = sqlite3_prepare_v2(sql_handle002b, "select lat,lon from node where id=?;", -1, &stmt_sel002b, NULL); |
|
|
1205 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1206 | retval = sqlite3_prepare_v2(sql_handle003b, "select lat,lon from node where id=?;", -1, &stmt_sel002__2b, NULL); |
|
|
1207 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1208 | |
|
|
1209 | retval = sqlite3_prepare_v2(sql_handle, "INSERT INTO town (done, id, country_id, name, size, postal, lat, lon, border_id) VALUES (0,?,?,?,?,?,?,?,?);", -1, &stmt_town, NULL); |
|
|
1210 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1211 | //retval = sqlite3_prepare_v2(sql_handle, "UPDATE way set lat=?, lon=? WHERE id=?;", -1, &stmt_way2, NULL); |
|
|
1212 | //fprintf(stderr, "prep:%d\n", retval); |
|
|
1213 | |
|
|
1214 | retval = sqlite3_prepare_v2(sql_handle, "select id,size,lat,lon,name,border_id from town where done = 0 order by size desc;", -1, &stmt_town_sel001, NULL); |
|
|
1215 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1216 | retval = sqlite3_prepare_v2(sql_handle, "update way set town_id = ? where lat >= ? and lat <= ? and lon >= ? and lon <= ? and town_id = -1;", -1, &stmt_way3, NULL); |
|
|
1217 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1218 | |
|
|
1219 | retval = sqlite3_prepare_v2(sql_handle, "select id, lat, lon from way where lat >= ? and lat <= ? and lon >= ? and lon <= ? and town_id = -1;", -1, &stmt_way3a, NULL); |
|
|
1220 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1221 | retval = sqlite3_prepare_v2(sql_handle, "update way set town_id = ? where id = ?;", -1, &stmt_way3b, NULL); |
|
|
1222 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1223 | |
|
|
1224 | retval = sqlite3_prepare_v2(sql_handle, "select count(*) from town where done = 0;", -1, &stmt_town_sel002, NULL); |
|
|
1225 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1226 | |
|
|
1227 | retval = sqlite3_prepare_v2(sql_handle, "update town set done = 1 where id = ?;", -1, &stmt_town_sel007, NULL); |
|
|
1228 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1229 | |
|
|
1230 | retval = sqlite3_prepare_v2(sql_handle, "insert into town2 (border_id, id, admin_level) values (?,?,?);", -1, &stmt_town_sel008, NULL); |
|
|
1231 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1232 | |
|
|
1233 | retval = sqlite3_prepare_v2(sql_handle, "select id, country_id, name, border_id from town order by id;", -1, &stmt_town_sel005, NULL); |
|
|
1234 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1235 | |
|
|
1236 | retval = sqlite3_prepare_v2(sql_handle, "select count(id) from town;", -1, &stmt_town_sel006, NULL); |
|
|
1237 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1238 | |
|
|
1239 | retval = sqlite3_prepare_v2(sql_handle, "insert into boundary (done, rel_id, admin_level, lat, lon, name) values (0, ?,?,?,?,?);", -1, &stmt_bd_001, NULL); |
|
|
1240 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1241 | |
|
|
1242 | retval = sqlite3_prepare_v2(sql_handle, "select rel_id, admin_level, lat, lon, name from boundary where done = 0;", -1, &stmt_bd_002, NULL); |
|
|
1243 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1244 | |
|
|
1245 | retval = sqlite3_prepare_v2(sql_handle, "update boundary set done = 1, parent_rel_id = ? where rel_id = ?;", -1, &stmt_bd_003, NULL); |
|
|
1246 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1247 | |
|
|
1248 | retval = sqlite3_prepare_v2(sql_handle, "update boundary set lat = ?, lon = ? where rel_id = ?;", -1, &stmt_bd_004, NULL); |
|
|
1249 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1250 | |
|
|
1251 | retval = sqlite3_prepare_v2(sql_handle, "select rel_id, parent_rel_id, name from boundary where rel_id = ?;", -1, &stmt_bd_005, NULL); |
|
|
1252 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1253 | |
|
|
1254 | retval = sqlite3_prepare_v2(sql_handle, "select t.id,w.lat, w.lon, w.name, t.country_id from way w left outer join town t on w.town_id=t.id where w.ind = 0 and w.name_fold like ? order by w.name_fold,w.town_id;", -1, &stmt_sel003, NULL); |
|
|
1255 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1256 | |
|
|
1257 | retval = sqlite3_prepare_v2(sql_handle, "update way set ind = ? where ind = 0 and name_fold like ?;", -1, &stmt_sel003u, NULL); |
|
|
1258 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1259 | |
|
|
1260 | retval = sqlite3_prepare_v2(sql_handle, "select t.id,w.lat, w.lon, w.name, t.country_id from way w left outer join town t on w.town_id=t.id \ |
|
|
1261 | where ind = 0 \ |
|
|
1262 | and w.name_fold not like 'a%' \ |
|
|
1263 | and w.name_fold not like 'b%' \ |
|
|
1264 | and w.name_fold not like 'c%' \ |
|
|
1265 | and w.name_fold not like 'd%' \ |
|
|
1266 | and w.name_fold not like 'e%' \ |
|
|
1267 | and w.name_fold not like 'f%' \ |
|
|
1268 | and w.name_fold not like 'g%' \ |
|
|
1269 | and w.name_fold not like 'h%' \ |
|
|
1270 | and w.name_fold not like 'i%' \ |
|
|
1271 | and w.name_fold not like 'j%' \ |
|
|
1272 | and w.name_fold not like 'k%' \ |
|
|
1273 | and w.name_fold not like 'l%' \ |
|
|
1274 | and w.name_fold not like 'm%' \ |
|
|
1275 | and w.name_fold not like 'n%' \ |
|
|
1276 | and w.name_fold not like 'o%' \ |
|
|
1277 | and w.name_fold not like 'p%' \ |
|
|
1278 | and w.name_fold not like 'q%' \ |
|
|
1279 | and w.name_fold not like 'r%' \ |
|
|
1280 | and w.name_fold not like 's%' \ |
|
|
1281 | and w.name_fold not like 't%' \ |
|
|
1282 | and w.name_fold not like 'u%' \ |
|
|
1283 | and w.name_fold not like 'v%' \ |
|
|
1284 | and w.name_fold not like 'w%' \ |
|
|
1285 | and w.name_fold not like 'x%' \ |
|
|
1286 | and w.name_fold not like 'y%' \ |
|
|
1287 | and w.name_fold not like 'z%' \ |
|
|
1288 | order by w.name_fold,w.town_id;", -1, &stmt_sel004, NULL); |
|
|
1289 | fprintf(stderr, "prep:%d\n", retval); |
|
|
1290 | |
|
|
1291 | sql_counter = 0; |
|
|
1292 | sql_counter2 = 0; |
|
|
1293 | sql_counter3 = 0; |
|
|
1294 | sql_counter4 = 0; |
|
|
1295 | #endif |
|
|
1296 | } |
|
|
1297 | |
|
|
1298 | static void usage(FILE *f) |
|
|
1299 | { |
107 | fprintf(f,"\n"); |
1300 | fprintf(f, "\n"); |
108 | fprintf(f,"maptool - parse osm textfile and converts to Navit binfile format\n\n"); |
1301 | fprintf(f, "ZANavi maptool - parse osm textfile and convert to [ZANavi] binfile format\n"); |
|
|
1302 | fprintf(f, "version: "SVN_VERSION"\n\n"); |
109 | fprintf(f,"Usage :\n"); |
1303 | fprintf(f, "Usage :\n"); |
110 | fprintf(f,"bzcat planet.osm.bz2 | maptool mymap.bin\n"); |
1304 | fprintf(f, "bzcat planet.osm.bz2 | maptool mymap.bin\n"); |
111 | fprintf(f,"Available switches:\n"); |
1305 | fprintf(f, "Available switches:\n"); |
112 | fprintf(f,"-h (--help) : this screen\n"); |
1306 | fprintf(f, "-h (--help) : this screen\n"); |
113 | fprintf(f,"-5 (--md5) : set file where to write md5 sum\n"); |
1307 | // fprintf(f, "-5 (--md5) : set file where to write md5 sum\n"); |
114 | fprintf(f,"-6 (--64bit) : set zip 64 bit compression\n"); |
1308 | fprintf(f, "-6 (--64bit) : set zip 64 bit compression\n"); |
115 | fprintf(f,"-a (--attr-debug-level) : control which data is included in the debug attribute\n"); |
1309 | fprintf(f, "-a (--attr-debug-level) : control which data is included in the debug attribute\n"); |
116 | fprintf(f,"-c (--dump-coordinates) : dump coordinates after phase 1\n"); |
1310 | // fprintf(f, "-c (--dump-coordinates) : dump coordinates after phase 1\n"); |
|
|
1311 | fprintf(f, "-X : generate country-border-ONLY map\n"); |
|
|
1312 | fprintf(f, "-Y : generate coastline-ONLY map\n"); |
|
|
1313 | fprintf(f, "-Z : output coastline-ONLY map as XML file\n"); |
117 | #ifdef HAVE_POSTGRESQL |
1314 | //#ifdef HAVE_POSTGRESQL |
118 | fprintf(f,"-d (--db) : get osm data out of a postgresql database with osm simple scheme and given connect string\n"); |
1315 | // fprintf(f," -d (--db) : get osm data out of a postgresql database with osm simple scheme and given connect string\n"); |
119 | #endif |
1316 | //#endif |
120 | fprintf(f,"-e (--end) : end at specified phase\n"); |
1317 | // fprintf(f, "-e (--end) : end at specified phase\n"); |
|
|
1318 | fprintf(f, "-g : use ./db/ as directory for SQLite db files\n"); |
|
|
1319 | fprintf(f, "-f : use ./db/ as directory for SQLite db files and SQLite temp files\n"); |
|
|
1320 | fprintf(f, "-F : specify a fixed country id for this input file\n"); |
121 | fprintf(f,"-i (--input-file) : specify the input file name (OSM), overrules default stdin\n"); |
1321 | fprintf(f, "-i (--input-file) : specify the input file name (OSM), overrules default stdin\n"); |
|
|
1322 | fprintf(f, "-j : specify number of worker threads (max. %d !!)\n", MAX_THREADS); |
122 | fprintf(f,"-k (--keep-tmpfiles) : do not delete tmp files after processing. useful to reuse them\n\n"); |
1323 | // fprintf(f, "-k (--keep-tmpfiles) : do not delete tmp files after processing. useful to reuse them\n\n"); |
123 | fprintf(f,"-N (--nodes-only) : process only nodes\n"); |
1324 | fprintf(f, "-N (--nodes-only) : process only nodes\n"); |
|
|
1325 | fprintf(f, "-n : ignore unknown types\n"); |
124 | fprintf(f,"-o (--coverage) : map every street to item coverage\n"); |
1326 | // fprintf(f, "-o (--coverage) : map every street to item coverage\n"); |
125 | fprintf(f,"-P (--protobuf) : input file is protobuf\n"); |
1327 | // fprintf(f, "-P (--protobuf) : input file is protobuf\n"); |
126 | fprintf(f,"-r (--rule-file) : read mapping rules from specified file\n"); |
1328 | fprintf(f, "-r (--rule-file) : read mapping rules from specified file\n"); |
127 | fprintf(f,"-s (--start) : start at specified phase\n"); |
1329 | // fprintf(f, "-s (--start) : start at specified phase\n"); |
128 | fprintf(f,"-S (--slice-size) : defines the amount of memory to use, in bytes. Default is 1GB\n"); |
1330 | fprintf(f, "-S (--slice-size) : defines the amount of memory to use, in bytes. Default is 1GB\n"); |
|
|
1331 | fprintf(f, "-v : verbose mode\n"); |
129 | fprintf(f,"-w (--dedupe-ways) : ensure no duplicate ways or nodes. useful when using several input files\n"); |
1332 | fprintf(f, "-w (--dedupe-ways) : ensure no duplicate ways or nodes. useful when using several input files\n"); |
130 | fprintf(f,"-W (--ways-only) : process only ways\n"); |
1333 | fprintf(f, "-W (--ways-only) : process only ways\n"); |
131 | fprintf(f,"-z (--compression-level) : set the compression level\n"); |
1334 | fprintf(f, "-z (--compression-level) : set the compression level\n"); |
132 | |
1335 | fprintf(f, "-U (--unknown-country) : add objects with unknown country to index\n"); |
|
|
1336 | |
133 | exit(1); |
1337 | exit(1); |
134 | } |
1338 | } |
135 | |
1339 | |
|
|
1340 | void *sql_thread(void *ptr) |
|
|
1341 | { |
|
|
1342 | // this call never returns!! |
|
|
1343 | #ifdef MAPTOOL_USE_SQL |
|
|
1344 | sqlite3async_run(); |
|
|
1345 | #endif |
|
|
1346 | } |
|
|
1347 | |
|
|
1348 | void *multi_threaded_phase_001(void *ptr) |
|
|
1349 | { |
|
|
1350 | struct phase_001_thread_var *vars = (struct phase_001_thread_var*) ptr; |
|
|
1351 | |
|
|
1352 | long long i_x_slice_base = vars->count * slice_size; |
|
|
1353 | |
|
|
1354 | fprintf(stderr, "[THREAD] #%d load buffer\n", vars->thread_num); |
|
|
1355 | load_buffer("coords.tmp", &node_buffer[vars->thread_num], i_x_slice_base, slice_size); |
|
|
1356 | fprintf(stderr, "[THREAD] #%d load buffer ready\n", vars->thread_num); |
|
|
1357 | |
|
|
1358 | // try to fillup the node_hash again |
|
|
1359 | fprintf(stderr, "[THREAD] #%d fill hash node\n", vars->thread_num); |
|
|
1360 | fill_hash_node(vars->thread_num); |
|
|
1361 | fprintf(stderr, "[THREAD] #%d fill hash node ready\n", vars->thread_num); |
|
|
1362 | |
|
|
1363 | fprintf(stderr, "[THREAD] #%d ref ways\n", vars->thread_num); |
|
|
1364 | ref_ways(vars->file1, vars->thread_num); // --> this just sets "ref_way" count, of nodes (and takes hours of time!!) |
|
|
1365 | fprintf(stderr, "[THREAD] #%d ref ways ready\n", vars->thread_num); |
|
|
1366 | |
|
|
1367 | fprintf(stderr, "[THREAD] #%d save buffer\n", vars->thread_num); |
|
|
1368 | save_buffer("coords.tmp", &node_buffer[vars->thread_num], i_x_slice_base); // this saves the "ref_way" count back to file |
|
|
1369 | fprintf(stderr, "[THREAD] #%d save buffer ready\n", vars->thread_num); |
|
|
1370 | |
|
|
1371 | thread_is_working_[vars->thread_num] = 0; |
|
|
1372 | fprintf(stderr, "[THREAD] #%d ready\n", vars->thread_num); |
|
|
1373 | } |
|
|
1374 | |
136 | int main(int argc, char **argv) |
1375 | int main(int argc, char **argv) |
137 | { |
1376 | { |
138 | FILE *ways=NULL,*ways_split=NULL,*ways_split_index=NULL,*nodes=NULL,*turn_restrictions=NULL,*graph=NULL,*coastline=NULL,*tilesdir,*coords,*relations=NULL,*boundaries=NULL; |
1377 | FILE *ways = NULL, *ways_split = NULL, *ways_split_index = NULL, *towns = NULL, *nodes = NULL; |
|
|
1378 | FILE *turn_restrictions = NULL, *graph = NULL, *coastline = NULL; |
|
|
1379 | FILE *tilesdir, *coords, *relations = NULL, *boundaries = NULL, *relations_riverbank = NULL; |
139 | FILE *files[10]; |
1380 | FILE *files[10]; |
140 | FILE *references[10]; |
1381 | FILE *references[10]; |
141 | |
1382 | |
|
|
1383 | // ------------------------------------------- |
|
|
1384 | // initialize gthreads |
|
|
1385 | g_thread_init(NULL); |
|
|
1386 | fprintf(stderr, "glib thread support=%d\n", g_thread_supported()); |
|
|
1387 | // ------------------------------------------- |
|
|
1388 | |
|
|
1389 | time(&global_start_tt); |
|
|
1390 | |
|
|
1391 | linguistics_init(); |
|
|
1392 | |
142 | #if 0 |
1393 | #if 0 |
143 | char *map=g_strdup(attrmap); |
1394 | char *map=g_strdup(attrmap); |
144 | #endif |
1395 | #endif |
|
|
1396 | |
|
|
1397 | int jk; |
|
|
1398 | for (jk = 0; jk < max_threads; jk++) |
|
|
1399 | { |
|
|
1400 | node_buffer[jk].malloced_step = 64 * 1024 * 1024; // extend in 64MByte steps |
|
|
1401 | node_buffer[jk].malloced = 0; |
|
|
1402 | node_buffer[jk].base = NULL; |
|
|
1403 | node_buffer[jk].size = 0; |
|
|
1404 | } |
|
|
1405 | |
145 | int zipnum,c,start=1,end=99,dump_coordinates=0; |
1406 | int zipnum, c, start = 1, end = 99, dump_coordinates = 0; |
146 | int keep_tmpfiles=0; |
1407 | int keep_tmpfiles = 0; |
147 | int process_nodes=1, process_ways=1, process_relations=1; |
1408 | int process_nodes = 1, process_ways = 1, process_relations = 1; |
148 | #ifdef HAVE_ZLIB |
1409 | #ifdef HAVE_ZLIB |
149 | int compression_level=9; |
1410 | int compression_level = 9; |
150 | #else |
1411 | #else |
151 | int compression_level=0; |
1412 | int compression_level = 0; |
152 | #endif |
1413 | #endif |
153 | int zip64=0; |
1414 | int zip64 = 0; |
154 | int output=0; |
1415 | int output = 0; |
155 | int input=0; |
1416 | int input = 0; |
156 | int protobuf=0; |
1417 | int protobuf = 0; |
157 | int f,pos; |
1418 | int f, pos; |
158 | char *result,*optarg_cp,*attr_name,*attr_value; |
1419 | char *result, *optarg_cp, *attr_name, *attr_value; |
159 | char *protobufdb=NULL,*protobufdb_operation=NULL,*md5file=NULL; |
1420 | char *protobufdb = NULL, *protobufdb_operation = NULL, *md5file = NULL; |
|
|
1421 | GList *boundaries_list = NULL; |
|
|
1422 | |
|
|
1423 | diff_tt = 0; |
|
|
1424 | diff2_tt = 0; |
|
|
1425 | |
|
|
1426 | use_global_fixed_country_id = 0; |
|
|
1427 | |
160 | #ifdef HAVE_POSTGRESQL |
1428 | #ifdef HAVE_POSTGRESQL |
161 | char *dbstr=NULL; |
1429 | char *dbstr=NULL; |
162 | #endif |
1430 | #endif |
163 | |
1431 | |
164 | FILE* input_file = stdin; // input data |
1432 | FILE* input_file = stdin; // input data |
165 | |
1433 | |
166 | FILE* rule_file = NULL; // external rule file |
1434 | FILE* rule_file = NULL; // external rule file |
167 | |
1435 | |
168 | struct attr *attrs[10]; |
1436 | struct attr *attrs[10]; |
169 | GList *map_handles=NULL; |
1437 | GList *map_handles = NULL; |
170 | struct map *handle; |
1438 | struct map *handle; |
|
|
1439 | struct maptool_osm osm; |
171 | #if 0 |
1440 | #if 0 |
|
|
1441 | char *suffixes[]= |
172 | char *suffixes[]={"m0l0", "m0l1","m0l2","m0l3","m0l4","m0l5","m0l6"}; |
1442 | { "m0l0", "m0l1","m0l2","m0l3","m0l4","m0l5","m0l6"}; |
173 | char *suffixes[]={"m","r"}; |
1443 | char *suffixes[]= |
|
|
1444 | { "m","r"}; |
174 | #else |
1445 | #else |
175 | char *suffixes[]={""}; |
1446 | char *suffixes[] = { "" }; |
176 | #endif |
1447 | #endif |
177 | char *suffix=suffixes[0]; |
1448 | char *suffix = suffixes[0]; |
178 | |
1449 | |
179 | int suffix_count=sizeof(suffixes)/sizeof(char *); |
1450 | int suffix_count = sizeof(suffixes) / sizeof(char *); |
180 | int i; |
1451 | int i; |
181 | char r[] ="r"; /* Used to make compiler happy due to Bug 35903 in gcc */ |
1452 | char r[] = "r"; /* Used to make compiler happy due to Bug 35903 in gcc */ |
182 | main_init(argv[0]); |
1453 | main_init(argv[0]); |
183 | struct zip_info *zip_info=NULL; |
1454 | struct zip_info *zip_info = NULL; |
184 | int suffix_start=0; |
1455 | int suffix_start = 0; |
185 | char *timestamp=current_to_iso8601(); |
1456 | char *timestamp = current_to_iso8601(); |
186 | char *url=NULL; |
1457 | char *url = NULL; |
187 | #ifndef HAVE_GLIB |
1458 | #ifndef HAVE_GLIB |
188 | _g_slice_thread_init_nomessage(); |
1459 | // _g_slice_thread_init_nomessage(); |
189 | #endif |
1460 | #endif |
190 | |
1461 | |
|
|
1462 | osm.boundaries = NULL; |
|
|
1463 | osm.relations_riverbank = NULL; |
|
|
1464 | osm.turn_restrictions = NULL; |
|
|
1465 | osm.nodes = NULL; |
|
|
1466 | osm.ways = NULL; |
|
|
1467 | osm.line2poi = NULL; |
|
|
1468 | osm.poly2poi = NULL; |
|
|
1469 | osm.towns = NULL; |
|
|
1470 | osm.ways_with_coords = NULL; |
|
|
1471 | |
|
|
1472 | // init the ling. hashes!! |
|
|
1473 | linguistics_init(); |
|
|
1474 | |
191 | while (1) { |
1475 | while (1) |
|
|
1476 | { |
192 | #if 0 |
1477 | #if 0 |
193 | int this_option_optind = optind ? optind : 1; |
1478 | int this_option_optind = optind ? optind : 1; |
194 | #endif |
1479 | #endif |
195 | int option_index = 0; |
1480 | int option_index = 0; |
196 | static struct option long_options[] = { |
1481 | static struct option long_options[] = { { "md5", 1, 0, '5' }, { "64bit", 0, 0, '6' }, { "attr-debug-level", 1, 0, 'a' }, { "binfile", 0, 0, 'b' }, { "compression-level", 1, 0, 'z' }, |
197 | {"md5", 1, 0, '5'}, |
|
|
198 | {"64bit", 0, 0, '6'}, |
|
|
199 | {"attr-debug-level", 1, 0, 'a'}, |
|
|
200 | {"binfile", 0, 0, 'b'}, |
|
|
201 | {"compression-level", 1, 0, 'z'}, |
|
|
202 | #ifdef HAVE_POSTGRESQL |
1482 | #ifdef HAVE_POSTGRESQL |
203 | {"db", 1, 0, 'd'}, |
1483 | { "db", 1, 0, 'd'}, |
204 | #endif |
1484 | #endif |
205 | {"dedupe-ways", 0, 0, 'w'}, |
1485 | { "dedupe-ways", 0, 0, 'w' }, { "dump", 0, 0, 'D' }, { "dump-coordinates", 0, 0, 'c' }, { "end", 1, 0, 'e' }, { "help", 0, 0, 'h' }, { "keep-tmpfiles", 0, 0, 'k' }, { "nodes-only", 0, 0, 'N' }, { "map", 1, 0, 'm' }, { "plugin", 1, 0, 'p' }, |
206 | {"dump", 0, 0, 'D'}, |
|
|
207 | {"dump-coordinates", 0, 0, 'c'}, |
|
|
208 | {"end", 1, 0, 'e'}, |
|
|
209 | {"help", 0, 0, 'h'}, |
|
|
210 | {"keep-tmpfiles", 0, 0, 'k'}, |
|
|
211 | {"nodes-only", 0, 0, 'N'}, |
|
|
212 | {"map", 1, 0, 'm'}, |
|
|
213 | {"plugin", 1, 0, 'p'}, |
|
|
214 | {"protobuf", 0, 0, 'P'}, |
1486 | // { "protobuf", 0, 0, 'P' }, |
215 | {"start", 1, 0, 's'}, |
1487 | { "start", 1, 0, 's' }, { "input-file", 1, 0, 'i' }, { "rule-file", 1, 0, 'r' }, { "ignore-unknown", 0, 0, 'n' }, { "url", 1, 0, 'u' }, { "ways-only", 0, 0, 'W' }, { "slice-size", 1, 0, 'S' }, { "unknown-country", 0, 0, 'U' }, { 0, 0, 0, 0 } }; |
216 | {"input-file", 1, 0, 'i'}, |
|
|
217 | {"rule-file", 1, 0, 'r'}, |
|
|
218 | {"ignore-unknown", 0, 0, 'n'}, |
|
|
219 | {"url", 1, 0, 'u'}, |
|
|
220 | {"ways-only", 0, 0, 'W'}, |
|
|
221 | {"slice-size", 1, 0, 'S'}, |
|
|
222 | {0, 0, 0, 0} |
|
|
223 | }; |
|
|
224 | c = getopt_long (argc, argv, "5:6B:DNO:PWS:a:bc" |
1488 | c = getopt_long(argc, argv, "5:6B:DF:NO:PWS:a:bc" |
225 | #ifdef HAVE_POSTGRESQL |
1489 | #ifdef HAVE_POSTGRESQL |
226 | "d:" |
1490 | "d:" |
227 | #endif |
1491 | #endif |
228 | "e:hi:knm:p:r:s:wu:z:", long_options, &option_index); |
1492 | "e:fghj:i:knm:p:r:s:wvu:z:UXYZ", long_options, &option_index); |
229 | if (c == -1) |
1493 | if (c == -1) |
|
|
1494 | { |
230 | break; |
1495 | break; |
|
|
1496 | } |
|
|
1497 | |
231 | switch (c) { |
1498 | switch (c) |
|
|
1499 | { |
232 | case '5': |
1500 | case '5': |
233 | md5file=optarg; |
1501 | md5file = optarg; |
234 | break; |
1502 | break; |
235 | case '6': |
1503 | case '6': |
|
|
1504 | fprintf(stderr, "I will generate a ZIP64 map\n"); |
236 | zip64=1; |
1505 | zip64 = 1; |
237 | break; |
1506 | break; |
238 | case 'B': |
1507 | //case 'B': |
239 | protobufdb=optarg; |
1508 | // protobufdb = optarg; |
240 | break; |
1509 | // break; |
241 | case 'D': |
1510 | case 'D': |
242 | output=1; |
1511 | output = 1; |
243 | break; |
1512 | break; |
244 | case 'N': |
1513 | case 'N': |
245 | process_ways=0; |
1514 | process_ways = 0; |
246 | break; |
1515 | break; |
247 | case 'R': |
1516 | case 'R': |
248 | process_relations=0; |
1517 | process_relations = 0; |
249 | break; |
1518 | break; |
250 | case 'O': |
1519 | //case 'O': |
251 | protobufdb_operation=optarg; |
1520 | // protobufdb_operation = optarg; |
252 | output=1; |
1521 | // output = 1; |
253 | break; |
1522 | // break; |
254 | case 'P': |
1523 | //case 'P': |
255 | protobuf=1; |
1524 | // protobuf = 1; |
256 | break; |
1525 | // break; |
257 | case 'S': |
1526 | case 'S': |
258 | slice_size=atoll(optarg); |
1527 | slice_size = atoll(optarg); |
259 | break; |
1528 | break; |
260 | case 'W': |
1529 | case 'W': |
261 | process_nodes=0; |
1530 | process_nodes = 0; |
262 | break; |
1531 | break; |
|
|
1532 | case 'U': |
|
|
1533 | fprintf(stderr, "Towns in UNKNOWN Country will be added to index\n"); |
|
|
1534 | unknown_country = 1; |
|
|
1535 | break; |
|
|
1536 | case 'X': |
|
|
1537 | fprintf(stderr, "I will GENERATE a country-border-only map\n"); |
|
|
1538 | border_only_map = 1; |
|
|
1539 | break; |
|
|
1540 | case 'Y': |
|
|
1541 | fprintf(stderr, "I will GENERATE a coastline-only map\n"); |
|
|
1542 | coastline_only_map = 1; |
|
|
1543 | break; |
|
|
1544 | case 'Z': |
|
|
1545 | fprintf(stderr, "I will output a country-border-only map as XML file\n"); |
|
|
1546 | border_only_map = 1; |
|
|
1547 | border_only_map_as_xml = 1; |
|
|
1548 | |
|
|
1549 | FILE *out_ = tempfile("", "borders.xml", 1); |
|
|
1550 | fprintf(out_, "<?xml version='1.0' encoding='UTF-8'?>\n"); |
|
|
1551 | fprintf(out_, "<osm version=\"0.6\" generator=\"ZANavi maptool\">\n"); |
|
|
1552 | fclose(out_); |
|
|
1553 | |
|
|
1554 | break; |
263 | case 'a': |
1555 | case 'a': |
264 | attr_debug_level=atoi(optarg); |
1556 | attr_debug_level = atoi(optarg); |
265 | break; |
1557 | break; |
|
|
1558 | case 'j': |
|
|
1559 | threads = atoi(optarg); |
|
|
1560 | if (threads > MAX_THREADS) |
|
|
1561 | { |
|
|
1562 | threads = MAX_THREADS; |
|
|
1563 | } |
|
|
1564 | else if (threads < 1) |
|
|
1565 | { |
|
|
1566 | threads = 1; |
|
|
1567 | } |
|
|
1568 | fprintf(stderr, "using %d THREADS\n", threads); |
|
|
1569 | break; |
266 | case 'b': |
1570 | case 'b': |
267 | input=1; |
1571 | input = 1; |
268 | break; |
1572 | break; |
269 | case 'c': |
1573 | case 'c': |
270 | dump_coordinates=1; |
1574 | dump_coordinates = 1; |
271 | break; |
1575 | break; |
272 | #ifdef HAVE_POSTGRESQL |
1576 | #ifdef HAVE_POSTGRESQL |
273 | case 'd': |
1577 | case 'd': |
274 | dbstr=optarg; |
1578 | dbstr=optarg; |
275 | break; |
1579 | break; |
276 | #endif |
1580 | #endif |
277 | case 'e': |
1581 | case 'e': |
278 | end=atoi(optarg); |
1582 | end = atoi(optarg); |
279 | break; |
1583 | break; |
|
|
1584 | case 'g': |
|
|
1585 | sqlite_db_dir = sqlite_db_dir_extra; |
|
|
1586 | sqlite_temp_dir = 0; |
|
|
1587 | break; |
|
|
1588 | case 'f': |
|
|
1589 | sqlite_db_dir = sqlite_db_dir_extra; |
|
|
1590 | sqlite_temp_dir = 1; |
|
|
1591 | break; |
280 | case 'h': |
1592 | case 'h': |
281 | usage(stdout); |
1593 | usage(stdout); |
282 | break; |
1594 | break; |
283 | case 'm': |
1595 | case 'm': |
284 | optarg_cp=g_strdup(optarg); |
1596 | optarg_cp = g_strdup(optarg); |
285 | pos=0; |
1597 | pos = 0; |
286 | i=0; |
1598 | i = 0; |
287 | attr_name=g_strdup(optarg); |
1599 | attr_name = g_strdup(optarg); |
288 | attr_value=g_strdup(optarg); |
1600 | attr_value = g_strdup(optarg); |
289 | while (i < 9 && attr_from_line(optarg_cp, NULL, &pos, attr_value, attr_name)) { |
1601 | while (i < 9 && attr_from_line(optarg_cp, NULL, &pos, attr_value, attr_name)) |
|
|
1602 | { |
290 | attrs[i]=attr_new_from_text(attr_name,attr_value); |
1603 | attrs[i] = attr_new_from_text(attr_name, attr_value); |
291 | if (attrs[i]) { |
1604 | if (attrs[i]) |
|
|
1605 | { |
292 | i++; |
1606 | i++; |
|
|
1607 | } |
293 | } else { |
1608 | else |
|
|
1609 | { |
294 | fprintf(stderr,"Failed to convert %s=%s to attribute\n",attr_name,attr_value); |
1610 | fprintf(stderr, "Failed to convert %s=%s to attribute\n", attr_name, attr_value); |
|
|
1611 | } |
|
|
1612 | attr_value = g_strdup(optarg); |
295 | } |
1613 | } |
296 | attr_value=g_strdup(optarg); |
|
|
297 | } |
|
|
298 | attrs[i++]=NULL; |
1614 | attrs[i++] = NULL; |
299 | g_free(attr_value); |
1615 | g_free(attr_value); |
300 | g_free(optarg_cp); |
1616 | g_free(optarg_cp); |
301 | handle=map_new(NULL, attrs); |
1617 | handle = map_new(NULL, attrs); |
302 | if (! handle) { |
1618 | if (!handle) |
|
|
1619 | { |
303 | fprintf(stderr,"Failed to create map from attributes\n"); |
1620 | fprintf(stderr, "Failed to create map from attributes\n"); |
304 | exit(1); |
1621 | exit(1); |
305 | } |
1622 | } |
306 | map_handles=g_list_append(map_handles,handle); |
1623 | map_handles = g_list_append(map_handles, handle); |
307 | break; |
1624 | break; |
308 | case 'n': |
1625 | case 'n': |
309 | fprintf(stderr,"I will IGNORE unknown types\n"); |
1626 | fprintf(stderr, "I will IGNORE unknown types\n"); |
310 | ignore_unkown=1; |
1627 | ignore_unkown = 1; |
311 | break; |
1628 | break; |
312 | case 'k': |
1629 | case 'k': |
313 | fprintf(stderr,"I will KEEP tmp files\n"); |
1630 | fprintf(stderr, "I will KEEP tmp files\n"); |
314 | keep_tmpfiles=1; |
1631 | keep_tmpfiles = 1; |
315 | break; |
1632 | break; |
316 | case 'p': |
1633 | case 'p': |
317 | add_plugin(optarg); |
1634 | add_plugin(optarg); |
318 | break; |
1635 | break; |
319 | case 's': |
1636 | case 's': |
320 | start=atoi(optarg); |
1637 | start = atoi(optarg); |
321 | break; |
1638 | break; |
322 | case 'w': |
1639 | case 'w': |
323 | dedupe_ways_hash=g_hash_table_new(NULL, NULL); |
1640 | // dedupe_ways_hash = g_hash_table_new(NULL, NULL); |
324 | break; |
1641 | break; |
|
|
1642 | case 'v': |
|
|
1643 | verbose_mode = 1; |
|
|
1644 | break; |
|
|
1645 | case 'F': |
|
|
1646 | use_global_fixed_country_id = 1; |
|
|
1647 | global_fixed_country_id = atoi(optarg); |
|
|
1648 | fprintf(stderr, "ASSUME map is country id: %d\n", global_fixed_country_id); |
|
|
1649 | break; |
325 | case 'i': |
1650 | case 'i': |
326 | input_file = fopen( optarg, "r" ); |
1651 | input_file = fopen(optarg, "r"); |
327 | if ( input_file == NULL ) |
1652 | if (input_file == NULL) |
|
|
1653 | { |
|
|
1654 | fprintf(stderr, "\nInput file (%s) not found\n", optarg); |
|
|
1655 | exit(-1); |
|
|
1656 | } |
|
|
1657 | break; |
|
|
1658 | case 'r': |
|
|
1659 | rule_file = fopen(optarg, "r"); |
|
|
1660 | if (rule_file == NULL) |
|
|
1661 | { |
|
|
1662 | fprintf(stderr, "\nRule file (%s) not found\n", optarg); |
|
|
1663 | exit(-1); |
|
|
1664 | } |
|
|
1665 | break; |
|
|
1666 | case 'u': |
|
|
1667 | url = optarg; |
|
|
1668 | break; |
|
|
1669 | #ifdef HAVE_ZLIB |
|
|
1670 | case 'z': |
|
|
1671 | compression_level=atoi(optarg); |
|
|
1672 | break; |
|
|
1673 | #endif |
|
|
1674 | case '?': |
|
|
1675 | usage(stderr); |
|
|
1676 | break; |
|
|
1677 | default: |
|
|
1678 | fprintf(stderr, "c=%d\n", c); |
|
|
1679 | } |
|
|
1680 | |
|
|
1681 | } |
|
|
1682 | |
|
|
1683 | if (optind != argc - (output == 1 ? 0 : 1)) |
|
|
1684 | { |
|
|
1685 | usage(stderr); |
|
|
1686 | } |
|
|
1687 | result = argv[optind]; |
|
|
1688 | |
|
|
1689 | sig_alrm(0); |
|
|
1690 | |
|
|
1691 | // initialize plugins and OSM mappings |
|
|
1692 | maptool_init(rule_file); |
|
|
1693 | //if (protobufdb_operation) |
|
|
1694 | //{ |
|
|
1695 | // osm_protobufdb_load(input_file, protobufdb); |
|
|
1696 | // return 0; |
|
|
1697 | //} |
|
|
1698 | |
|
|
1699 | unlink(g_strdup_printf("%stemp_data.db",sqlite_db_dir)); |
|
|
1700 | unlink("temp_data.db"); |
|
|
1701 | |
|
|
1702 | unlink(g_strdup_printf("%stemp_data002a.db",sqlite_db_dir)); |
|
|
1703 | unlink(g_strdup_printf("%stemp_data003a.db",sqlite_db_dir)); |
|
|
1704 | unlink(g_strdup_printf("%stemp_data002b.db",sqlite_db_dir)); |
|
|
1705 | unlink(g_strdup_printf("%stemp_data003b.db",sqlite_db_dir)); |
|
|
1706 | unlink("temp_data002a.db"); |
|
|
1707 | unlink("temp_data003a.db"); |
|
|
1708 | unlink("temp_data002b.db"); |
|
|
1709 | unlink("temp_data003b.db"); |
|
|
1710 | |
|
|
1711 | unlink(g_strdup_printf("%stemp_data004.db",sqlite_db_dir)); |
|
|
1712 | unlink(g_strdup_printf("%stemp_data005.db",sqlite_db_dir)); |
|
|
1713 | unlink(g_strdup_printf("%stemp_data006.db",sqlite_db_dir)); |
|
|
1714 | unlink(g_strdup_printf("%stemp_data007.db",sqlite_db_dir)); |
|
|
1715 | unlink("temp_data004.db"); |
|
|
1716 | unlink("temp_data005.db"); |
|
|
1717 | unlink("temp_data006.db"); |
|
|
1718 | unlink("temp_data007.db"); |
|
|
1719 | |
|
|
1720 | sql_db_open(); |
|
|
1721 | sql_db_init(1); |
|
|
1722 | |
|
|
1723 | unlink("coords.tmp"); |
|
|
1724 | if (process_ways) |
|
|
1725 | { |
|
|
1726 | ways = tempfile(suffix, "ways", 1); |
|
|
1727 | } |
|
|
1728 | if (process_nodes) |
|
|
1729 | { |
|
|
1730 | nodes = tempfile(suffix, "nodes", 1); |
|
|
1731 | towns = tempfile(suffix, "towns", 1); |
|
|
1732 | } |
|
|
1733 | if (process_ways && process_nodes) |
|
|
1734 | { |
|
|
1735 | turn_restrictions = tempfile(suffix, "turn_restrictions", 1); |
|
|
1736 | } |
|
|
1737 | if (process_relations) |
|
|
1738 | { |
|
|
1739 | boundaries = tempfile(suffix, "boundaries", 1); |
|
|
1740 | relations_riverbank = tempfile(suffix, "relations_riverbank", 1); |
|
|
1741 | } |
|
|
1742 | |
|
|
1743 | osm.ways_with_coords = tempfile(suffix, "ways_with_coords", 1); |
|
|
1744 | |
|
|
1745 | phase = 1; |
|
|
1746 | fprintf(stderr, "PROGRESS: Phase 1: collecting data\n"); |
|
|
1747 | osm.ways = ways; |
|
|
1748 | osm.nodes = nodes; |
|
|
1749 | osm.towns = towns; |
|
|
1750 | osm.turn_restrictions = turn_restrictions; |
|
|
1751 | osm.boundaries = boundaries; |
|
|
1752 | osm.relations_riverbank = relations_riverbank; |
|
|
1753 | |
|
|
1754 | init_node_hash(max_threads, 1); // initialze to maximum array size |
|
|
1755 | |
|
|
1756 | if (map_handles) |
|
|
1757 | { |
|
|
1758 | if (verbose_mode) |
|
|
1759 | fprintf(stderr, "**phase1:A**\n"); |
|
|
1760 | GList *l; |
|
|
1761 | phase1_map(map_handles, ways, nodes); |
|
|
1762 | l = map_handles; |
|
|
1763 | while (l) |
|
|
1764 | { |
|
|
1765 | map_destroy(l->data); |
|
|
1766 | l = g_list_next(l); |
|
|
1767 | } |
|
|
1768 | } |
|
|
1769 | else if (protobuf) |
|
|
1770 | { |
|
|
1771 | if (verbose_mode) |
|
|
1772 | fprintf(stderr, "**phase1:B**\n"); |
|
|
1773 | // ---obsolete--- // map_collect_data_osm_protobuf(input_file, &osm); |
|
|
1774 | } |
|
|
1775 | else |
|
|
1776 | { |
|
|
1777 | time(&start_tt); |
|
|
1778 | |
|
|
1779 | if (verbose_mode) |
|
|
1780 | fprintf(stderr, "**phase1:C**\n"); |
|
|
1781 | |
|
|
1782 | // ---------------- MAIN routine to read in data from OSM !!! ---------- |
|
|
1783 | // ---------------- MAIN routine to read in data from OSM !!! ---------- |
|
|
1784 | // ---------------- MAIN routine to read in data from OSM !!! ---------- |
|
|
1785 | // ---------------- MAIN routine to read in data from OSM !!! ---------- |
|
|
1786 | // ---------------- MAIN routine to read in data from OSM !!! ---------- |
|
|
1787 | // ---------------- MAIN routine to read in data from OSM !!! ---------- |
|
|
1788 | |
|
|
1789 | ways_processed_count = 0; |
|
|
1790 | map_collect_data_osm(input_file, &osm); |
|
|
1791 | |
|
|
1792 | // ---------------- MAIN routine to read in data from OSM !!! ---------- |
|
|
1793 | // ---------------- MAIN routine to read in data from OSM !!! ---------- |
|
|
1794 | // ---------------- MAIN routine to read in data from OSM !!! ---------- |
|
|
1795 | // ---------------- MAIN routine to read in data from OSM !!! ---------- |
|
|
1796 | // ---------------- MAIN routine to read in data from OSM !!! ---------- |
|
|
1797 | // ---------------- MAIN routine to read in data from OSM !!! ---------- |
|
|
1798 | |
|
|
1799 | |
|
|
1800 | time(&end_tt); |
|
|
1801 | diff_tt = difftime(end_tt, start_tt); |
|
|
1802 | char outstring[200]; |
|
|
1803 | convert_to_human_time(diff_tt, outstring); |
|
|
1804 | fprintf(stderr, "-RUNTIME-PHASE1: %s\n", outstring); |
|
|
1805 | } |
|
|
1806 | |
|
|
1807 | sql_db_close(); |
|
|
1808 | |
|
|
1809 | //fprintf(stderr, "slices=====%d\n", slices); |
|
|
1810 | |
|
|
1811 | //if (slices) |
|
|
1812 | //{ |
|
|
1813 | // THREADS ----------- |
|
|
1814 | cur_thread_num = 0; |
|
|
1815 | // GThread *thread_[threads]; |
|
|
1816 | pthread_t thread_[threads]; |
|
|
1817 | int iret_[threads]; |
|
|
1818 | FILE *ways_file[threads]; |
|
|
1819 | struct phase_001_thread_var vars[threads]; |
|
|
1820 | // THREADS ----------- |
|
|
1821 | |
|
|
1822 | for (i = 0; i < threads; i++) |
|
|
1823 | { |
|
|
1824 | thread_is_working_[i] = 0; |
|
|
1825 | ways_file[i] = NULL; |
|
|
1826 | } |
|
|
1827 | |
|
|
1828 | init_node_hash(threads, 0); |
|
|
1829 | |
|
|
1830 | fprintf(stderr, "%d slices\n", slices); |
|
|
1831 | |
|
|
1832 | flush_nodes(1, cur_thread_num); // flush remains to "coords.tmp" from "osm_end_node" |
|
|
1833 | |
|
|
1834 | // fprintf(stderr, "slices==2==%d\n", slices); |
|
|
1835 | |
|
|
1836 | long long i_x_slice_size; |
|
|
1837 | // for (i = slices - 2; i >= 0; i--) |
|
|
1838 | for (i = 0; i < slices; i++) |
|
|
1839 | { |
|
|
1840 | if (verbose_mode) |
|
|
1841 | { |
|
|
1842 | fprintf(stderr, "thread #%d\n", cur_thread_num); |
|
|
1843 | } |
|
|
1844 | // fprintf(stderr, "slice %d of %d\n", slices - i - 1, slices - 1); |
|
|
1845 | fprintf(stderr, "slice %d of %d\n", i + 1, slices); |
|
|
1846 | |
|
|
1847 | if (thread_is_working_[cur_thread_num] == 1) |
|
|
1848 | { |
|
|
1849 | // find next free thread |
|
|
1850 | // if all threads working, then return any thread num |
|
|
1851 | int ij; |
|
|
1852 | for (ij = 0; ij < threads; ij++) |
328 | { |
1853 | { |
329 | fprintf( stderr, "\nInput file (%s) not found\n", optarg ); |
1854 | if ((cur_thread_num + ij + 1) <= threads) |
330 | exit( -1 ); |
|
|
331 | } |
|
|
332 | break; |
|
|
333 | case 'r': |
|
|
334 | rule_file = fopen( optarg, "r" ); |
|
|
335 | if ( rule_file == NULL ) |
|
|
336 | { |
1855 | { |
337 | fprintf( stderr, "\nRule file (%s) not found\n", optarg ); |
1856 | if (thread_is_working_[cur_thread_num + ij] == 0) |
338 | exit( -1 ); |
1857 | { |
|
|
1858 | cur_thread_num = cur_thread_num + ij; |
|
|
1859 | fprintf(stderr, "found free thread #%d\n", cur_thread_num); |
|
|
1860 | pthread_join(thread_[cur_thread_num], NULL); |
|
|
1861 | break; |
|
|
1862 | } |
339 | } |
1863 | } |
340 | break; |
|
|
341 | case 'u': |
|
|
342 | url=optarg; |
|
|
343 | break; |
|
|
344 | #ifdef HAVE_ZLIB |
|
|
345 | case 'z': |
|
|
346 | compression_level=atoi(optarg); |
|
|
347 | break; |
|
|
348 | #endif |
|
|
349 | case '?': |
|
|
350 | usage(stderr); |
|
|
351 | break; |
|
|
352 | default: |
|
|
353 | fprintf(stderr,"c=%d\n", c); |
|
|
354 | } |
|
|
355 | |
|
|
356 | } |
|
|
357 | if (optind != argc-(output == 1 ? 0:1)) |
|
|
358 | usage(stderr); |
|
|
359 | result=argv[optind]; |
|
|
360 | |
|
|
361 | // initialize plugins and OSM mappings |
|
|
362 | maptool_init(rule_file); |
|
|
363 | if (protobufdb_operation) { |
|
|
364 | osm_protobufdb_load(input_file, protobufdb); |
|
|
365 | return 0; |
|
|
366 | } |
|
|
367 | |
|
|
368 | // input from an OSM file |
|
|
369 | if (input == 0) { |
|
|
370 | if (start == 1) { |
|
|
371 | unlink("coords.tmp"); |
|
|
372 | if (process_ways) |
|
|
373 | ways=tempfile(suffix,"ways",1); |
|
|
374 | if (process_nodes) |
|
|
375 | nodes=tempfile(suffix,"nodes",1); |
|
|
376 | if (process_ways && process_nodes) |
|
|
377 | turn_restrictions=tempfile(suffix,"turn_restrictions",1); |
|
|
378 | if (process_relations) |
|
|
379 | boundaries=tempfile(suffix,"boundaries",1); |
|
|
380 | phase=1; |
|
|
381 | fprintf(stderr,"PROGRESS: Phase 1: collecting data\n"); |
|
|
382 | #ifdef HAVE_POSTGRESQL |
|
|
383 | if (dbstr) |
|
|
384 | map_collect_data_osm_db(dbstr,ways,nodes,turn_restrictions,boundaries); |
|
|
385 | else |
1864 | else |
386 | #endif |
1865 | { |
387 | if (map_handles) { |
1866 | if (thread_is_working_[cur_thread_num + ij - threads] == 0) |
388 | GList *l; |
1867 | { |
389 | phase1_map(map_handles,ways,nodes); |
1868 | cur_thread_num = cur_thread_num + ij - threads; |
390 | l=map_handles; |
1869 | fprintf(stderr, "found free thread #%d\n", cur_thread_num); |
391 | while (l) { |
1870 | pthread_join(thread_[cur_thread_num], NULL); |
392 | map_destroy(l->data); |
1871 | break; |
393 | l=g_list_next(l); |
1872 | } |
|
|
1873 | } |
394 | } |
1874 | } |
395 | } |
1875 | } |
396 | else if (protobuf) |
1876 | |
397 | map_collect_data_osm_protobuf(input_file,ways,nodes,turn_restrictions,boundaries); |
1877 | if (thread_is_working_[cur_thread_num] == 1) |
398 | else |
1878 | { |
399 | map_collect_data_osm(input_file,ways,nodes,turn_restrictions,boundaries); |
1879 | time(&start_tt); |
400 | if (slices) { |
1880 | |
401 | fprintf(stderr,"%d slices\n",slices); |
1881 | fprintf(stderr, "need to wait for thread #%d to finish first ...\n", cur_thread_num); |
402 | flush_nodes(1); |
1882 | //iret_[cur_thread_num] = g_thread_join(thread_[cur_thread_num]); |
403 | for (i = slices-2 ; i>=0 ; i--) { |
1883 | pthread_join(thread_[cur_thread_num], NULL); |
404 | fprintf(stderr, "slice %d of %d\n",slices-i-1,slices-1); |
1884 | //thread_is_working_[cur_thread_num] = 0; |
405 | load_buffer("coords.tmp",&node_buffer, i*slice_size, slice_size); |
1885 | if (verbose_mode) |
406 | resolve_ways(ways, NULL); |
1886 | printf("Thread %d returns: %d\n", cur_thread_num, iret_[cur_thread_num]); |
407 | save_buffer("coords.tmp",&node_buffer, i*slice_size); |
1887 | fprintf(stderr, "... thread #%d ready\n", cur_thread_num); |
|
|
1888 | |
|
|
1889 | time(&end_tt); |
|
|
1890 | diff_tt = difftime(end_tt, start_tt); |
|
|
1891 | char outstring[200]; |
|
|
1892 | convert_to_human_time(diff_tt, outstring); |
|
|
1893 | fprintf(stderr, "-RUNTIME-LOOP1: %s this loop run\n", outstring); |
|
|
1894 | diff2_tt = diff2_tt + diff_tt; |
|
|
1895 | if (i > 0) |
|
|
1896 | { |
|
|
1897 | double eta_time = (diff2_tt / i) * (slices - i); |
|
|
1898 | convert_to_human_time(eta_time, outstring); |
|
|
1899 | fprintf(stderr, "-RUNTIME-LOOP1: %s left\n", outstring); |
408 | } |
1900 | } |
409 | } else |
1901 | } |
410 | save_buffer("coords.tmp",&node_buffer, 0); |
1902 | |
|
|
1903 | if (ways_file[cur_thread_num] == NULL) |
|
|
1904 | { |
|
|
1905 | ways_file[cur_thread_num] = tempfile(suffix, "ways", 0); |
|
|
1906 | } |
|
|
1907 | |
|
|
1908 | vars[cur_thread_num].count = i; |
|
|
1909 | vars[cur_thread_num].thread_num = cur_thread_num; |
|
|
1910 | vars[cur_thread_num].file1 = ways_file[cur_thread_num]; |
|
|
1911 | fprintf(stderr, "starting thread #%d\n", cur_thread_num); |
|
|
1912 | |
|
|
1913 | thread_is_working_[cur_thread_num] = 1; |
|
|
1914 | |
|
|
1915 | //fprintf(stderr, "before start thread\n"); |
|
|
1916 | //my_sleep(40); |
|
|
1917 | // thread_[cur_thread_num] = g_thread_new("t", multi_threaded_phase_001, (void*) &vars[cur_thread_num]); |
|
|
1918 | iret_[cur_thread_num] = pthread_create(&thread_[cur_thread_num], NULL, multi_threaded_phase_001, (void*) &vars[cur_thread_num]); |
|
|
1919 | //fprintf(stderr, "after start thread\n"); |
|
|
1920 | //my_sleep(40); |
|
|
1921 | |
|
|
1922 | cur_thread_num++; |
|
|
1923 | if ((cur_thread_num + 1) > threads) |
|
|
1924 | { |
|
|
1925 | cur_thread_num = 0; |
|
|
1926 | } |
|
|
1927 | } |
|
|
1928 | |
|
|
1929 | for (i = 0; i < threads; i++) |
|
|
1930 | { |
|
|
1931 | if (thread_is_working_[i] == 1) |
|
|
1932 | { |
|
|
1933 | fprintf(stderr, "[LAST] need to wait for thread #%d to finish first ...\n", i); |
|
|
1934 | // iret_[i] = g_thread_join(thread_[i]); |
|
|
1935 | pthread_join(thread_[i], NULL); |
|
|
1936 | if (verbose_mode) |
|
|
1937 | { |
|
|
1938 | printf("[LAST] Thread %d returns: %d\n", i, iret_[i]); |
|
|
1939 | } |
|
|
1940 | //thread_is_working_[i] = 0; |
|
|
1941 | fprintf(stderr, "[LAST] ... ready\n"); |
|
|
1942 | } |
|
|
1943 | } |
|
|
1944 | |
|
|
1945 | for (i = 0; i < threads; i++) |
|
|
1946 | { |
|
|
1947 | if (ways_file[i]) |
|
|
1948 | { |
|
|
1949 | fclose(ways_file[i]); |
|
|
1950 | ways_file[i] = NULL; |
|
|
1951 | } |
|
|
1952 | } |
|
|
1953 | //} |
|
|
1954 | //else |
|
|
1955 | //{ |
|
|
1956 | // //fprintf(stderr, "calling save_buffer 2\n"); |
|
|
1957 | // cur_thread_num = 0; |
|
|
1958 | // // --old-- save_buffer("coords.tmp", &node_buffer[cur_thread_num], 0); // where did we "load_buffer" first?? this seems kaputt!! |
|
|
1959 | // flush_nodes(1, cur_thread_num); // flush remains to "coords.tmp" from "osm_end_node" |
|
|
1960 | // |
|
|
1961 | // FILE *file1 = tempfile(suffix, "ways", 0); |
|
|
1962 | // long long i_x_slice_base = 0 * slice_size; |
|
|
1963 | // load_buffer("coords.tmp", &node_buffer[0], i_x_slice_base, slice_size); |
|
|
1964 | // // try to fillup the node_hash again |
|
|
1965 | // fill_hash_node(0); |
|
|
1966 | // ref_ways(file1, 0); // --> this just sets "ref_way" count, of nodes |
|
|
1967 | // save_buffer("coords.tmp", &node_buffer[0], i_x_slice_base); // this saves the "ref_way" count back to file |
|
|
1968 | // fclose(file1); |
|
|
1969 | //} |
|
|
1970 | |
|
|
1971 | cur_thread_num = 0; |
|
|
1972 | |
|
|
1973 | // clean up buffer(s) |
|
|
1974 | for (i = 0; i < threads; i++) |
|
|
1975 | { |
|
|
1976 | int jj = 0; |
|
|
1977 | for (jj = 0; jj < 800000; jj++) |
|
|
1978 | { |
|
|
1979 | ib_buffer_array[i][jj] = 0; |
|
|
1980 | } |
|
|
1981 | } |
|
|
1982 | |
|
|
1983 | for (jk = 0; jk < max_threads; jk++) |
|
|
1984 | { |
|
|
1985 | if (node_buffer[jk].base != NULL) |
|
|
1986 | { |
|
|
1987 | free(node_buffer[jk].base); |
|
|
1988 | } |
|
|
1989 | node_buffer[jk].malloced = 0; |
|
|
1990 | node_buffer[jk].base = NULL; |
|
|
1991 | node_buffer[jk].size = 0; |
|
|
1992 | } |
|
|
1993 | |
|
|
1994 | if (osm.ways_with_coords) |
|
|
1995 | { |
|
|
1996 | fclose(osm.ways_with_coords); |
|
|
1997 | } |
|
|
1998 | |
411 | if (ways) |
1999 | if (ways) |
|
|
2000 | fclose(ways); |
|
|
2001 | if (nodes) |
|
|
2002 | fclose(nodes); |
|
|
2003 | if (towns) |
|
|
2004 | fclose(towns); |
|
|
2005 | if (turn_restrictions) |
|
|
2006 | fclose(turn_restrictions); |
|
|
2007 | if (boundaries) |
|
|
2008 | { |
|
|
2009 | fclose(boundaries); |
|
|
2010 | fclose(relations_riverbank); |
|
|
2011 | } |
|
|
2012 | |
|
|
2013 | // ------ add tags from "relations" back down to "ways" -- (nonrecursive, meaning only 1 depth) ----- |
|
|
2014 | fprintf(stderr, "PROGRESS: Phase 8: add tags from relations back down to ways\n"); |
|
|
2015 | |
|
|
2016 | time(&start_tt); |
|
|
2017 | ways = tempfile(suffix, "ways", 0); |
|
|
2018 | FILE *ways_relationtags = tempfile(suffix, "ways_relationtags", 1); |
|
|
2019 | relations_riverbank = tempfile(suffix, "relations_riverbank", 0); |
|
|
2020 | copy_tags_to_ways(ways, ways_relationtags, relations_riverbank); |
|
|
2021 | fclose(relations_riverbank); |
|
|
2022 | fclose(ways_relationtags); |
|
|
2023 | fclose(ways); |
|
|
2024 | tempfile_unlink(suffix, "ways"); |
|
|
2025 | tempfile_rename(suffix, "ways_relationtags", "ways"); |
|
|
2026 | time(&end_tt); |
|
|
2027 | diff_tt = difftime(end_tt, start_tt); |
|
|
2028 | char outstring2[200]; |
|
|
2029 | convert_to_human_time(diff_tt, outstring2); |
|
|
2030 | fprintf(stderr, "-RUNTIME-PHASE8: %s\n", outstring2); |
|
|
2031 | // ------ add tags from "relations" back down to "ways" -- (nonrecursive, meaning only 1 depth) ----- |
|
|
2032 | |
|
|
2033 | |
|
|
2034 | #if 0 |
|
|
2035 | // triple memory here |
|
|
2036 | long long slice_size99 = slice_size * 3; |
|
|
2037 | int slices99 = slices / 3; |
|
|
2038 | if ((slices99 * 3) < slices) |
|
|
2039 | { |
|
|
2040 | slices99++; |
|
|
2041 | } |
|
|
2042 | #endif |
|
|
2043 | #if 1 |
|
|
2044 | // keep mem same size |
|
|
2045 | long long slice_size99 = slice_size * 1; |
|
|
2046 | int slices99 = slices / 1; |
|
|
2047 | if ((slices99 * 1) < slices) |
|
|
2048 | { |
|
|
2049 | slices99++; |
|
|
2050 | } |
|
|
2051 | #endif |
|
|
2052 | |
|
|
2053 | if (process_ways) |
|
|
2054 | { |
|
|
2055 | ways = tempfile(suffix, "ways", 0); // start with "ways" file |
|
|
2056 | phase = 2; |
|
|
2057 | fprintf(stderr, "PROGRESS: Phase 2: finding intersections\n"); // and resolve ways (write coords from nodes to ways)!! |
|
|
2058 | diff2_tt = 0; |
|
|
2059 | for (i = 0; i < slices99; i++) |
|
|
2060 | { |
|
|
2061 | time(&start_tt); |
|
|
2062 | |
|
|
2063 | fprintf(stderr, "slice %d of %d\n", i + 1, slices99); |
|
|
2064 | int final = (i >= slices99 - 1); |
|
|
2065 | ways_split = tempfile(suffix, "ways_split", 1); |
|
|
2066 | ways_split_index = final ? tempfile(suffix, "ways_split_index", 1) : NULL; |
|
|
2067 | graph = tempfile(suffix, "graph", 1); |
|
|
2068 | coastline = tempfile(suffix, "coastline", 1); |
|
|
2069 | |
|
|
2070 | load_buffer("coords.tmp", &node_buffer[cur_thread_num], i * slice_size99, slice_size99); |
|
|
2071 | // try to fillup the node_hash again |
|
|
2072 | fill_hash_node(cur_thread_num); |
|
|
2073 | |
|
|
2074 | // fill in lat,long for way, and find intersections |
|
|
2075 | map_find_intersections(ways, ways_split, ways_split_index, graph, coastline, final); |
|
|
2076 | // write to "ways_split" file |
|
|
2077 | |
|
|
2078 | fclose(ways_split); |
|
|
2079 | if (ways_split_index) |
|
|
2080 | { |
|
|
2081 | fclose(ways_split_index); |
|
|
2082 | } |
412 | fclose(ways); |
2083 | fclose(ways); |
413 | if (nodes) |
|
|
414 | fclose(nodes); |
|
|
415 | if (turn_restrictions) |
|
|
416 | fclose(turn_restrictions); |
|
|
417 | if (boundaries) |
|
|
418 | fclose(boundaries); |
|
|
419 | } |
|
|
420 | if (!slices) { |
|
|
421 | if (end == 1 || dump_coordinates) |
|
|
422 | flush_nodes(1); |
|
|
423 | else |
|
|
424 | slices++; |
|
|
425 | } |
|
|
426 | if (end == 1) |
|
|
427 | exit(0); |
|
|
428 | if (start == 2) { |
|
|
429 | load_buffer("coords.tmp",&node_buffer,0, slice_size); |
|
|
430 | } |
|
|
431 | if (start <= 2) { |
|
|
432 | if (process_ways) { |
|
|
433 | ways=tempfile(suffix,"ways",0); |
|
|
434 | phase=2; |
|
|
435 | fprintf(stderr,"PROGRESS: Phase 2: finding intersections\n"); |
|
|
436 | for (i = 0 ; i < slices ; i++) { |
|
|
437 | int final=(i >= slices-1); |
|
|
438 | ways_split=tempfile(suffix,"ways_split",1); |
|
|
439 | ways_split_index=final ? tempfile(suffix,"ways_split_index",1) : NULL; |
|
|
440 | graph=tempfile(suffix,"graph",1); |
|
|
441 | coastline=tempfile(suffix,"coastline",1); |
|
|
442 | if (i) |
|
|
443 | load_buffer("coords.tmp",&node_buffer, i*slice_size, slice_size); |
|
|
444 | map_find_intersections(ways,ways_split,ways_split_index,graph,coastline,final); |
|
|
445 | fclose(ways_split); |
|
|
446 | if (ways_split_index) |
|
|
447 | fclose(ways_split_index); |
|
|
448 | fclose(ways); |
|
|
449 | fclose(graph); |
2084 | fclose(graph); |
450 | fclose(coastline); |
2085 | fclose(coastline); |
451 | if (! final) { |
2086 | if (!final) |
|
|
2087 | { |
|
|
2088 | // rename to "ways_to_resolve" and use that as new input |
452 | tempfile_rename(suffix,"ways_split","ways_to_resolve"); |
2089 | tempfile_rename(suffix, "ways_split", "ways_to_resolve"); |
453 | ways=tempfile(suffix,"ways_to_resolve",0); |
2090 | ways = tempfile(suffix, "ways_to_resolve", 0); |
|
|
2091 | } |
|
|
2092 | |
|
|
2093 | if (i == 0) |
|
|
2094 | { |
|
|
2095 | // after first loop, delete unused original ways file (to save diskspace) |
|
|
2096 | if (!keep_tmpfiles) |
|
|
2097 | { |
|
|
2098 | tempfile_unlink(suffix, "ways"); |
454 | } |
2099 | } |
455 | } |
2100 | } |
456 | if(!keep_tmpfiles) |
|
|
457 | tempfile_unlink(suffix,"ways"); |
|
|
458 | tempfile_unlink(suffix,"ways_to_resolve"); |
|
|
459 | } else |
|
|
460 | fprintf(stderr,"PROGRESS: Skipping Phase 2\n"); |
|
|
461 | } |
|
|
462 | free(node_buffer.base); |
|
|
463 | node_buffer.base=NULL; |
|
|
464 | node_buffer.malloced=0; |
|
|
465 | node_buffer.size=0; |
|
|
466 | if (end == 2) |
|
|
467 | exit(0); |
|
|
468 | } else { |
|
|
469 | ways_split=tempfile(suffix,"ways_split",0); |
|
|
470 | process_binfile(stdin, ways_split); |
|
|
471 | fclose(ways_split); |
|
|
472 | } |
|
|
473 | |
2101 | |
474 | #if 1 |
2102 | time(&end_tt); |
475 | coastline=tempfile(suffix,"coastline",0); |
2103 | diff_tt = difftime(end_tt, start_tt); |
476 | if (coastline) { |
2104 | char outstring[200]; |
477 | ways_split=tempfile(suffix,"ways_split",2); |
2105 | convert_to_human_time(diff_tt, outstring); |
478 | fprintf(stderr,"coastline=%p\n",coastline); |
2106 | fprintf(stderr, "-RUNTIME-LOOP2: %s this loop run\n", outstring); |
479 | process_coastlines(coastline, ways_split); |
2107 | diff2_tt = diff2_tt + diff_tt; |
480 | fclose(ways_split); |
2108 | if ((i + 1) > 0) |
481 | fclose(coastline); |
2109 | { |
482 | } |
2110 | double eta_time = (diff2_tt / (i + 1)) * (slices99 - (i + 1)); |
483 | #endif |
2111 | convert_to_human_time(eta_time, outstring); |
484 | if (start <= 3) { |
2112 | fprintf(stderr, "-RUNTIME-LOOP2: %s left\n", outstring); |
485 | fprintf(stderr,"PROGRESS: Phase 3: sorting countries, generating turn restrictions\n"); |
|
|
486 | sort_countries(keep_tmpfiles); |
|
|
487 | if (process_relations) { |
|
|
488 | #if 0 |
|
|
489 | boundaries=tempfile(suffix,"boundaries",0); |
|
|
490 | ways_split=tempfile(suffix,"ways_split",0); |
|
|
491 | process_boundaries(boundaries, ways_split); |
|
|
492 | fclose(boundaries); |
|
|
493 | fclose(ways_split); |
|
|
494 | exit(0); |
|
|
495 | #endif |
|
|
496 | turn_restrictions=tempfile(suffix,"turn_restrictions",0); |
|
|
497 | if (turn_restrictions) { |
|
|
498 | relations=tempfile(suffix,"relations",1); |
|
|
499 | coords=fopen("coords.tmp","rb"); |
|
|
500 | ways_split=tempfile(suffix,"ways_split",0); |
|
|
501 | ways_split_index=tempfile(suffix,"ways_split_index",0); |
|
|
502 | process_turn_restrictions(turn_restrictions,coords,ways_split,ways_split_index,relations); |
|
|
503 | fclose(ways_split_index); |
|
|
504 | fclose(ways_split); |
|
|
505 | fclose(coords); |
|
|
506 | fclose(relations); |
|
|
507 | fclose(turn_restrictions); |
|
|
508 | if(!keep_tmpfiles) |
|
|
509 | tempfile_unlink(suffix,"turn_restrictions"); |
|
|
510 | } |
2113 | } |
511 | } |
2114 | } |
|
|
2115 | |
|
|
2116 | tempfile_unlink(suffix, "ways_to_resolve"); |
|
|
2117 | } |
|
|
2118 | else |
|
|
2119 | { |
|
|
2120 | fprintf(stderr, "PROGRESS: Skipping Phase 2\n"); |
|
|
2121 | } |
|
|
2122 | |
|
|
2123 | for (jk = 0; jk < max_threads; jk++) |
|
|
2124 | { |
|
|
2125 | if (node_buffer[jk].base != NULL) |
|
|
2126 | { |
|
|
2127 | free(node_buffer[jk].base); |
|
|
2128 | } |
|
|
2129 | node_buffer[jk].malloced = 0; |
|
|
2130 | node_buffer[jk].base = NULL; |
|
|
2131 | node_buffer[jk].size = 0; |
|
|
2132 | } |
|
|
2133 | |
|
|
2134 | // ------ append already resolved ways to ways file ----- |
|
|
2135 | fprintf(stderr, "PROGRESS: Phase 12: append already resolved ways to ways file\n"); |
|
|
2136 | |
|
|
2137 | time(&start_tt); |
|
|
2138 | ways = tempfile(suffix, "ways_split", 2); |
|
|
2139 | osm.ways_with_coords = tempfile(suffix, "ways_with_coords", 0); |
|
|
2140 | append_pre_resolved_ways(ways, &osm); |
|
|
2141 | if (ways) |
|
|
2142 | { |
|
|
2143 | fclose(ways); |
|
|
2144 | } |
|
|
2145 | if (osm.ways_with_coords) |
|
|
2146 | { |
|
|
2147 | fclose(osm.ways_with_coords); |
|
|
2148 | } |
|
|
2149 | time(&end_tt); |
|
|
2150 | diff_tt = difftime(end_tt, start_tt); |
|
|
2151 | char outstring6[200]; |
|
|
2152 | convert_to_human_time(diff_tt, outstring6); |
|
|
2153 | fprintf(stderr, "-RUNTIME-PHASE12: %s\n", outstring6); |
|
|
2154 | // ------ append already resolved ways to ways file ----- |
|
|
2155 | |
|
|
2156 | |
|
|
2157 | // ------ take attr housenumber from ways (building=yes) and add as housenumber node ----- |
|
|
2158 | fprintf(stderr, "PROGRESS: Phase 9: take attr housenumber and add as housenumber node\n"); |
|
|
2159 | |
|
|
2160 | time(&start_tt); |
|
|
2161 | ways = tempfile(suffix, "ways_split", 0); |
|
|
2162 | FILE *nodes2 = tempfile(suffix, "nodes", 2); |
|
|
2163 | process_way2poi_housenumber(ways, nodes2); // append to "nodes" file |
|
|
2164 | if (ways) |
|
|
2165 | fclose(ways); |
|
|
2166 | if (nodes2) |
|
|
2167 | fclose(nodes2); |
|
|
2168 | time(&end_tt); |
|
|
2169 | diff_tt = difftime(end_tt, start_tt); |
|
|
2170 | char outstring3[200]; |
|
|
2171 | convert_to_human_time(diff_tt, outstring3); |
|
|
2172 | fprintf(stderr, "-RUNTIME-PHASE9: %s\n", outstring3); |
|
|
2173 | // ------ take attr housenumber from ways (building=yes) and add as housenumber node ----- |
|
|
2174 | |
|
|
2175 | |
|
|
2176 | // ------ remove useless tags from ways -------------------------------------------------- |
|
|
2177 | fprintf(stderr, "PROGRESS: Phase 10: remove useless tags from ways\n"); |
|
|
2178 | |
|
|
2179 | time(&start_tt); |
|
|
2180 | ways = tempfile(suffix, "ways_split", 0); |
|
|
2181 | FILE *ways28 = tempfile(suffix, "ways_tags_removed", 1); |
|
|
2182 | remove_useless_tags_from_ways(ways, ways28); |
|
|
2183 | if (ways) |
|
|
2184 | fclose(ways); |
|
|
2185 | if (ways28) |
|
|
2186 | fclose(ways28); |
|
|
2187 | tempfile_unlink(suffix, "ways_split"); |
|
|
2188 | tempfile_rename(suffix, "ways_tags_removed", "ways_split"); |
|
|
2189 | time(&end_tt); |
|
|
2190 | diff_tt = difftime(end_tt, start_tt); |
|
|
2191 | char outstring4[200]; |
|
|
2192 | convert_to_human_time(diff_tt, outstring4); |
|
|
2193 | fprintf(stderr, "-RUNTIME-PHASE10: %s\n", outstring4); |
|
|
2194 | // ------ remove useless tags from ways -------------------------------------------------- |
|
|
2195 | |
|
|
2196 | |
|
|
2197 | FILE *coastline2 = tempfile(suffix, "coastline", 0); |
|
|
2198 | if (coastline2) |
|
|
2199 | { |
|
|
2200 | time(&start_tt); |
|
|
2201 | |
|
|
2202 | fprintf(stderr, "PROGRESS: Processing Coastlines\n"); |
|
|
2203 | FILE *coastline_result = tempfile(suffix, "coastline_result", 1); |
|
|
2204 | process_coastlines(coastline2, coastline_result); // complex coastline stuff (at normal mapgen it does nothing!!) |
|
|
2205 | fclose(coastline_result); |
|
|
2206 | fclose(coastline2); |
|
|
2207 | |
|
|
2208 | time(&end_tt); |
|
|
2209 | diff_tt = difftime(end_tt, start_tt); |
|
|
2210 | char outstring[200]; |
|
|
2211 | convert_to_human_time(diff_tt, outstring); |
|
|
2212 | fprintf(stderr, "-RUNTIME-COASTLINES: %s\n", outstring); |
|
|
2213 | } |
|
|
2214 | |
|
|
2215 | sql_db_open(); |
|
|
2216 | sql_db_init(0); |
|
|
2217 | |
|
|
2218 | FILE *towns2 = tempfile(suffix, "towns", 0); |
|
|
2219 | FILE *boundaries2 = NULL; |
|
|
2220 | FILE *ways2 = NULL; |
|
|
2221 | FILE *coords2 = NULL; |
|
|
2222 | if (towns2) |
|
|
2223 | { |
|
|
2224 | time(&start_tt); |
|
|
2225 | boundaries2 = tempfile(suffix, "boundaries", 0); |
|
|
2226 | ways2 = tempfile(suffix, "ways_split", 0); |
|
|
2227 | coords2 = fopen("coords.tmp", "rb"); |
|
|
2228 | |
|
|
2229 | #ifdef MAPTOOL_USE_SQL |
|
|
2230 | sql_counter = 0; |
|
|
2231 | sql_counter2 = 0; |
|
|
2232 | sql_counter3 = 0; |
|
|
2233 | sql_counter4 = 0; |
|
|
2234 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
2235 | sqlite3_exec(sql_handle002a, "COMMIT", 0, 0, 0); |
|
|
2236 | sqlite3_exec(sql_handle003a, "COMMIT", 0, 0, 0); |
|
|
2237 | sqlite3_exec(sql_handle002b, "COMMIT", 0, 0, 0); |
|
|
2238 | sqlite3_exec(sql_handle003b, "COMMIT", 0, 0, 0); |
|
|
2239 | sqlite3_exec(sql_handle004, "COMMIT", 0, 0, 0); |
|
|
2240 | sqlite3_exec(sql_handle005, "COMMIT", 0, 0, 0); |
|
|
2241 | sqlite3_exec(sql_handle006, "COMMIT", 0, 0, 0); |
|
|
2242 | sqlite3_exec(sql_handle007, "COMMIT", 0, 0, 0); |
|
|
2243 | #endif |
|
|
2244 | boundaries_list = osm_process_towns(towns2, coords2, boundaries2, ways2); // check where towns are located with boundaries and "is_in" |
|
|
2245 | |
|
|
2246 | correct_boundary_ref_point(boundaries_list); |
|
|
2247 | build_boundary_tree(boundaries_list); |
|
|
2248 | #ifdef MAPTOOL_USE_SQL |
|
|
2249 | sql_counter = 0; |
|
|
2250 | sql_counter2 = 0; |
|
|
2251 | sql_counter3 = 0; |
|
|
2252 | sql_counter4 = 0; |
|
|
2253 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
2254 | sqlite3_exec(sql_handle002a, "COMMIT", 0, 0, 0); |
|
|
2255 | sqlite3_exec(sql_handle003a, "COMMIT", 0, 0, 0); |
|
|
2256 | sqlite3_exec(sql_handle002b, "COMMIT", 0, 0, 0); |
|
|
2257 | sqlite3_exec(sql_handle003b, "COMMIT", 0, 0, 0); |
|
|
2258 | sqlite3_exec(sql_handle004, "COMMIT", 0, 0, 0); |
|
|
2259 | sqlite3_exec(sql_handle005, "COMMIT", 0, 0, 0); |
|
|
2260 | sqlite3_exec(sql_handle006, "COMMIT", 0, 0, 0); |
|
|
2261 | sqlite3_exec(sql_handle007, "COMMIT", 0, 0, 0); |
|
|
2262 | |
|
|
2263 | fprintf(stderr, "SQL: (create index 002) start\n"); |
|
|
2264 | sql_create_index002(); |
|
|
2265 | fprintf(stderr, "SQL: (create index 002) ready\n"); |
|
|
2266 | // reopen for indexes to be used |
|
|
2267 | sql_db_close(); |
|
|
2268 | sql_db_open(); |
|
|
2269 | sql_db_init(0); |
|
|
2270 | |
|
|
2271 | #endif |
|
|
2272 | |
|
|
2273 | fclose(ways2); |
|
|
2274 | fclose(boundaries2); |
|
|
2275 | fclose(towns2); |
|
|
2276 | fclose(coords2); |
512 | if(!keep_tmpfiles) |
2277 | if (!keep_tmpfiles) |
|
|
2278 | { |
|
|
2279 | tempfile_unlink(suffix, "towns"); |
|
|
2280 | } |
|
|
2281 | time(&end_tt); |
|
|
2282 | diff_tt = difftime(end_tt, start_tt); |
|
|
2283 | char outstring[200]; |
|
|
2284 | convert_to_human_time(diff_tt, outstring); |
|
|
2285 | fprintf(stderr, "-RUNTIME-TOWNS: %s\n", outstring); |
|
|
2286 | } |
|
|
2287 | |
|
|
2288 | // ------ assign town to streets -------------------------------------------------- |
|
|
2289 | fprintf(stderr, "PROGRESS: Phase 13: assign town to streets\n"); |
|
|
2290 | |
|
|
2291 | time(&start_tt); |
|
|
2292 | assign_town_to_streets(boundaries_list); |
|
|
2293 | // we should free the GList boundaries_list here!!! |
|
|
2294 | time(&end_tt); |
|
|
2295 | diff_tt = difftime(end_tt, start_tt); |
|
|
2296 | char outstring7[200]; |
|
|
2297 | convert_to_human_time(diff_tt, outstring7); |
|
|
2298 | fprintf(stderr, "-RUNTIME-PHASE13: %s\n", outstring7); |
|
|
2299 | // ------ assign town to streets -------------------------------------------------- |
|
|
2300 | |
|
|
2301 | |
|
|
2302 | // ------ generate street index file -------------------------------------------------- |
|
|
2303 | fprintf(stderr, "PROGRESS: Phase 14: generate street index file\n"); |
|
|
2304 | |
|
|
2305 | time(&start_tt); |
|
|
2306 | |
|
|
2307 | FILE *ways14_2 = tempfile(suffix, "town_index", 1); |
|
|
2308 | generate_town_index_file(ways14_2); |
|
|
2309 | fclose(ways14_2); |
|
|
2310 | |
|
|
2311 | FILE *ways14_1 = tempfile(suffix, "street_index", 1); |
|
|
2312 | generate_street_index_file(ways14_1); |
|
|
2313 | fclose(ways14_1); |
|
|
2314 | |
|
|
2315 | ways14_1 = tempfile(suffix, "street_index", 0); |
|
|
2316 | ways14_2 = tempfile(suffix, "town_index", 0); |
|
|
2317 | FILE *ways14_3 = tempfile(suffix, "street_town_index", 1); |
|
|
2318 | generate_combined_index_file(ways14_2, ways14_1, ways14_3); |
|
|
2319 | fclose(ways14_1); |
|
|
2320 | fclose(ways14_2); |
|
|
2321 | fclose(ways14_3); |
|
|
2322 | |
|
|
2323 | tempfile_unlink(suffix, "town_index"); |
|
|
2324 | tempfile_unlink(suffix, "street_index"); |
|
|
2325 | |
|
|
2326 | // street_town_index_.tmp -> <$result>.idx |
|
|
2327 | char* outfilename_idx = g_strdup_printf("%s.idx", result); |
|
|
2328 | rename("street_town_index_.tmp", outfilename_idx); |
|
|
2329 | g_free(outfilename_idx); |
|
|
2330 | |
|
|
2331 | time(&end_tt); |
|
|
2332 | diff_tt = difftime(end_tt, start_tt); |
|
|
2333 | char outstring8[200]; |
|
|
2334 | convert_to_human_time(diff_tt, outstring8); |
|
|
2335 | fprintf(stderr, "-RUNTIME-PHASE14: %s\n", outstring8); |
|
|
2336 | // ------ generate street index file -------------------------------------------------- |
|
|
2337 | |
|
|
2338 | |
|
|
2339 | |
|
|
2340 | |
|
|
2341 | sql_db_close(); |
|
|
2342 | |
|
|
2343 | unlink(g_strdup_printf("%stemp_data.db",sqlite_db_dir)); |
|
|
2344 | unlink("temp_data.db"); |
|
|
2345 | |
|
|
2346 | unlink(g_strdup_printf("%stemp_data002a.db",sqlite_db_dir)); |
|
|
2347 | unlink(g_strdup_printf("%stemp_data003a.db",sqlite_db_dir)); |
|
|
2348 | unlink(g_strdup_printf("%stemp_data002b.db",sqlite_db_dir)); |
|
|
2349 | unlink(g_strdup_printf("%stemp_data003b.db",sqlite_db_dir)); |
|
|
2350 | unlink("temp_data002a.db"); |
|
|
2351 | unlink("temp_data003a.db"); |
|
|
2352 | unlink("temp_data002b.db"); |
|
|
2353 | unlink("temp_data003b.db"); |
|
|
2354 | |
|
|
2355 | unlink(g_strdup_printf("%stemp_data004.db",sqlite_db_dir)); |
|
|
2356 | unlink(g_strdup_printf("%stemp_data005.db",sqlite_db_dir)); |
|
|
2357 | unlink(g_strdup_printf("%stemp_data006.db",sqlite_db_dir)); |
|
|
2358 | unlink(g_strdup_printf("%stemp_data007.db",sqlite_db_dir)); |
|
|
2359 | unlink("temp_data004.db"); |
|
|
2360 | unlink("temp_data005.db"); |
|
|
2361 | unlink("temp_data006.db"); |
|
|
2362 | unlink("temp_data007.db"); |
|
|
2363 | |
|
|
2364 | |
|
|
2365 | |
|
|
2366 | |
|
|
2367 | |
|
|
2368 | |
|
|
2369 | |
|
|
2370 | |
|
|
2371 | |
|
|
2372 | |
|
|
2373 | |
|
|
2374 | fprintf(stderr, "PROGRESS: Phase 3: sorting countries, generating turn restrictions\n"); |
|
|
2375 | sort_countries(keep_tmpfiles); // sort the temp country files |
|
|
2376 | |
|
|
2377 | if (process_relations) |
|
|
2378 | { |
|
|
2379 | turn_restrictions = tempfile(suffix, "turn_restrictions", 0); |
|
|
2380 | if (turn_restrictions) |
|
|
2381 | { |
|
|
2382 | time(&start_tt); |
|
|
2383 | relations = tempfile(suffix, "relations", 1); |
|
|
2384 | coords = fopen("coords.tmp", "rb"); |
|
|
2385 | ways_split = tempfile(suffix, "ways_split", 0); |
|
|
2386 | ways_split_index = tempfile(suffix, "ways_split_index", 0); |
|
|
2387 | process_turn_restrictions(turn_restrictions, coords, ways_split, ways_split_index, relations); // process turn restrictions (osm releations!) |
|
|
2388 | fclose(ways_split_index); |
|
|
2389 | fclose(ways_split); |
|
|
2390 | fclose(coords); |
|
|
2391 | fclose(relations); |
|
|
2392 | fclose(turn_restrictions); |
|
|
2393 | if (!keep_tmpfiles) |
|
|
2394 | { |
|
|
2395 | tempfile_unlink(suffix, "turn_restrictions"); |
|
|
2396 | } |
|
|
2397 | time(&end_tt); |
|
|
2398 | diff_tt = difftime(end_tt, start_tt); |
|
|
2399 | char outstring[200]; |
|
|
2400 | convert_to_human_time(diff_tt, outstring); |
|
|
2401 | fprintf(stderr, "-RUNTIME-TURN_RESTRICTIONS: %s\n", outstring); |
|
|
2402 | } |
|
|
2403 | } |
|
|
2404 | |
|
|
2405 | if (!keep_tmpfiles) |
|
|
2406 | { |
513 | tempfile_unlink(suffix,"ways_split_index"); |
2407 | tempfile_unlink(suffix, "ways_split_index"); |
514 | } |
2408 | } |
515 | if (end == 3) |
2409 | |
516 | exit(0); |
|
|
517 | if (output == 1) { |
2410 | if (output == 1) |
|
|
2411 | { |
518 | fprintf(stderr,"PROGRESS: Phase 4: dumping\n"); |
2412 | fprintf(stderr, "PROGRESS: Phase 4: dumping\n"); |
519 | if (process_nodes) { |
2413 | if (process_nodes) |
|
|
2414 | { |
520 | nodes=tempfile(suffix,"nodes",0); |
2415 | nodes = tempfile(suffix, "nodes", 0); |
521 | if (nodes) { |
2416 | if (nodes) |
|
|
2417 | { |
522 | dump(nodes); |
2418 | dump(nodes); |
523 | fclose(nodes); |
2419 | fclose(nodes); |
524 | } |
2420 | } |
525 | } |
2421 | } |
526 | if (process_ways) { |
2422 | if (process_ways) |
|
|
2423 | { |
527 | ways_split=tempfile(suffix,"ways_split",0); |
2424 | ways_split = tempfile(suffix, "ways_split", 0); |
528 | if (ways_split) { |
2425 | if (ways_split) |
|
|
2426 | { |
529 | dump(ways_split); |
2427 | dump(ways_split); |
530 | fclose(ways_split); |
2428 | fclose(ways_split); |
531 | } |
2429 | } |
532 | } |
2430 | } |
533 | if (process_relations) { |
2431 | if (process_relations) |
|
|
2432 | { |
534 | relations=tempfile(suffix,"relations",0); |
2433 | relations = tempfile(suffix, "relations", 0); |
535 | fprintf(stderr,"Relations=%p\n",relations); |
|
|
536 | if (relations) { |
2434 | if (relations) |
|
|
2435 | { |
537 | dump(relations); |
2436 | dump(relations); |
538 | fclose(relations); |
2437 | fclose(relations); |
539 | } |
2438 | } |
540 | } |
2439 | } |
541 | exit(0); |
2440 | exit(0); |
542 | } |
2441 | } |
|
|
2442 | |
|
|
2443 | // ------ remove useless tags from nodes -------------------------------------------------- |
|
|
2444 | fprintf(stderr, "PROGRESS: Phase 11: remove useless tags from nodes\n"); |
|
|
2445 | |
|
|
2446 | time(&start_tt); |
|
|
2447 | nodes = tempfile(suffix, "nodes", 0); |
|
|
2448 | FILE *nodes28 = tempfile(suffix, "nodes_tags_removed", 1); |
|
|
2449 | remove_useless_tags_from_nodes(nodes, nodes28); |
|
|
2450 | if (nodes) |
|
|
2451 | fclose(nodes); |
|
|
2452 | if (nodes28) |
|
|
2453 | fclose(nodes28); |
|
|
2454 | tempfile_unlink(suffix, "nodes"); |
|
|
2455 | tempfile_rename(suffix, "nodes_tags_removed", "nodes"); |
|
|
2456 | time(&end_tt); |
|
|
2457 | diff_tt = difftime(end_tt, start_tt); |
|
|
2458 | char outstring5[200]; |
|
|
2459 | convert_to_human_time(diff_tt, outstring5); |
|
|
2460 | fprintf(stderr, "-RUNTIME-PHASE11: %s\n", outstring5); |
|
|
2461 | // ------ remove useless tags from nodes -------------------------------------------------- |
|
|
2462 | |
|
|
2463 | |
|
|
2464 | // remove DB |
|
|
2465 | // ** unlink("temp_data.db"); |
|
|
2466 | // ** unlink("temp_data002.db"); |
|
|
2467 | |
|
|
2468 | |
543 | for (i = suffix_start ; i < suffix_count ; i++) { |
2469 | for (i = suffix_start; i < suffix_count; i++) |
|
|
2470 | { |
544 | suffix=suffixes[i]; |
2471 | suffix = suffixes[i]; |
545 | if (start <= 4) { |
2472 | if (start <= 4) |
|
|
2473 | { |
546 | phase=3; |
2474 | phase = 3; |
547 | if (i == suffix_start) { |
2475 | if (i == suffix_start) |
|
|
2476 | { |
548 | zip_info=zip_new(); |
2477 | zip_info = zip_new(); |
549 | zip_set_zip64(zip_info, zip64); |
2478 | zip_set_zip64(zip_info, zip64); |
550 | zip_set_timestamp(zip_info, timestamp); |
2479 | zip_set_timestamp(zip_info, timestamp); |
551 | } |
2480 | } |
552 | zipnum=zip_get_zipnum(zip_info); |
2481 | zipnum = zip_get_zipnum(zip_info); |
553 | fprintf(stderr,"PROGRESS: Phase 4: generating tiles %s\n",suffix); |
2482 | fprintf(stderr, "PROGRESS: Phase 4: generating tiles %s\n", suffix); |
554 | tilesdir=tempfile(suffix,"tilesdir",1); |
2483 | tilesdir = tempfile(suffix, "tilesdir", 1); |
|
|
2484 | if (!strcmp(suffix, r)) |
555 | if (!strcmp(suffix,r)) { /* Makes compiler happy due to bug 35903 in gcc */ |
2485 | { /* Makes compiler happy due to bug 35903 in gcc */ |
556 | ch_generate_tiles(suffixes[0],suffix,tilesdir,zip_info); |
2486 | ch_generate_tiles(suffixes[0], suffix, tilesdir, zip_info); |
|
|
2487 | } |
557 | } else { |
2488 | else |
|
|
2489 | { |
558 | for (f = 0 ; f < 3 ; f++) |
2490 | for (f = 0; f < 3; f++) |
|
|
2491 | { |
559 | files[f]=NULL; |
2492 | files[f] = NULL; |
|
|
2493 | } |
560 | if (process_relations) |
2494 | if (process_relations) |
|
|
2495 | { |
561 | files[0]=tempfile(suffix,"relations",0); |
2496 | files[0] = tempfile(suffix, "relations", 0); |
|
|
2497 | } |
562 | if (process_ways) |
2498 | if (process_ways) |
|
|
2499 | { |
563 | files[1]=tempfile(suffix,"ways_split",0); |
2500 | files[1] = tempfile(suffix, "ways_split", 0); |
|
|
2501 | } |
564 | if (process_nodes) |
2502 | if (process_nodes) |
|
|
2503 | { |
565 | files[2]=tempfile(suffix,"nodes",0); |
2504 | files[2] = tempfile(suffix, "nodes", 0); |
|
|
2505 | } |
|
|
2506 | |
|
|
2507 | time(&start_tt); |
566 | phase4(files,3,0,suffix,tilesdir,zip_info); |
2508 | phase4(files, 3, 0, suffix, tilesdir, zip_info); |
|
|
2509 | time(&end_tt); |
|
|
2510 | diff_tt = difftime(end_tt, start_tt); |
|
|
2511 | char outstring[200]; |
|
|
2512 | convert_to_human_time(diff_tt, outstring); |
|
|
2513 | fprintf(stderr, "-RUNTIME-PHASE4: %s\n", outstring); |
|
|
2514 | |
567 | for (f = 0 ; f < 3 ; f++) { |
2515 | for (f = 0; f < 3; f++) |
|
|
2516 | { |
568 | if (files[f]) |
2517 | if (files[f]) |
|
|
2518 | { |
569 | fclose(files[f]); |
2519 | fclose(files[f]); |
|
|
2520 | } |
570 | } |
2521 | } |
571 | } |
2522 | } |
572 | fclose(tilesdir); |
2523 | fclose(tilesdir); |
573 | zip_set_zipnum(zip_info,zipnum); |
2524 | zip_set_zipnum(zip_info, zipnum); |
574 | } |
2525 | } |
|
|
2526 | |
575 | if (end == 4) |
2527 | if (end == 4) |
576 | exit(0); |
2528 | exit(0); |
|
|
2529 | |
577 | if (zip_info) { |
2530 | if (zip_info) |
|
|
2531 | { |
578 | zip_destroy(zip_info); |
2532 | zip_destroy(zip_info); |
579 | zip_info=NULL; |
2533 | zip_info = NULL; |
580 | } |
2534 | } |
|
|
2535 | |
581 | if (start <= 5) { |
2536 | if (start <= 5) |
|
|
2537 | { |
582 | phase=4; |
2538 | phase = 4; |
583 | fprintf(stderr,"PROGRESS: Phase 5: assembling map %s\n",suffix); |
2539 | fprintf(stderr, "PROGRESS: Phase 5: assembling map %s\n", suffix); |
584 | if (i == suffix_start) { |
2540 | if (i == suffix_start) |
|
|
2541 | { |
585 | char *zipdir=tempfile_name("zipdir",""); |
2542 | char *zipdir = tempfile_name("zipdir", ""); |
586 | char *zipindex=tempfile_name("index",""); |
2543 | char *zipindex = tempfile_name("index", ""); |
587 | zip_info=zip_new(); |
2544 | zip_info = zip_new(); |
588 | zip_set_zip64(zip_info, zip64); |
2545 | zip_set_zip64(zip_info, zip64); |
589 | zip_set_timestamp(zip_info, timestamp); |
2546 | zip_set_timestamp(zip_info, timestamp); |
590 | zip_set_maxnamelen(zip_info, 14+strlen(suffixes[0])); |
2547 | zip_set_maxnamelen(zip_info, 14 + strlen(suffixes[0])); |
591 | zip_set_compression_level(zip_info, compression_level); |
2548 | zip_set_compression_level(zip_info, compression_level); |
|
|
2549 | |
592 | if (md5file) |
2550 | if (md5file) |
|
|
2551 | { |
593 | zip_set_md5(zip_info, 1); |
2552 | zip_set_md5(zip_info, 1); |
|
|
2553 | } |
|
|
2554 | |
594 | zip_open(zip_info, result, zipdir, zipindex); |
2555 | zip_open(zip_info, result, zipdir, zipindex); |
|
|
2556 | |
595 | if (url) { |
2557 | if (url) |
|
|
2558 | { |
596 | map_information_attrs[1].type=attr_url; |
2559 | map_information_attrs[1].type = attr_url; |
597 | map_information_attrs[1].u.str=url; |
2560 | map_information_attrs[1].u.str = url; |
598 | } |
2561 | } |
599 | index_init(zip_info, 1); |
2562 | index_init(zip_info, 1); |
600 | } |
2563 | } |
|
|
2564 | |
|
|
2565 | if (!strcmp(suffix, r)) |
601 | if (!strcmp(suffix,r)) { /* Makes compiler happy due to bug 35903 in gcc */ |
2566 | { /* Makes compiler happy due to bug 35903 in gcc */ |
602 | ch_assemble_map(suffixes[0],suffix,zip_info); |
2567 | ch_assemble_map(suffixes[0], suffix, zip_info); |
|
|
2568 | } |
603 | } else { |
2569 | else |
|
|
2570 | { |
604 | for (f = 0 ; f < 3 ; f++) { |
2571 | for (f = 0; f < 3; f++) |
|
|
2572 | { |
605 | files[f]=NULL; |
2573 | files[f] = NULL; |
606 | references[f]=NULL; |
2574 | references[f] = NULL; |
607 | } |
2575 | } |
|
|
2576 | |
608 | if (process_relations) |
2577 | if (process_relations) |
|
|
2578 | { |
609 | files[0]=tempfile(suffix,"relations",0); |
2579 | files[0] = tempfile(suffix, "relations", 0); |
610 | if (process_ways) { |
|
|
611 | files[1]=tempfile(suffix,"ways_split",0); |
|
|
612 | references[1]=tempfile(suffix,"ways_split_ref",1); |
|
|
613 | } |
2580 | } |
|
|
2581 | |
|
|
2582 | if (process_ways) |
|
|
2583 | { |
|
|
2584 | files[1] = tempfile(suffix, "ways_split", 0); |
|
|
2585 | references[1] = tempfile(suffix, "ways_split_ref", 1); |
|
|
2586 | } |
|
|
2587 | |
614 | if (process_nodes) |
2588 | if (process_nodes) |
|
|
2589 | { |
615 | files[2]=tempfile(suffix,"nodes",0); |
2590 | files[2] = tempfile(suffix, "nodes", 0); |
|
|
2591 | } |
|
|
2592 | |
616 | fprintf(stderr,"Slice %d\n",i); |
2593 | fprintf(stderr, "Slice %d\n", i); |
617 | |
2594 | |
|
|
2595 | time(&start_tt); |
618 | phase5(files,references,3,0,suffix,zip_info); |
2596 | phase5(files, references, 3, 0, suffix, zip_info); |
|
|
2597 | time(&end_tt); |
|
|
2598 | diff_tt = difftime(end_tt, start_tt); |
|
|
2599 | char outstring[200]; |
|
|
2600 | convert_to_human_time(diff_tt, outstring); |
|
|
2601 | fprintf(stderr, "-RUNTIME-PHASE5: %s\n", outstring); |
|
|
2602 | |
619 | for (f = 0 ; f < 3 ; f++) { |
2603 | for (f = 0; f < 3; f++) |
|
|
2604 | { |
620 | if (files[f]) |
2605 | if (files[f]) |
|
|
2606 | { |
621 | fclose(files[f]); |
2607 | fclose(files[f]); |
|
|
2608 | } |
622 | if (references[f]) |
2609 | if (references[f]) |
|
|
2610 | { |
623 | fclose(references[f]); |
2611 | fclose(references[f]); |
|
|
2612 | } |
624 | } |
2613 | } |
625 | } |
2614 | } |
|
|
2615 | |
626 | if(!keep_tmpfiles) { |
2616 | if (!keep_tmpfiles) |
|
|
2617 | { |
627 | tempfile_unlink(suffix,"relations"); |
2618 | tempfile_unlink(suffix, "relations"); |
628 | tempfile_unlink(suffix,"nodes"); |
2619 | tempfile_unlink(suffix, "nodes"); |
629 | tempfile_unlink(suffix,"ways_split"); |
2620 | tempfile_unlink(suffix, "ways_split"); |
630 | tempfile_unlink(suffix,"ways_split_ref"); |
2621 | tempfile_unlink(suffix, "ways_split_ref"); |
|
|
2622 | tempfile_unlink(suffix, "ways_with_coords"); |
631 | tempfile_unlink(suffix,"coastline"); |
2623 | tempfile_unlink(suffix, "coastline"); |
632 | tempfile_unlink(suffix,"turn_restrictions"); |
2624 | tempfile_unlink(suffix, "turn_restrictions"); |
633 | tempfile_unlink(suffix,"graph"); |
2625 | tempfile_unlink(suffix, "graph"); |
634 | tempfile_unlink(suffix,"tilesdir"); |
2626 | tempfile_unlink(suffix, "tilesdir"); |
635 | tempfile_unlink(suffix,"boundaries"); |
2627 | tempfile_unlink(suffix, "boundaries"); |
|
|
2628 | tempfile_unlink(suffix, "relations_riverbank"); |
|
|
2629 | tempfile_unlink(suffix, "coastline_result"); |
|
|
2630 | |
636 | unlink("coords.tmp"); |
2631 | unlink("coords.tmp"); |
637 | } |
2632 | } |
|
|
2633 | |
638 | if (i == suffix_count-1) { |
2634 | if (i == suffix_count - 1) |
|
|
2635 | { |
639 | unsigned char md5_data[16]; |
2636 | unsigned char md5_data[16]; |
|
|
2637 | |
640 | zipnum=zip_get_zipnum(zip_info); |
2638 | zipnum = zip_get_zipnum(zip_info); |
641 | add_aux_tiles("auxtiles.txt", zip_info); |
2639 | add_aux_tiles("auxtiles.txt", zip_info); |
|
|
2640 | |
642 | write_countrydir(zip_info); |
2641 | write_countrydir(zip_info); |
643 | zip_set_zipnum(zip_info, zipnum); |
2642 | zip_set_zipnum(zip_info, zipnum); |
644 | write_aux_tiles(zip_info); |
2643 | write_aux_tiles(zip_info); |
645 | zip_write_index(zip_info); |
2644 | zip_write_index(zip_info); |
646 | zip_write_directory(zip_info); |
2645 | zip_write_directory(zip_info); |
647 | zip_close(zip_info); |
2646 | zip_close(zip_info); |
|
|
2647 | |
648 | if (md5file && zip_get_md5(zip_info, md5_data)) { |
2648 | if (md5file && zip_get_md5(zip_info, md5_data)) |
|
|
2649 | { |
649 | FILE *md5=fopen(md5file,"w"); |
2650 | FILE *md5 = fopen(md5file, "w"); |
650 | int i; |
2651 | int i; |
651 | for (i = 0 ; i < 16 ; i++) |
2652 | for (i = 0; i < 16; i++) |
|
|
2653 | { |
652 | fprintf(md5,"%02x",md5_data[i]); |
2654 | fprintf(md5, "%02x", md5_data[i]); |
|
|
2655 | } |
653 | fprintf(md5,"\n"); |
2656 | fprintf(md5, "\n"); |
654 | fclose(md5); |
2657 | fclose(md5); |
655 | } |
2658 | } |
|
|
2659 | |
656 | if (!keep_tmpfiles) { |
2660 | if (!keep_tmpfiles) |
|
|
2661 | { |
657 | remove_countryfiles(); |
2662 | remove_countryfiles(); |
658 | tempfile_unlink("index",""); |
2663 | tempfile_unlink("index", ""); |
659 | tempfile_unlink("zipdir",""); |
2664 | tempfile_unlink("zipdir", ""); |
660 | } |
2665 | } |
661 | } |
2666 | } |
662 | } |
2667 | } |
663 | } |
2668 | } |
|
|
2669 | |
|
|
2670 | if (border_only_map_as_xml == 1) |
|
|
2671 | { |
|
|
2672 | FILE *out_ = tempfile("", "borders.xml", 2); |
|
|
2673 | fprintf(out_, "</osm>\n"); |
|
|
2674 | fclose(out_); |
|
|
2675 | } |
|
|
2676 | |
|
|
2677 | sig_alrm(0); |
|
|
2678 | sig_alrm_end(); |
|
|
2679 | |
|
|
2680 | time(&global_end_tt); |
|
|
2681 | global_diff_tt = difftime(global_end_tt, global_start_tt); |
|
|
2682 | char global_outstring[200]; |
|
|
2683 | convert_to_human_time(global_diff_tt, global_outstring); |
|
|
2684 | fprintf(stderr, "PROGRESS: Phase 999:%s:### Map Ready ### -RUNTIME-OVERALL: %s\n", result, global_outstring); |
|
|
2685 | |
664 | return 0; |
2686 | return 0; |
665 | } |
2687 | } |
|
|
2688 | |