/[zanavi_public1]/navit/navit/maptool/maptool.c
ZANavi

Contents of /navit/navit/maptool/maptool.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Mon Feb 4 17:41:59 2013 UTC (7 years, 6 months ago) by zoff99
File MIME type: text/plain
File size: 90966 byte(s)
new map version, lots of fixes and experimental new features
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
20 /**
21 * Navit, a modular navigation system.
22 * Copyright (C) 2005-2011 Navit Team
23 *
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * version 2 as published by the Free Software Foundation.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the
35 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
36 * Boston, MA 02110-1301, USA.
37 */
38
39 #define _FILE_OFFSET_BITS 64
40 #define _LARGEFILE_SOURCE
41 #define _LARGEFILE64_SOURCE
42 #include <stdlib.h>
43 #include <time.h>
44 #include <sys/resource.h>
45 #include <glib.h>
46 #include <assert.h>
47 #include <string.h>
48 #include <signal.h>
49 #include <stdio.h>
50 #include <math.h>
51 #include <getopt.h>
52 #include <unistd.h>
53 #include <fcntl.h>
54 #include <sys/stat.h>
55 #include <zlib.h>
56
57 // pthreads
58 #include <pthread.h>
59 // pthreads
60
61 #include "version_maptool.h"
62
63 #include "file.h"
64 #include "item.h"
65 #include "map.h"
66 #include "zipfile.h"
67 #include "main.h"
68 #include "config.h"
69 #include "linguistics.h"
70 #include "plugin.h"
71 #include "util.h"
72 #include "maptool.h"
73
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
84 int attr_debug_level = 1;
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;
89 // GHashTable *dedupe_ways_hash;
90 int phase;
91 int slices;
92 int unknown_country;
93 int doway2poi = 0;
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;
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
146 int processed_nodes, processed_nodes_out, processed_ways, processed_relations, processed_tiles = 0;
147
148 int overlap = 1;
149
150 int bytes_read;
151
152 void sig_alrm(int sig)
153 {
154 #ifndef _WIN32
155 signal(SIGALRM, sig_alrm);
156 alarm(60);
157 #endif
158 //if (verbose_mode)
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();
162 }
163
164 void sig_alrm_end(void)
165 {
166 #ifndef _WIN32
167 alarm(0);
168 #endif
169 }
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
223 static struct plugins *plugins;
224
225 static void add_plugin(char *path)
226 {
227 struct attr **attrs;
228
229 if (!plugins)
230 {
231 // file_init(); // must define some CACHE thingy first!!
232 plugins = plugins_new();
233 }
234 attrs = (struct attr*[])
235 { &(struct attr)
236 { attr_path,
237 { path}},NULL};
238 plugin_new(&(struct attr)
239 { attr_plugins,.u.plugins=plugins}, attrs);
240 }
241
242 static void maptool_init(FILE* rule_file)
243 {
244 if (plugins)
245 {
246 plugins_init(plugins);
247 }
248 osm_init(rule_file);
249 }
250
251 void my_sleep(int delay)
252 {
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 {
1300 fprintf(f, "\n");
1301 fprintf(f, "ZANavi maptool - parse osm textfile and convert to [ZANavi] binfile format\n");
1302 fprintf(f, "version: "SVN_VERSION"\n\n");
1303 fprintf(f, "Usage :\n");
1304 fprintf(f, "bzcat planet.osm.bz2 | maptool mymap.bin\n");
1305 fprintf(f, "Available switches:\n");
1306 fprintf(f, "-h (--help) : this screen\n");
1307 // fprintf(f, "-5 (--md5) : set file where to write md5 sum\n");
1308 fprintf(f, "-6 (--64bit) : set zip 64 bit compression\n");
1309 fprintf(f, "-a (--attr-debug-level) : control which data is included in the debug attribute\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");
1314 //#ifdef HAVE_POSTGRESQL
1315 // fprintf(f," -d (--db) : get osm data out of a postgresql database with osm simple scheme and given connect string\n");
1316 //#endif
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");
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);
1323 // fprintf(f, "-k (--keep-tmpfiles) : do not delete tmp files after processing. useful to reuse them\n\n");
1324 fprintf(f, "-N (--nodes-only) : process only nodes\n");
1325 fprintf(f, "-n : ignore unknown types\n");
1326 // fprintf(f, "-o (--coverage) : map every street to item coverage\n");
1327 // fprintf(f, "-P (--protobuf) : input file is protobuf\n");
1328 fprintf(f, "-r (--rule-file) : read mapping rules from specified file\n");
1329 // fprintf(f, "-s (--start) : start at specified phase\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");
1332 fprintf(f, "-w (--dedupe-ways) : ensure no duplicate ways or nodes. useful when using several input files\n");
1333 fprintf(f, "-W (--ways-only) : process only ways\n");
1334 fprintf(f, "-z (--compression-level) : set the compression level\n");
1335 fprintf(f, "-U (--unknown-country) : add objects with unknown country to index\n");
1336
1337 exit(1);
1338 }
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
1375 int main(int argc, char **argv)
1376 {
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;
1380 FILE *files[10];
1381 FILE *references[10];
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
1393 #if 0
1394 char *map=g_strdup(attrmap);
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
1406 int zipnum, c, start = 1, end = 99, dump_coordinates = 0;
1407 int keep_tmpfiles = 0;
1408 int process_nodes = 1, process_ways = 1, process_relations = 1;
1409 #ifdef HAVE_ZLIB
1410 int compression_level = 9;
1411 #else
1412 int compression_level = 0;
1413 #endif
1414 int zip64 = 0;
1415 int output = 0;
1416 int input = 0;
1417 int protobuf = 0;
1418 int f, pos;
1419 char *result, *optarg_cp, *attr_name, *attr_value;
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
1428 #ifdef HAVE_POSTGRESQL
1429 char *dbstr=NULL;
1430 #endif
1431
1432 FILE* input_file = stdin; // input data
1433
1434 FILE* rule_file = NULL; // external rule file
1435
1436 struct attr *attrs[10];
1437 GList *map_handles = NULL;
1438 struct map *handle;
1439 struct maptool_osm osm;
1440 #if 0
1441 char *suffixes[]=
1442 { "m0l0", "m0l1","m0l2","m0l3","m0l4","m0l5","m0l6"};
1443 char *suffixes[]=
1444 { "m","r"};
1445 #else
1446 char *suffixes[] = { "" };
1447 #endif
1448 char *suffix = suffixes[0];
1449
1450 int suffix_count = sizeof(suffixes) / sizeof(char *);
1451 int i;
1452 char r[] = "r"; /* Used to make compiler happy due to Bug 35903 in gcc */
1453 main_init(argv[0]);
1454 struct zip_info *zip_info = NULL;
1455 int suffix_start = 0;
1456 char *timestamp = current_to_iso8601();
1457 char *url = NULL;
1458 #ifndef HAVE_GLIB
1459 // _g_slice_thread_init_nomessage();
1460 #endif
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
1475 while (1)
1476 {
1477 #if 0
1478 int this_option_optind = optind ? optind : 1;
1479 #endif
1480 int option_index = 0;
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' },
1482 #ifdef HAVE_POSTGRESQL
1483 { "db", 1, 0, 'd'},
1484 #endif
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' },
1486 // { "protobuf", 0, 0, 'P' },
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 } };
1488 c = getopt_long(argc, argv, "5:6B:DF:NO:PWS:a:bc"
1489 #ifdef HAVE_POSTGRESQL
1490 "d:"
1491 #endif
1492 "e:fghj:i:knm:p:r:s:wvu:z:UXYZ", long_options, &option_index);
1493 if (c == -1)
1494 {
1495 break;
1496 }
1497
1498 switch (c)
1499 {
1500 case '5':
1501 md5file = optarg;
1502 break;
1503 case '6':
1504 fprintf(stderr, "I will generate a ZIP64 map\n");
1505 zip64 = 1;
1506 break;
1507 //case 'B':
1508 // protobufdb = optarg;
1509 // break;
1510 case 'D':
1511 output = 1;
1512 break;
1513 case 'N':
1514 process_ways = 0;
1515 break;
1516 case 'R':
1517 process_relations = 0;
1518 break;
1519 //case 'O':
1520 // protobufdb_operation = optarg;
1521 // output = 1;
1522 // break;
1523 //case 'P':
1524 // protobuf = 1;
1525 // break;
1526 case 'S':
1527 slice_size = atoll(optarg);
1528 break;
1529 case 'W':
1530 process_nodes = 0;
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;
1555 case 'a':
1556 attr_debug_level = atoi(optarg);
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;
1570 case 'b':
1571 input = 1;
1572 break;
1573 case 'c':
1574 dump_coordinates = 1;
1575 break;
1576 #ifdef HAVE_POSTGRESQL
1577 case 'd':
1578 dbstr=optarg;
1579 break;
1580 #endif
1581 case 'e':
1582 end = atoi(optarg);
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;
1592 case 'h':
1593 usage(stdout);
1594 break;
1595 case 'm':
1596 optarg_cp = g_strdup(optarg);
1597 pos = 0;
1598 i = 0;
1599 attr_name = g_strdup(optarg);
1600 attr_value = g_strdup(optarg);
1601 while (i < 9 && attr_from_line(optarg_cp, NULL, &pos, attr_value, attr_name))
1602 {
1603 attrs[i] = attr_new_from_text(attr_name, attr_value);
1604 if (attrs[i])
1605 {
1606 i++;
1607 }
1608 else
1609 {
1610 fprintf(stderr, "Failed to convert %s=%s to attribute\n", attr_name, attr_value);
1611 }
1612 attr_value = g_strdup(optarg);
1613 }
1614 attrs[i++] = NULL;
1615 g_free(attr_value);
1616 g_free(optarg_cp);
1617 handle = map_new(NULL, attrs);
1618 if (!handle)
1619 {
1620 fprintf(stderr, "Failed to create map from attributes\n");
1621 exit(1);
1622 }
1623 map_handles = g_list_append(map_handles, handle);
1624 break;
1625 case 'n':
1626 fprintf(stderr, "I will IGNORE unknown types\n");
1627 ignore_unkown = 1;
1628 break;
1629 case 'k':
1630 fprintf(stderr, "I will KEEP tmp files\n");
1631 keep_tmpfiles = 1;
1632 break;
1633 case 'p':
1634 add_plugin(optarg);
1635 break;
1636 case 's':
1637 start = atoi(optarg);
1638 break;
1639 case 'w':
1640 // dedupe_ways_hash = g_hash_table_new(NULL, NULL);
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;
1650 case 'i':
1651 input_file = fopen(optarg, "r");
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++)
1853 {
1854 if ((cur_thread_num + ij + 1) <= threads)
1855 {
1856 if (thread_is_working_[cur_thread_num + ij] == 0)
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 }
1863 }
1864 else
1865 {
1866 if (thread_is_working_[cur_thread_num + ij - threads] == 0)
1867 {
1868 cur_thread_num = cur_thread_num + ij - threads;
1869 fprintf(stderr, "found free thread #%d\n", cur_thread_num);
1870 pthread_join(thread_[cur_thread_num], NULL);
1871 break;
1872 }
1873 }
1874 }
1875 }
1876
1877 if (thread_is_working_[cur_thread_num] == 1)
1878 {
1879 time(&start_tt);
1880
1881 fprintf(stderr, "need to wait for thread #%d to finish first ...\n", cur_thread_num);
1882 //iret_[cur_thread_num] = g_thread_join(thread_[cur_thread_num]);
1883 pthread_join(thread_[cur_thread_num], NULL);
1884 //thread_is_working_[cur_thread_num] = 0;
1885 if (verbose_mode)
1886 printf("Thread %d returns: %d\n", cur_thread_num, iret_[cur_thread_num]);
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);
1900 }
1901 }
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
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 }
2083 fclose(ways);
2084 fclose(graph);
2085 fclose(coastline);
2086 if (!final)
2087 {
2088 // rename to "ways_to_resolve" and use that as new input
2089 tempfile_rename(suffix, "ways_split", "ways_to_resolve");
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");
2099 }
2100 }
2101
2102 time(&end_tt);
2103 diff_tt = difftime(end_tt, start_tt);
2104 char outstring[200];
2105 convert_to_human_time(diff_tt, outstring);
2106 fprintf(stderr, "-RUNTIME-LOOP2: %s this loop run\n", outstring);
2107 diff2_tt = diff2_tt + diff_tt;
2108 if ((i + 1) > 0)
2109 {
2110 double eta_time = (diff2_tt / (i + 1)) * (slices99 - (i + 1));
2111 convert_to_human_time(eta_time, outstring);
2112 fprintf(stderr, "-RUNTIME-LOOP2: %s left\n", outstring);
2113 }
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);
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 {
2407 tempfile_unlink(suffix, "ways_split_index");
2408 }
2409
2410 if (output == 1)
2411 {
2412 fprintf(stderr, "PROGRESS: Phase 4: dumping\n");
2413 if (process_nodes)
2414 {
2415 nodes = tempfile(suffix, "nodes", 0);
2416 if (nodes)
2417 {
2418 dump(nodes);
2419 fclose(nodes);
2420 }
2421 }
2422 if (process_ways)
2423 {
2424 ways_split = tempfile(suffix, "ways_split", 0);
2425 if (ways_split)
2426 {
2427 dump(ways_split);
2428 fclose(ways_split);
2429 }
2430 }
2431 if (process_relations)
2432 {
2433 relations = tempfile(suffix, "relations", 0);
2434 if (relations)
2435 {
2436 dump(relations);
2437 fclose(relations);
2438 }
2439 }
2440 exit(0);
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
2469 for (i = suffix_start; i < suffix_count; i++)
2470 {
2471 suffix = suffixes[i];
2472 if (start <= 4)
2473 {
2474 phase = 3;
2475 if (i == suffix_start)
2476 {
2477 zip_info = zip_new();
2478 zip_set_zip64(zip_info, zip64);
2479 zip_set_timestamp(zip_info, timestamp);
2480 }
2481 zipnum = zip_get_zipnum(zip_info);
2482 fprintf(stderr, "PROGRESS: Phase 4: generating tiles %s\n", suffix);
2483 tilesdir = tempfile(suffix, "tilesdir", 1);
2484 if (!strcmp(suffix, r))
2485 { /* Makes compiler happy due to bug 35903 in gcc */
2486 ch_generate_tiles(suffixes[0], suffix, tilesdir, zip_info);
2487 }
2488 else
2489 {
2490 for (f = 0; f < 3; f++)
2491 {
2492 files[f] = NULL;
2493 }
2494 if (process_relations)
2495 {
2496 files[0] = tempfile(suffix, "relations", 0);
2497 }
2498 if (process_ways)
2499 {
2500 files[1] = tempfile(suffix, "ways_split", 0);
2501 }
2502 if (process_nodes)
2503 {
2504 files[2] = tempfile(suffix, "nodes", 0);
2505 }
2506
2507 time(&start_tt);
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
2515 for (f = 0; f < 3; f++)
2516 {
2517 if (files[f])
2518 {
2519 fclose(files[f]);
2520 }
2521 }
2522 }
2523 fclose(tilesdir);
2524 zip_set_zipnum(zip_info, zipnum);
2525 }
2526
2527 if (end == 4)
2528 exit(0);
2529
2530 if (zip_info)
2531 {
2532 zip_destroy(zip_info);
2533 zip_info = NULL;
2534 }
2535
2536 if (start <= 5)
2537 {
2538 phase = 4;
2539 fprintf(stderr, "PROGRESS: Phase 5: assembling map %s\n", suffix);
2540 if (i == suffix_start)
2541 {
2542 char *zipdir = tempfile_name("zipdir", "");
2543 char *zipindex = tempfile_name("index", "");
2544 zip_info = zip_new();
2545 zip_set_zip64(zip_info, zip64);
2546 zip_set_timestamp(zip_info, timestamp);
2547 zip_set_maxnamelen(zip_info, 14 + strlen(suffixes[0]));
2548 zip_set_compression_level(zip_info, compression_level);
2549
2550 if (md5file)
2551 {
2552 zip_set_md5(zip_info, 1);
2553 }
2554
2555 zip_open(zip_info, result, zipdir, zipindex);
2556
2557 if (url)
2558 {
2559 map_information_attrs[1].type = attr_url;
2560 map_information_attrs[1].u.str = url;
2561 }
2562 index_init(zip_info, 1);
2563 }
2564
2565 if (!strcmp(suffix, r))
2566 { /* Makes compiler happy due to bug 35903 in gcc */
2567 ch_assemble_map(suffixes[0], suffix, zip_info);
2568 }
2569 else
2570 {
2571 for (f = 0; f < 3; f++)
2572 {
2573 files[f] = NULL;
2574 references[f] = NULL;
2575 }
2576
2577 if (process_relations)
2578 {
2579 files[0] = tempfile(suffix, "relations", 0);
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
2588 if (process_nodes)
2589 {
2590 files[2] = tempfile(suffix, "nodes", 0);
2591 }
2592
2593 fprintf(stderr, "Slice %d\n", i);
2594
2595 time(&start_tt);
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
2603 for (f = 0; f < 3; f++)
2604 {
2605 if (files[f])
2606 {
2607 fclose(files[f]);
2608 }
2609 if (references[f])
2610 {
2611 fclose(references[f]);
2612 }
2613 }
2614 }
2615
2616 if (!keep_tmpfiles)
2617 {
2618 tempfile_unlink(suffix, "relations");
2619 tempfile_unlink(suffix, "nodes");
2620 tempfile_unlink(suffix, "ways_split");
2621 tempfile_unlink(suffix, "ways_split_ref");
2622 tempfile_unlink(suffix, "ways_with_coords");
2623 tempfile_unlink(suffix, "coastline");
2624 tempfile_unlink(suffix, "turn_restrictions");
2625 tempfile_unlink(suffix, "graph");
2626 tempfile_unlink(suffix, "tilesdir");
2627 tempfile_unlink(suffix, "boundaries");
2628 tempfile_unlink(suffix, "relations_riverbank");
2629 tempfile_unlink(suffix, "coastline_result");
2630
2631 unlink("coords.tmp");
2632 }
2633
2634 if (i == suffix_count - 1)
2635 {
2636 unsigned char md5_data[16];
2637
2638 zipnum = zip_get_zipnum(zip_info);
2639 add_aux_tiles("auxtiles.txt", zip_info);
2640
2641 write_countrydir(zip_info);
2642 zip_set_zipnum(zip_info, zipnum);
2643 write_aux_tiles(zip_info);
2644 zip_write_index(zip_info);
2645 zip_write_directory(zip_info);
2646 zip_close(zip_info);
2647
2648 if (md5file && zip_get_md5(zip_info, md5_data))
2649 {
2650 FILE *md5 = fopen(md5file, "w");
2651 int i;
2652 for (i = 0; i < 16; i++)
2653 {
2654 fprintf(md5, "%02x", md5_data[i]);
2655 }
2656 fprintf(md5, "\n");
2657 fclose(md5);
2658 }
2659
2660 if (!keep_tmpfiles)
2661 {
2662 remove_countryfiles();
2663 tempfile_unlink("index", "");
2664 tempfile_unlink("zipdir", "");
2665 }
2666 }
2667 }
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
2686 return 0;
2687 }
2688

   
Visit the ZANavi Wiki