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