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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

   
Visit the ZANavi Wiki