1 |
/**
|
2 |
* ZANavi, Zoff Android Navigation system.
|
3 |
* Copyright (C) 2011-2012 Zoff <zoff@zoff.cc>
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* version 2 as published by the Free Software Foundation.
|
8 |
*
|
9 |
* This program is distributed in the hope that it will be useful,
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
* GNU General Public License for more details.
|
13 |
*
|
14 |
* You should have received a copy of the GNU General Public License
|
15 |
* along with this program; if not, write to the
|
16 |
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
17 |
* Boston, MA 02110-1301, USA.
|
18 |
*/
|
19 |
|
20 |
/**
|
21 |
* Navit, a modular navigation system.
|
22 |
* Copyright (C) 2005-2011 Navit Team
|
23 |
*
|
24 |
* This program is free software; you can redistribute it and/or
|
25 |
* modify it under the terms of the GNU General Public License
|
26 |
* version 2 as published by the Free Software Foundation.
|
27 |
*
|
28 |
* This program is distributed in the hope that it will be useful,
|
29 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
30 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
31 |
* GNU General Public License for more details.
|
32 |
*
|
33 |
* You should have received a copy of the GNU General Public License
|
34 |
* along with this program; if not, write to the
|
35 |
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
36 |
* Boston, MA 02110-1301, USA.
|
37 |
*/
|
38 |
#include <glib.h>
|
39 |
#include "config.h"
|
40 |
#include "coord.h"
|
41 |
#include "item.h"
|
42 |
#include "attr.h"
|
43 |
#include <setjmp.h>
|
44 |
#ifdef HAVE_LIBCRYPTO
|
45 |
#include <openssl/md5.h>
|
46 |
#endif
|
47 |
|
48 |
#define MAX_THREADS 8
|
49 |
|
50 |
|
51 |
#define MAPTOOL_SQL_INPUT_TOO_SMALL 0 // only set this to 1 for testing very small input files!!!!!!
|
52 |
|
53 |
#define MAPTOOL_USE_SQL 1 // if u want to use SQL and all the related stuff
|
54 |
#define MAPTOOL_USE_STRINDEX_COMPRESSION 1 // use street index compression
|
55 |
// #define MAPTOOL_USE_ASYNC_SQL 1 // sql writes are done in async thread
|
56 |
#define USE_STREET_INDEX_COMPRESSION 1
|
57 |
#define MAPTOOL_TRIANGULATE 1 // use polygon to triangle conversion
|
58 |
// #define MAPTOOL_SPLIT_NODE_DB 1 // split up node sql db
|
59 |
// #define MAPTOOL_SPLIT_NODE_DB_MORE 1 // split up node sql db into 2 more files
|
60 |
#define MAPTOOL_SPLIT_NODE_BIT 268435456 // split up at bit X (set value of bit e.g. 64)
|
61 |
//#define MAPTOOL_SPLIT_WAYNODE_DB 1 // split up way-node sql db
|
62 |
#define MAPTOOL_SPLIT_WAYNODE_BIT 2 // split up at bit X
|
63 |
#define MAPTOOL_SPLIT_WAYNODE_BIT2 256 // split up at bit X
|
64 |
|
65 |
// cfu hash
|
66 |
#include "cfuhash.h"
|
67 |
|
68 |
#define CFUHASH_BUCKETS_NODES 16777216
|
69 |
#define CFUHASH_BUCKETS_WAYS 16777216
|
70 |
#define CFUHASH_BUCKETS_OTHER 16777216 // also nodes!?
|
71 |
|
72 |
// sqlite 3
|
73 |
#ifdef MAPTOOL_USE_SQL
|
74 |
|
75 |
#define SQLITE_ENABLE_STAT3
|
76 |
#define SQLITE_OMIT_AUTOVACUUM
|
77 |
#define SQLITE_OMIT_AUTOMATIC_INDEX
|
78 |
|
79 |
#include "sqlite3.h"
|
80 |
#include "sqlite3async.h"
|
81 |
|
82 |
extern sqlite3 *sql_handle;
|
83 |
extern sqlite3 *sql_handle002a;
|
84 |
extern sqlite3 *sql_handle003a;
|
85 |
extern sqlite3 *sql_handle002b;
|
86 |
extern sqlite3 *sql_handle003b;
|
87 |
extern sqlite3 *sql_handle004;
|
88 |
extern sqlite3 *sql_handle005;
|
89 |
extern sqlite3 *sql_handle006;
|
90 |
extern sqlite3 *sql_handle007;
|
91 |
#else
|
92 |
extern void *sql_handle;
|
93 |
extern void *sql_handle002a;
|
94 |
extern void *sql_handle003a;
|
95 |
extern void *sql_handle002b;
|
96 |
extern void *sql_handle003b;
|
97 |
extern void *sql_handle004;
|
98 |
extern void *sql_handle005;
|
99 |
extern void *sql_handle006;
|
100 |
extern void *sql_handle007;
|
101 |
#endif
|
102 |
|
103 |
int sql_counter;
|
104 |
int sql_counter2;
|
105 |
int sql_counter3;
|
106 |
int sql_counter4;
|
107 |
#define MAX_ROWS_WO_COMMIT 140000 // nodes
|
108 |
#define MAX_ROWS_WO_COMMIT_2 1000 // town to streets (2)
|
109 |
#define MAX_ROWS_WO_COMMIT_2a 100 // town to streets (1)
|
110 |
#define MAX_ROWS_WO_COMMIT_2b 10000 // town to streets (with boundaries)
|
111 |
#define MAX_ROWS_WO_COMMIT_3 90000 // ways
|
112 |
#define MAX_ROWS_WO_COMMIT_4 220000 // waynodes
|
113 |
#define MAX_ROWS_WO_COMMIT_5 6000 // towns to country
|
114 |
// sqlite 3
|
115 |
|
116 |
#ifdef HAVE_API_WIN32_BASE
|
117 |
#define LONGLONG_FMT "%I64d"
|
118 |
#else
|
119 |
#define LONGLONG_FMT "%lld"
|
120 |
#endif
|
121 |
|
122 |
#define sq(x) ((double)(x)*(x))
|
123 |
|
124 |
#define BUFFER_SIZE 1280
|
125 |
|
126 |
#define debug_tile(x) 0
|
127 |
#define debug_itembin(x) 0
|
128 |
|
129 |
// ---------EXCEPTIONS--------
|
130 |
char stack[SIGSTKSZ];
|
131 |
struct sigaction sa;
|
132 |
stack_t ss;
|
133 |
void catch_signal(int param);
|
134 |
|
135 |
jmp_buf ex_buf__; // global var!
|
136 |
|
137 |
// #define TRY do{ jmp_buf ex_buf__; switch( setjmp(ex_buf__) ){ case 0: while(1){
|
138 |
#define TRY do{ switch( setjmp(ex_buf__) ){ case 0: while(1){
|
139 |
#define CATCH(x) break; case x:
|
140 |
#define FINALLY break; } default:
|
141 |
#define ETRY } }while(0)
|
142 |
#define THROW(x) longjmp(ex_buf__, x)
|
143 |
|
144 |
#define MAPTOOL_00001_EXCEPTION (1)
|
145 |
#define MAPTOOL_00002_EXCEPTION (2)
|
146 |
#define MAPTOOL_00003_EXCEPTION (3)
|
147 |
// ---------EXCEPTIONS--------
|
148 |
|
149 |
|
150 |
#ifdef MAPTOOL_USE_SQL
|
151 |
sqlite3_stmt *stmt_nodea;
|
152 |
sqlite3_stmt *stmt_node__2a;
|
153 |
sqlite3_stmt *stmt_nodeb;
|
154 |
sqlite3_stmt *stmt_node__2b;
|
155 |
sqlite3_stmt *stmt_nodei;
|
156 |
sqlite3_stmt *stmt_way;
|
157 |
sqlite3_stmt *stmt_way2;
|
158 |
sqlite3_stmt *stmt_way_node;
|
159 |
sqlite3_stmt *stmt_way_node__2;
|
160 |
sqlite3_stmt *stmt_way_nodeb;
|
161 |
sqlite3_stmt *stmt_way_node__2b;
|
162 |
sqlite3_stmt *stmt_way3;
|
163 |
sqlite3_stmt *stmt_way3a;
|
164 |
sqlite3_stmt *stmt_way3b;
|
165 |
sqlite3_stmt *stmt_town_sel001;
|
166 |
sqlite3_stmt *stmt_sel001;
|
167 |
sqlite3_stmt *stmt_sel001__2;
|
168 |
sqlite3_stmt *stmt_sel001b;
|
169 |
sqlite3_stmt *stmt_sel001__2b;
|
170 |
sqlite3_stmt *stmt_sel0012;
|
171 |
sqlite3_stmt *stmt_sel0012__2;
|
172 |
sqlite3_stmt *stmt_sel0012b;
|
173 |
sqlite3_stmt *stmt_sel0012__2b;
|
174 |
sqlite3_stmt *stmt_sel002a;
|
175 |
sqlite3_stmt *stmt_sel002__2a;
|
176 |
sqlite3_stmt *stmt_sel002b;
|
177 |
sqlite3_stmt *stmt_sel002__2b;
|
178 |
sqlite3_stmt *stmt_town_sel002;
|
179 |
sqlite3_stmt *stmt_town_sel005;
|
180 |
sqlite3_stmt *stmt_town_sel006;
|
181 |
sqlite3_stmt *stmt_town_sel007;
|
182 |
sqlite3_stmt *stmt_town_sel008;
|
183 |
sqlite3_stmt *stmt_town;
|
184 |
sqlite3_stmt *stmt_sel003;
|
185 |
sqlite3_stmt *stmt_sel003u;
|
186 |
sqlite3_stmt *stmt_sel004;
|
187 |
sqlite3_stmt *stmt_bd_001;
|
188 |
sqlite3_stmt *stmt_bd_002;
|
189 |
sqlite3_stmt *stmt_bd_003;
|
190 |
sqlite3_stmt *stmt_bd_004;
|
191 |
sqlite3_stmt *stmt_bd_005;
|
192 |
sqlite3_stmt *stmt_sel0012_tt[MAX_THREADS];
|
193 |
sqlite3_stmt *stmt_sel0012__2_tt[MAX_THREADS];
|
194 |
sqlite3_stmt *stmt_sel0012b_tt[MAX_THREADS];
|
195 |
sqlite3_stmt *stmt_sel0012__2b_tt[MAX_THREADS];
|
196 |
#else
|
197 |
|
198 |
typedef void sqlite3_stmt;
|
199 |
|
200 |
void *stmt_nodea;
|
201 |
void *stmt_node__2a;
|
202 |
void *stmt_nodeb;
|
203 |
void *stmt_node__2b;
|
204 |
void *stmt_nodei;
|
205 |
void *stmt_way;
|
206 |
void *stmt_way2;
|
207 |
void *stmt_way_node;
|
208 |
void *stmt_way_node__2;
|
209 |
void *stmt_way_nodeb;
|
210 |
void *stmt_way_node__2b;
|
211 |
void *stmt_way3;
|
212 |
void *stmt_way3a;
|
213 |
void *stmt_way3b;
|
214 |
void *stmt_town_sel001;
|
215 |
void *stmt_sel001;
|
216 |
void *stmt_sel001__2;
|
217 |
void *stmt_sel001b;
|
218 |
void *stmt_sel001__2b;
|
219 |
void *stmt_sel0012;
|
220 |
void *stmt_sel0012__2;
|
221 |
void *stmt_sel0012b;
|
222 |
void *stmt_sel0012__2b;
|
223 |
void *stmt_sel002a;
|
224 |
void *stmt_sel002__2a;
|
225 |
void *stmt_sel002b;
|
226 |
void *stmt_sel002__2b;
|
227 |
void *stmt_town_sel002;
|
228 |
void *stmt_town_sel005;
|
229 |
void *stmt_town_sel006;
|
230 |
void *stmt_town_sel007;
|
231 |
void *stmt_town_sel008;
|
232 |
void *stmt_town;
|
233 |
void *stmt_sel003;
|
234 |
void *stmt_sel003u;
|
235 |
void *stmt_sel004;
|
236 |
void *stmt_bd_001;
|
237 |
void *stmt_bd_002;
|
238 |
void *stmt_bd_003;
|
239 |
void *stmt_bd_004;
|
240 |
void *stmt_bd_005;
|
241 |
void *stmt_sel0012_tt[MAX_THREADS];
|
242 |
void *stmt_sel0012__2_tt[MAX_THREADS];
|
243 |
void *stmt_sel0012b_tt[MAX_THREADS];
|
244 |
void *stmt_sel0012__2b_tt[MAX_THREADS];
|
245 |
|
246 |
|
247 |
#define SQLITE_STATIC 1
|
248 |
#define SQLITE_ROW 2
|
249 |
#define SQLITE_DONE 3
|
250 |
int sqlite3_reset(void*);
|
251 |
int sqlite3_step(void*);
|
252 |
int sqlite3_exec(void*,void*, void*, void*,void*);
|
253 |
int sqlite3_bind_int64(void*, int, long);
|
254 |
int sqlite3_bind_int(void*, int, int);
|
255 |
int sqlite3_bind_double(void*, int, double);
|
256 |
long sqlite3_column_int64(void*, int);
|
257 |
double sqlite3_column_double(void*, int);
|
258 |
int sqlite3_column_int(void*, int);
|
259 |
int sqlite3_bind_text(void*, int, char*, int, int);
|
260 |
|
261 |
#endif
|
262 |
|
263 |
#define TOWN_BY_BOUNDARY_SIZE_FACTOR 1000000
|
264 |
#define TOWN_ADMIN_LEVEL_CORR_BASE 99999
|
265 |
#define TOWN_ADMIN_LEVEL_START 8
|
266 |
|
267 |
long long ways_processed_count;
|
268 |
|
269 |
struct rect
|
270 |
{
|
271 |
struct coord l, h;
|
272 |
};
|
273 |
|
274 |
struct rect_lat_lon
|
275 |
{
|
276 |
double lu_lat;
|
277 |
double lu_lon;
|
278 |
double rl_lat;
|
279 |
double rl_lon;
|
280 |
};
|
281 |
|
282 |
struct node_lat_lon
|
283 |
{
|
284 |
double lat;
|
285 |
double lon;
|
286 |
int valid; // 0 -> invalid, 1 -> valid
|
287 |
};
|
288 |
|
289 |
struct tile_data
|
290 |
{
|
291 |
char buffer[1024];
|
292 |
int tile_depth;
|
293 |
struct rect item_bbox;
|
294 |
struct rect tile_bbox;
|
295 |
};
|
296 |
|
297 |
struct tile_parameter
|
298 |
{
|
299 |
int min;
|
300 |
int max;
|
301 |
int overlap;
|
302 |
};
|
303 |
|
304 |
struct tile_info
|
305 |
{
|
306 |
int write;
|
307 |
int maxlen;
|
308 |
char *suffix;
|
309 |
GList **tiles_list;
|
310 |
FILE *tilesdir_out;
|
311 |
};
|
312 |
|
313 |
extern struct tile_head
|
314 |
{
|
315 |
int num_subtiles;
|
316 |
int total_size;
|
317 |
char *name;
|
318 |
char *zip_data;
|
319 |
int total_size_used;
|
320 |
int zipnum;
|
321 |
int process;
|
322 |
struct tile_head *next;
|
323 |
// char subtiles[0];
|
324 |
}*tile_head_root;
|
325 |
|
326 |
struct item_bin
|
327 |
{
|
328 |
int len;
|
329 |
enum item_type type;
|
330 |
int clen;
|
331 |
};
|
332 |
|
333 |
struct attr_bin
|
334 |
{
|
335 |
int len;
|
336 |
enum attr_type type;
|
337 |
};
|
338 |
|
339 |
struct item_bin_sink_func
|
340 |
{
|
341 |
int (*func)(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data);
|
342 |
void *priv_data[8];
|
343 |
};
|
344 |
|
345 |
struct item_bin_sink
|
346 |
{
|
347 |
void *priv_data[8];
|
348 |
GList *sink_funcs;
|
349 |
};
|
350 |
|
351 |
typedef long long osmid;
|
352 |
|
353 |
struct node_item
|
354 |
{
|
355 |
osmid id;
|
356 |
char ref_node;
|
357 |
char ref_way;
|
358 |
char ref_ref;
|
359 |
char dummy;
|
360 |
struct coord c;
|
361 |
};
|
362 |
|
363 |
struct way_tag
|
364 |
{
|
365 |
long long way_id;
|
366 |
int tag_id;
|
367 |
};
|
368 |
|
369 |
struct relation_member
|
370 |
{
|
371 |
int type;
|
372 |
long long id;
|
373 |
char *role;
|
374 |
};
|
375 |
|
376 |
struct zip_info;
|
377 |
struct country_table;
|
378 |
|
379 |
/* boundaries.c */
|
380 |
struct boundary
|
381 |
{
|
382 |
struct item_bin *ib;
|
383 |
struct country_table *country;
|
384 |
char *iso2;
|
385 |
GList *segments, *sorted_segments;
|
386 |
GList *children;
|
387 |
struct rect r;
|
388 |
};
|
389 |
|
390 |
char *osm_tag_value(struct item_bin *ib, char *key);
|
391 |
long long *boundary_relid(struct boundary *b);
|
392 |
GList *process_boundaries(FILE *boundaries, FILE *coords, FILE *ways);
|
393 |
void build_boundary_tree(GList *bl);
|
394 |
GList *boundary_find_matches(GList *bl, struct coord *c);
|
395 |
GList *boundary_find_matches_level(GList *l, struct coord *c, int min_admin_level, int max_admin_level);
|
396 |
GList *boundary_find_matches_single(GList *bl, struct coord *c);
|
397 |
void correct_boundary_ref_point(GList *bl);
|
398 |
|
399 |
/* buffer.c */
|
400 |
struct buffer
|
401 |
{
|
402 |
int malloced_step;
|
403 |
long long malloced;
|
404 |
unsigned char *base;
|
405 |
long long size;
|
406 |
};
|
407 |
|
408 |
void save_buffer(char *filename, struct buffer *b, long long offset);
|
409 |
void free_buffer(char *filename, struct buffer *b);
|
410 |
void load_buffer(char *filename, struct buffer *b, long long offset, long long size);
|
411 |
|
412 |
/* ch.c */
|
413 |
|
414 |
void ch_generate_tiles(char *map_suffix, char *suffix, FILE *tilesdir_out, struct zip_info *zip_info);
|
415 |
void ch_assemble_map(char *map_suffix, char *suffix, struct zip_info *zip_info);
|
416 |
|
417 |
/* coastline.c */
|
418 |
|
419 |
void process_coastlines(FILE *in, FILE *out);
|
420 |
|
421 |
/* geom.c */
|
422 |
|
423 |
enum geom_poly_segment_type
|
424 |
{
|
425 |
geom_poly_segment_type_none, geom_poly_segment_type_way_inner, geom_poly_segment_type_way_outer, geom_poly_segment_type_way_left_side, geom_poly_segment_type_way_right_side, geom_poly_segment_type_way_unknown,
|
426 |
|
427 |
};
|
428 |
|
429 |
struct geom_poly_segment
|
430 |
{
|
431 |
enum geom_poly_segment_type type;
|
432 |
struct coord *first, *last;
|
433 |
};
|
434 |
|
435 |
void geom_coord_copy(struct coord *from, struct coord *to, int count, int reverse);
|
436 |
void geom_coord_revert(struct coord *c, int count);
|
437 |
long long geom_poly_area(struct coord *c, int count);
|
438 |
GList *geom_poly_segments_insert(GList *list, struct geom_poly_segment *first, struct geom_poly_segment *second, struct geom_poly_segment *third);
|
439 |
void geom_poly_segment_destroy(struct geom_poly_segment *seg);
|
440 |
GList *geom_poly_segments_remove(GList *list, struct geom_poly_segment *seg);
|
441 |
int geom_poly_segment_compatible(struct geom_poly_segment *s1, struct geom_poly_segment *s2, int dir);
|
442 |
GList *geom_poly_segments_sort(GList *in, enum geom_poly_segment_type type);
|
443 |
struct geom_poly_segment *item_bin_to_poly_segment(struct item_bin *ib, int type);
|
444 |
int geom_poly_segments_point_inside(GList *in, struct coord *c);
|
445 |
void clip_line(struct item_bin *ib, struct rect *r, struct tile_parameter *param, struct item_bin_sink *out);
|
446 |
void clip_polygon(struct item_bin *ib, struct rect *r, struct tile_parameter *param, struct item_bin_sink *out);
|
447 |
int item_bin_is_closed_poly(struct item_bin *ib);
|
448 |
|
449 |
/* itembin.c */
|
450 |
|
451 |
int item_bin_read(struct item_bin *ib, FILE *in);
|
452 |
void item_bin_set_type(struct item_bin *ib, enum item_type type);
|
453 |
void item_bin_init(struct item_bin *ib, enum item_type type);
|
454 |
void item_bin_add_coord(struct item_bin *ib, struct coord *c, int count);
|
455 |
void item_bin_add_coord_reverse(struct item_bin *ib, struct coord *c, int count);
|
456 |
void item_bin_bbox(struct item_bin *ib, struct rect *r);
|
457 |
void item_bin_copy_coord(struct item_bin *ib, struct item_bin *from, int dir);
|
458 |
void item_bin_add_coord_rect(struct item_bin *ib, struct rect *r);
|
459 |
int attr_bin_write_data(struct attr_bin *ab, enum attr_type type, void *data, int size);
|
460 |
int attr_bin_write_attr(struct attr_bin *ab, struct attr *attr);
|
461 |
void item_bin_add_attr_data(struct item_bin *ib, enum attr_type type, void *data, int size);
|
462 |
void item_bin_add_attr(struct item_bin *ib, struct attr *attr);
|
463 |
void item_bin_add_attr_int(struct item_bin *ib, enum attr_type type, int val);
|
464 |
void *item_bin_get_attr(struct item_bin *ib, enum attr_type type, void *last);
|
465 |
struct attr_bin * item_bin_get_attr_bin_last(struct item_bin *ib);
|
466 |
void item_bin_add_attr_longlong(struct item_bin *ib, enum attr_type type, long long val);
|
467 |
void item_bin_add_attr_string(struct item_bin *ib, enum attr_type type, char *str);
|
468 |
void item_bin_add_attr_range(struct item_bin *ib, enum attr_type type, short min, short max);
|
469 |
void item_bin_remove_attr(struct item_bin *ib, void *ptr);
|
470 |
void item_bin_write(struct item_bin *ib, FILE *out);
|
471 |
void item_bin_write_xml(struct item_bin *ib, char *filename);
|
472 |
struct item_bin *item_bin_dup(struct item_bin *ib);
|
473 |
void item_bin_write_range(struct item_bin *ib, FILE *out, int min, int max);
|
474 |
void item_bin_write_clipped(struct item_bin *ib, struct tile_parameter *param, struct item_bin_sink *out);
|
475 |
void item_bin_dump(struct item_bin *ib, FILE *out);
|
476 |
void dump_itembin(struct item_bin *ib);
|
477 |
void item_bin_set_type_by_population(struct item_bin *ib, int population);
|
478 |
void item_bin_write_match(struct item_bin *ib, enum attr_type type, enum attr_type match, FILE *out);
|
479 |
void item_bin_town_write_match(struct item_bin *ib, enum attr_type type, enum attr_type match, FILE *out);
|
480 |
int item_bin_sort_file(char *in_file, char *out_file, struct rect *r, int *size);
|
481 |
|
482 |
/* itembin_buffer.c */
|
483 |
struct node_item *read_node_item(FILE *in, int local_thread_num);
|
484 |
struct item_bin *read_item(FILE *in, int local_thread_num);
|
485 |
struct item_bin *read_item_range(FILE *in, int *min, int *max, int local_thread_num);
|
486 |
struct item_bin *init_item(enum item_type type, int local_thread_num);
|
487 |
|
488 |
/* maptool.c */
|
489 |
|
490 |
extern long long slice_size;
|
491 |
extern int attr_debug_level;
|
492 |
extern char *suffix;
|
493 |
extern int ignore_unkown;
|
494 |
// extern GHashTable *dedupe_ways_hash;
|
495 |
extern int phase;
|
496 |
extern int slices;
|
497 |
|
498 |
extern FILE *ways_ref_file;
|
499 |
extern FILE *ways_ref_file_thread[MAX_THREADS];
|
500 |
|
501 |
extern struct buffer node_buffer[MAX_THREADS];
|
502 |
extern struct buffer waytag_buffer;
|
503 |
extern GHashTable *node_hash[MAX_THREADS];
|
504 |
extern
|
505 |
cfuhash_table_t *node_hash_cfu[MAX_THREADS];
|
506 |
|
507 |
extern char ib_buffer_array[MAX_THREADS][2400000]; // 2.4 MB max size for 1 item
|
508 |
|
509 |
extern int processed_nodes, processed_nodes_out, processed_ways, processed_relations, processed_tiles;
|
510 |
extern struct item_bin *item_bin;
|
511 |
extern int bytes_read;
|
512 |
extern int overlap;
|
513 |
extern int experimental;
|
514 |
extern int use_global_fixed_country_id;
|
515 |
extern int global_fixed_country_id;
|
516 |
extern int unknown_country;
|
517 |
void sig_alrm(int sig);
|
518 |
void sig_alrm_end(void);
|
519 |
extern int border_only_map;
|
520 |
extern int coastline_only_map;
|
521 |
extern int border_only_map_as_xml;
|
522 |
extern int verbose_mode;
|
523 |
extern long long dummy_town_id;
|
524 |
|
525 |
void convert_to_human_time(long long seconds, char *outstring);
|
526 |
void convert_to_human_bytes(long long bytes, char *outstring);
|
527 |
void convert_to_human_bytes2(long long bytes, char *outstring);
|
528 |
|
529 |
struct phase_001_thread_var
|
530 |
{
|
531 |
int thread_num;
|
532 |
int count;
|
533 |
FILE* file1;
|
534 |
};
|
535 |
|
536 |
// ------ STREET INDEX FILE ------
|
537 |
|
538 |
#define REF_X 1073741834 // lat
|
539 |
#define REF_Y 240000000 // lon
|
540 |
|
541 |
#define STREET_INDEX_STREET_NAME_SIZE 48 // (this value + 16) must be a 2^n number!!!
|
542 |
struct streets_index_index_block_start
|
543 |
{
|
544 |
long long count_of_index_blocks;
|
545 |
}__attribute__ ((packed));
|
546 |
|
547 |
struct streets_index_index_block
|
548 |
{
|
549 |
char first_letter;
|
550 |
long long offset;
|
551 |
long long len;
|
552 |
}__attribute__ ((packed));
|
553 |
|
554 |
struct streets_index_data_block
|
555 |
{
|
556 |
long long town_id;
|
557 |
int lat; // if (lat equals REF_X) --> then lon is a flag field:
|
558 |
// lon -> 1 --> item is TOWN
|
559 |
// lon -> ... for future use
|
560 |
int lon;
|
561 |
char street_name[STREET_INDEX_STREET_NAME_SIZE];
|
562 |
}__attribute__ ((packed));
|
563 |
// ------ STREET INDEX FILE ------
|
564 |
|
565 |
|
566 |
// ------ TOWN INDEX FILE ------
|
567 |
|
568 |
#define TOWN_INDEX_TOWN_NAME_SIZE 52 // (this value + 12) must be a 2^n number!!!
|
569 |
struct town_index_index_block_start
|
570 |
{
|
571 |
long long count_of_index_blocks;
|
572 |
}__attribute__ ((packed));
|
573 |
|
574 |
struct town_index_index_block
|
575 |
{
|
576 |
long long first_id;
|
577 |
long long offset;
|
578 |
long long len;
|
579 |
}__attribute__ ((packed));
|
580 |
|
581 |
struct town_index_data_block
|
582 |
{
|
583 |
long long town_id;
|
584 |
int country_id;
|
585 |
char town_name[TOWN_INDEX_TOWN_NAME_SIZE];
|
586 |
}__attribute__ ((packed));
|
587 |
// ------ TOWN INDEX FILE ------
|
588 |
|
589 |
|
590 |
/* misc.c */
|
591 |
extern struct rect world_bbox;
|
592 |
|
593 |
void bbox_extend(struct coord *c, struct rect *r);
|
594 |
void bbox(struct coord *c, int count, struct rect *r);
|
595 |
int contains_bbox(int xl, int yl, int xh, int yh, struct rect *r);
|
596 |
int bbox_contains_coord(struct rect *r, struct coord *c);
|
597 |
int bbox_contains_bbox(struct rect *out, struct rect *in);
|
598 |
long long bbox_area(struct rect const *r);
|
599 |
void phase1_map(GList *maps, FILE *out_ways, FILE *out_nodes);
|
600 |
void dump(FILE *in);
|
601 |
int phase4(FILE **in, int in_count, int with_range, char *suffix, FILE *tilesdir_out, struct zip_info *zip_info);
|
602 |
int phase5(FILE **in, FILE **references, int in_count, int with_range, char *suffix, struct zip_info *zip_info);
|
603 |
void process_binfile(FILE *in, FILE *out);
|
604 |
void add_aux_tiles(char *name, struct zip_info *info);
|
605 |
void cat(FILE *in, FILE *out);
|
606 |
|
607 |
/* osm.c */
|
608 |
|
609 |
extern long long seekpos_waynode[MAX_THREADS];
|
610 |
extern long long last_seekpos_waynode[MAX_THREADS];
|
611 |
extern osmid last_seek_wayid[MAX_THREADS];
|
612 |
|
613 |
struct maptool_osm
|
614 |
{
|
615 |
FILE *boundaries;
|
616 |
FILE *turn_restrictions;
|
617 |
FILE *nodes;
|
618 |
FILE *ways;
|
619 |
FILE *line2poi;
|
620 |
FILE *poly2poi;
|
621 |
FILE *towns;
|
622 |
FILE *relations_riverbank;
|
623 |
FILE *ways_with_coords;
|
624 |
};
|
625 |
|
626 |
void append_pre_resolved_ways(FILE *out, struct maptool_osm *osm2);
|
627 |
void osm_warning(char *type, long long id, int cont, char *fmt, ...);
|
628 |
void osm_add_tag(char *k, char *v);
|
629 |
void osm_add_node(osmid id, double lat, double lon);
|
630 |
void osm_add_way(osmid id);
|
631 |
void osm_add_relation(osmid id);
|
632 |
void osm_end_relation(struct maptool_osm *osm);
|
633 |
void osm_add_member(int type, osmid ref, char *role);
|
634 |
void osm_end_way(struct maptool_osm *osm);
|
635 |
void osm_end_node(struct maptool_osm *osm);
|
636 |
void osm_add_nd(osmid ref);
|
637 |
long long item_bin_get_id(struct item_bin *ib);
|
638 |
void flush_nodes(int final, int local_thread_num);
|
639 |
void sort_countries(int keep_tmpfiles);
|
640 |
void process_turn_restrictions(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out);
|
641 |
void clear_node_item_buffer(void);
|
642 |
void ref_ways(FILE *in, int local_thread_num);
|
643 |
void resolve_ways(FILE *in, FILE *out);
|
644 |
long long item_bin_get_nodeid(struct item_bin *ib);
|
645 |
long long item_bin_get_wayid(struct item_bin *ib);
|
646 |
long long item_bin_get_relationid(struct item_bin *ib);
|
647 |
FILE *resolve_ways_file(FILE *in, char *suffix, char *filename);
|
648 |
void process_way2poi(FILE *in, FILE *out, int type);
|
649 |
int map_find_intersections(FILE *in, FILE *out, FILE *out_index, FILE *out_graph, FILE *out_coastline, int final);
|
650 |
int copy_tags_to_ways(FILE *in, FILE *out, FILE *tags_in);
|
651 |
void write_countrydir(struct zip_info *zip_info);
|
652 |
GList* osm_process_towns(FILE *in, FILE *coords, FILE *boundaries, FILE *ways);
|
653 |
void load_countries(void);
|
654 |
void remove_countryfiles(void);
|
655 |
struct country_table * country_from_iso2(char *iso);
|
656 |
void osm_init(FILE*);
|
657 |
osmid get_waynode_num(osmid way_id, int coord_num, int local_thread_num);
|
658 |
void map_find_housenumbers_interpolation(FILE *in, FILE *out);
|
659 |
|
660 |
extern struct item_bin *item_bin_2;
|
661 |
|
662 |
/* osm_psql.c */
|
663 |
int map_collect_data_osm_db(char *dbstr, struct maptool_osm *osm);
|
664 |
|
665 |
/* osm_protobuf.c */
|
666 |
//int map_collect_data_osm_protobuf(FILE *in, struct maptool_osm *osm);
|
667 |
//int osm_protobufdb_load(FILE *in, char *dir);
|
668 |
|
669 |
/* osm_relations.c */
|
670 |
struct relations * relations_new(void);
|
671 |
struct relations_func *relations_func_new(void(*func)(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv), void *func_priv);
|
672 |
void relations_add_func(struct relations *rel, struct relations_func *func, void *relation_priv, void *member_priv, int type, osmid id);
|
673 |
void relations_process(struct relations *rel, FILE *nodes, FILE *ways, FILE *relations);
|
674 |
|
675 |
/* osm_xml.c */
|
676 |
int osm_xml_get_attribute(char *xml, char *attribute, char *buffer, int buffer_size);
|
677 |
void osm_xml_decode_entities(char *buffer);
|
678 |
int map_collect_data_osm(FILE *in, struct maptool_osm *osm);
|
679 |
|
680 |
/* sourcesink.c */
|
681 |
|
682 |
struct item_bin_sink *item_bin_sink_new(void);
|
683 |
struct item_bin_sink_func *item_bin_sink_func_new(int(*func)(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data));
|
684 |
void item_bin_sink_func_destroy(struct item_bin_sink_func *func);
|
685 |
void item_bin_sink_add_func(struct item_bin_sink *sink, struct item_bin_sink_func *func);
|
686 |
void item_bin_sink_destroy(struct item_bin_sink *sink);
|
687 |
int item_bin_write_to_sink(struct item_bin *ib, struct item_bin_sink *sink, struct tile_data *tile_data);
|
688 |
struct item_bin_sink *file_reader_new(FILE *in, int limit, int offset);
|
689 |
int file_reader_finish(struct item_bin_sink *sink);
|
690 |
int file_writer_process(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data);
|
691 |
struct item_bin_sink_func *file_writer_new(FILE *out);
|
692 |
int file_writer_finish(struct item_bin_sink_func *file_writer);
|
693 |
int tile_collector_process(struct item_bin_sink_func *tile_collector, struct item_bin *ib, struct tile_data *tile_data);
|
694 |
struct item_bin_sink_func *tile_collector_new(struct item_bin_sink *out);
|
695 |
|
696 |
/* tempfile.c */
|
697 |
|
698 |
char *tempfile_name(char *suffix, char *name);
|
699 |
FILE *tempfile(char *suffix, char *name, int mode);
|
700 |
void tempfile_unlink(char *suffix, char *name);
|
701 |
void tempfile_rename(char *suffix, char *from, char *to);
|
702 |
|
703 |
/* tile.c */
|
704 |
extern GHashTable *tile_hash, *tile_hash2;
|
705 |
|
706 |
struct aux_tile
|
707 |
{
|
708 |
char *name;
|
709 |
char *filename;
|
710 |
int size;
|
711 |
};
|
712 |
|
713 |
extern GList *aux_tile_list;
|
714 |
|
715 |
int tile(struct rect *r, char *suffix, char *ret, int max, int overlap, struct rect *tr);
|
716 |
void tile_bbox(char *tile, struct rect *r, int overlap);
|
717 |
int tile_len(char *tile);
|
718 |
void tile_write_item_to_tile(struct tile_info *info, struct item_bin *ib, FILE *reference, char *name);
|
719 |
void tile_write_item_minmax(struct tile_info *info, struct item_bin *ib, FILE *reference, int min, int max);
|
720 |
int add_aux_tile(struct zip_info *zip_info, char *name, char *filename, int size);
|
721 |
int write_aux_tiles(struct zip_info *zip_info);
|
722 |
int create_tile_hash(void);
|
723 |
void write_tilesdir(struct tile_info *info, struct zip_info *zip_info, FILE *out);
|
724 |
void merge_tiles(struct tile_info *info);
|
725 |
struct attr map_information_attrs[32];
|
726 |
void index_init(struct zip_info *info, int version);
|
727 |
void index_submap_add(struct tile_info *info, struct tile_head *th);
|
728 |
|
729 |
/* zip.c */
|
730 |
void write_zipmember(struct zip_info *zip_info, char *name, int filelen, char *data, int data_size);
|
731 |
void zip_write_index(struct zip_info *info);
|
732 |
int zip_write_directory(struct zip_info *info);
|
733 |
struct zip_info *zip_new(void);
|
734 |
void zip_set_md5(struct zip_info *info, int on);
|
735 |
int zip_get_md5(struct zip_info *info, unsigned char *out);
|
736 |
void zip_set_zip64(struct zip_info *info, int on);
|
737 |
void zip_set_compression_level(struct zip_info *info, int level);
|
738 |
void zip_set_maxnamelen(struct zip_info *info, int max);
|
739 |
int zip_get_maxnamelen(struct zip_info *info);
|
740 |
int zip_add_member(struct zip_info *info);
|
741 |
int zip_set_timestamp(struct zip_info *info, char *timestamp);
|
742 |
int zip_set_password(struct zip_info *info, char *password);
|
743 |
void zip_open(struct zip_info *info, char *out, char *dir, char *index);
|
744 |
FILE *zip_get_index(struct zip_info *info);
|
745 |
int zip_get_zipnum(struct zip_info *info);
|
746 |
void zip_set_zipnum(struct zip_info *info, int num);
|
747 |
void zip_close(struct zip_info *info);
|
748 |
void zip_destroy(struct zip_info *info);
|
749 |
|
750 |
|
751 |
// color codes for colour attribute in OS;
|
752 |
|
753 |
unsigned int color_int_value_from_string(char* color_str);
|
754 |
|
755 |
struct css_color
|
756 |
{
|
757 |
char *col_name;
|
758 |
unsigned int col_value;
|
759 |
};
|
760 |
|
761 |
/*
|
762 |
unsinged int color_int;
|
763 |
|
764 |
unsinged int b=color_int & 0xff;
|
765 |
unsinged int g=(color_int >> 8) & 0xff;
|
766 |
unsinged int r=(color_int >> 16) & 0xff;
|
767 |
|
768 |
b=b << 8;
|
769 |
g=g << 8;
|
770 |
r=r << 8;
|
771 |
*/
|
772 |
|
773 |
|
774 |
#define _css_aliceblue 0xf0f8ff
|
775 |
#define _css_antiquewhite 0xfaebd7
|
776 |
#define _css_aqua 0x00ffff
|
777 |
#define _css_aquamarine 0x7fffd4
|
778 |
#define _css_azure 0xf0ffff
|
779 |
#define _css_beige 0xf5f5dc
|
780 |
#define _css_bisque 0xffe4c4
|
781 |
#define _css_black 0x000000
|
782 |
#define _css_blanchedalmond 0xffebcd
|
783 |
#define _css_blue 0x0000ff
|
784 |
#define _css_blueviolet 0x8a2be2
|
785 |
#define _css_brown 0xa52a2a
|
786 |
#define _css_burlywood 0xdeb887
|
787 |
#define _css_cadetblue 0x5f9ea0
|
788 |
#define _css_chartreuse 0x7fff00
|
789 |
#define _css_chocolate 0xd2691e
|
790 |
#define _css_coral 0xff7f50
|
791 |
#define _css_cornflowerblue 0x6495ed
|
792 |
#define _css_cornsilk 0xfff8dc
|
793 |
#define _css_crimson 0xdc143c
|
794 |
#define _css_cyan 0x00ffff
|
795 |
#define _css_darkblue 0x00008b
|
796 |
#define _css_darkcyan 0x008b8b
|
797 |
#define _css_darkgoldenrod 0xb8860b
|
798 |
#define _css_darkgray 0xa9a9a9
|
799 |
#define _css_darkgreen 0x006400
|
800 |
#define _css_darkkhaki 0xbdb76b
|
801 |
#define _css_darkmagenta 0x8b008b
|
802 |
#define _css_darkolivegreen 0x556b2f
|
803 |
#define _css_darkorange 0xff8c00
|
804 |
#define _css_darkorchid 0x9932cc
|
805 |
#define _css_darkred 0x8b0000
|
806 |
#define _css_darksalmon 0xe9967a
|
807 |
#define _css_darkseagreen 0x8fbc8f
|
808 |
#define _css_darkslateblue 0x483d8b
|
809 |
#define _css_darkslategray 0x2f4f4f
|
810 |
#define _css_darkturquoise 0x00ced1
|
811 |
#define _css_darkviolet 0x9400d3
|
812 |
#define _css_deeppink 0xff1493
|
813 |
#define _css_deepskyblue 0x00bfff
|
814 |
#define _css_dimgray 0x696969
|
815 |
#define _css_dodgerblue 0x1e90ff
|
816 |
#define _css_firebrick 0xb22222
|
817 |
#define _css_floralwhite 0xfffaf0
|
818 |
#define _css_forestgreen 0x228b22
|
819 |
#define _css_fuchsia 0xff00ff
|
820 |
#define _css_gainsboro 0xdcdcdc
|
821 |
#define _css_ghostwhite 0xf8f8ff
|
822 |
#define _css_gold 0xffd700
|
823 |
#define _css_goldenrod 0xdaa520
|
824 |
#define _css_gray 0x808080
|
825 |
#define _css_green 0x008000
|
826 |
#define _css_greenyellow 0xadff2f
|
827 |
#define _css_honeydew 0xf0fff0
|
828 |
#define _css_hotpink 0xff69b4
|
829 |
#define _css_indianred 0xcd5c5c
|
830 |
#define _css_indigo 0x4b0082
|
831 |
#define _css_ivory 0xfffff0
|
832 |
#define _css_khaki 0xf0e68c
|
833 |
#define _css_lavender 0xe6e6fa
|
834 |
#define _css_lavenderblush 0xfff0f5
|
835 |
#define _css_lawngreen 0x7cfc00
|
836 |
#define _css_lemonchiffon 0xfffacd
|
837 |
#define _css_lightblue 0xadd8e6
|
838 |
#define _css_lightcoral 0xf08080
|
839 |
#define _css_lightcyan 0xe0ffff
|
840 |
#define _css_lightgoldenrodyellow 0xfafad2
|
841 |
#define _css_lightgrey 0xd3d3d3
|
842 |
#define _css_lightgreen 0x90ee90
|
843 |
#define _css_lightpink 0xffb6c1
|
844 |
#define _css_lightsalmon 0xffa07a
|
845 |
#define _css_lightseagreen 0x20b2aa
|
846 |
#define _css_lightskyblue 0x87cefa
|
847 |
#define _css_lightslategray 0x778899
|
848 |
#define _css_lightsteelblue 0xb0c4de
|
849 |
#define _css_lightyellow 0xffffe0
|
850 |
#define _css_lime 0x00ff00
|
851 |
#define _css_limegreen 0x32cd32
|
852 |
#define _css_linen 0xfaf0e6
|
853 |
#define _css_magenta 0xff00ff
|
854 |
#define _css_maroon 0x800000
|
855 |
#define _css_mediumaquamarine 0x66cdaa
|
856 |
#define _css_mediumblue 0x0000cd
|
857 |
#define _css_mediumorchid 0xba55d3
|
858 |
#define _css_mediumpurple 0x9370d8
|
859 |
#define _css_mediumseagreen 0x3cb371
|
860 |
#define _css_mediumslateblue 0x7b68ee
|
861 |
#define _css_mediumspringgreen 0x00fa9a
|
862 |
#define _css_mediumturquoise 0x48d1cc
|
863 |
#define _css_mediumvioletred 0xc71585
|
864 |
#define _css_midnightblue 0x191970
|
865 |
#define _css_mintcream 0xf5fffa
|
866 |
#define _css_mistyrose 0xffe4e1
|
867 |
#define _css_moccasin 0xffe4b5
|
868 |
#define _css_navajowhite 0xffdead
|
869 |
#define _css_navy 0x000080
|
870 |
#define _css_oldlace 0xfdf5e6
|
871 |
#define _css_olive 0x808000
|
872 |
#define _css_olivedrab 0x6b8e23
|
873 |
#define _css_orange 0xffa500
|
874 |
#define _css_orangered 0xff4500
|
875 |
#define _css_orchid 0xda70d6
|
876 |
#define _css_palegoldenrod 0xeee8aa
|
877 |
#define _css_palegreen 0x98fb98
|
878 |
#define _css_paleturquoise 0xafeeee
|
879 |
#define _css_palevioletred 0xd87093
|
880 |
#define _css_papayawhip 0xffefd5
|
881 |
#define _css_peachpuff 0xffdab9
|
882 |
#define _css_peru 0xcd853f
|
883 |
#define _css_pink 0xffc0cb
|
884 |
#define _css_plum 0xdda0dd
|
885 |
#define _css_powderblue 0xb0e0e6
|
886 |
#define _css_purple 0x800080
|
887 |
#define _css_red 0xff0000
|
888 |
#define _css_rosybrown 0xbc8f8f
|
889 |
#define _css_royalblue 0x4169e1
|
890 |
#define _css_saddlebrown 0x8b4513
|
891 |
#define _css_salmon 0xfa8072
|
892 |
#define _css_sandybrown 0xf4a460
|
893 |
#define _css_seagreen 0x2e8b57
|
894 |
#define _css_seashell 0xfff5ee
|
895 |
#define _css_sienna 0xa0522d
|
896 |
#define _css_silver 0xc0c0c0
|
897 |
#define _css_skyblue 0x87ceeb
|
898 |
#define _css_slateblue 0x6a5acd
|
899 |
#define _css_slategray 0x708090
|
900 |
#define _css_snow 0xfffafa
|
901 |
#define _css_springgreen 0x00ff7f
|
902 |
#define _css_steelblue 0x4682b4
|
903 |
#define _css_tan 0xd2b48c
|
904 |
#define _css_teal 0x008080
|
905 |
#define _css_thistle 0xd8bfd8
|
906 |
#define _css_tomato 0xff6347
|
907 |
#define _css_turquoise 0x40e0d0
|
908 |
#define _css_violet 0xee82ee
|
909 |
#define _css_wheat 0xf5deb3
|
910 |
#define _css_white 0xffffff
|
911 |
#define _css_whitesmoke 0xf5f5f5
|
912 |
#define _css_yellow 0xffff00
|
913 |
#define _css_yellowgreen 0x9acd32
|
914 |
|
915 |
|