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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

   
Visit the ZANavi Wiki