1 |
/**
|
2 |
* Navit, a modular navigation system.
|
3 |
* Copyright (C) 2005-2011 Navit Team
|
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 |
#include <glib.h>
|
20 |
#include "config.h"
|
21 |
#include "coord.h"
|
22 |
#include "item.h"
|
23 |
#include "attr.h"
|
24 |
#ifdef HAVE_LIBCRYPTO
|
25 |
#include <openssl/md5.h>
|
26 |
#endif
|
27 |
|
28 |
|
29 |
#ifdef HAVE_API_WIN32_BASE
|
30 |
#define LONGLONG_FMT "%I64d"
|
31 |
#else
|
32 |
#define LONGLONG_FMT "%lld"
|
33 |
#endif
|
34 |
|
35 |
|
36 |
#define sq(x) ((double)(x)*(x))
|
37 |
|
38 |
|
39 |
#define BUFFER_SIZE 1280
|
40 |
|
41 |
#define debug_tile(x) 0
|
42 |
#define debug_itembin(x) 0
|
43 |
|
44 |
struct rect {
|
45 |
struct coord l,h;
|
46 |
};
|
47 |
|
48 |
struct tile_data {
|
49 |
char buffer[1024];
|
50 |
int tile_depth;
|
51 |
struct rect item_bbox;
|
52 |
struct rect tile_bbox;
|
53 |
};
|
54 |
|
55 |
struct tile_parameter {
|
56 |
int min;
|
57 |
int max;
|
58 |
int overlap;
|
59 |
};
|
60 |
|
61 |
struct tile_info {
|
62 |
int write;
|
63 |
int maxlen;
|
64 |
char *suffix;
|
65 |
GList **tiles_list;
|
66 |
FILE *tilesdir_out;
|
67 |
};
|
68 |
|
69 |
extern struct tile_head {
|
70 |
int num_subtiles;
|
71 |
int total_size;
|
72 |
char *name;
|
73 |
char *zip_data;
|
74 |
int total_size_used;
|
75 |
int zipnum;
|
76 |
int process;
|
77 |
struct tile_head *next;
|
78 |
// char subtiles[0];
|
79 |
} *tile_head_root;
|
80 |
|
81 |
|
82 |
|
83 |
struct item_bin {
|
84 |
int len;
|
85 |
enum item_type type;
|
86 |
int clen;
|
87 |
};
|
88 |
|
89 |
struct attr_bin {
|
90 |
int len;
|
91 |
enum attr_type type;
|
92 |
};
|
93 |
|
94 |
|
95 |
struct item_bin_sink_func {
|
96 |
int (*func)(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data);
|
97 |
void *priv_data[8];
|
98 |
};
|
99 |
|
100 |
struct item_bin_sink {
|
101 |
void *priv_data[8];
|
102 |
GList *sink_funcs;
|
103 |
};
|
104 |
|
105 |
struct node_item {
|
106 |
int id;
|
107 |
char ref_node;
|
108 |
char ref_way;
|
109 |
char ref_ref;
|
110 |
char dummy;
|
111 |
struct coord c;
|
112 |
};
|
113 |
|
114 |
struct zip_info;
|
115 |
struct country_table;
|
116 |
|
117 |
/* boundaries.c */
|
118 |
struct boundary {
|
119 |
struct item_bin *ib;
|
120 |
struct country_table *country;
|
121 |
char *iso2;
|
122 |
GList *segments,*sorted_segments;
|
123 |
GList *children;
|
124 |
struct rect r;
|
125 |
};
|
126 |
|
127 |
char *osm_tag_value(struct item_bin *ib, char *key);
|
128 |
long long *boundary_relid(struct boundary *b);
|
129 |
GList *process_boundaries(FILE *boundaries, FILE *ways);
|
130 |
GList *boundary_find_matches(GList *bl, struct coord *c);
|
131 |
|
132 |
/* buffer.c */
|
133 |
struct buffer {
|
134 |
int malloced_step;
|
135 |
long long malloced;
|
136 |
unsigned char *base;
|
137 |
long long size;
|
138 |
};
|
139 |
|
140 |
void save_buffer(char *filename, struct buffer *b, long long offset);
|
141 |
void load_buffer(char *filename, struct buffer *b, long long offset, long long size);
|
142 |
|
143 |
/* ch.c */
|
144 |
|
145 |
void ch_generate_tiles(char *map_suffix, char *suffix, FILE *tilesdir_out, struct zip_info *zip_info);
|
146 |
void ch_assemble_map(char *map_suffix, char *suffix, struct zip_info *zip_info);
|
147 |
|
148 |
/* coastline.c */
|
149 |
|
150 |
void process_coastlines(FILE *in, FILE *out);
|
151 |
|
152 |
/* geom.c */
|
153 |
|
154 |
enum geom_poly_segment_type {
|
155 |
geom_poly_segment_type_none,
|
156 |
geom_poly_segment_type_way_inner,
|
157 |
geom_poly_segment_type_way_outer,
|
158 |
geom_poly_segment_type_way_left_side,
|
159 |
geom_poly_segment_type_way_right_side,
|
160 |
geom_poly_segment_type_way_unknown,
|
161 |
|
162 |
};
|
163 |
|
164 |
struct geom_poly_segment {
|
165 |
enum geom_poly_segment_type type;
|
166 |
struct coord *first,*last;
|
167 |
};
|
168 |
|
169 |
void geom_coord_copy(struct coord *from, struct coord *to, int count, int reverse);
|
170 |
void geom_coord_revert(struct coord *c, int count);
|
171 |
long long geom_poly_area(struct coord *c, int count);
|
172 |
GList *geom_poly_segments_insert(GList *list, struct geom_poly_segment *first, struct geom_poly_segment *second, struct geom_poly_segment *third);
|
173 |
void geom_poly_segment_destroy(struct geom_poly_segment *seg);
|
174 |
GList *geom_poly_segments_remove(GList *list, struct geom_poly_segment *seg);
|
175 |
int geom_poly_segment_compatible(struct geom_poly_segment *s1, struct geom_poly_segment *s2, int dir);
|
176 |
GList *geom_poly_segments_sort(GList *in, enum geom_poly_segment_type type);
|
177 |
struct geom_poly_segment *item_bin_to_poly_segment(struct item_bin *ib, int type);
|
178 |
int geom_poly_segments_point_inside(GList *in, struct coord *c);
|
179 |
void clip_line(struct item_bin *ib, struct rect *r, struct tile_parameter *param, struct item_bin_sink *out);
|
180 |
void clip_polygon(struct item_bin *ib, struct rect *r, struct tile_parameter *param, struct item_bin_sink *out);
|
181 |
|
182 |
/* itembin.c */
|
183 |
|
184 |
int item_bin_read(struct item_bin *ib, FILE *in);
|
185 |
void item_bin_set_type(struct item_bin *ib, enum item_type type);
|
186 |
void item_bin_init(struct item_bin *ib, enum item_type type);
|
187 |
void item_bin_add_coord(struct item_bin *ib, struct coord *c, int count);
|
188 |
void item_bin_add_coord_reverse(struct item_bin *ib, struct coord *c, int count);
|
189 |
void item_bin_bbox(struct item_bin *ib, struct rect *r);
|
190 |
void item_bin_copy_coord(struct item_bin *ib, struct item_bin *from, int dir);
|
191 |
void item_bin_add_coord_rect(struct item_bin *ib, struct rect *r);
|
192 |
int attr_bin_write_data(struct attr_bin *ab, enum attr_type type, void *data, int size);
|
193 |
int attr_bin_write_attr(struct attr_bin *ab, struct attr *attr);
|
194 |
void item_bin_add_attr_data(struct item_bin *ib, enum attr_type type, void *data, int size);
|
195 |
void item_bin_add_attr(struct item_bin *ib, struct attr *attr);
|
196 |
void item_bin_add_attr_int(struct item_bin *ib, enum attr_type type, int val);
|
197 |
void *item_bin_get_attr(struct item_bin *ib, enum attr_type type, void *last);
|
198 |
struct attr_bin * item_bin_get_attr_bin_last(struct item_bin *ib);
|
199 |
void item_bin_add_attr_longlong(struct item_bin *ib, enum attr_type type, long long val);
|
200 |
void item_bin_add_attr_string(struct item_bin *ib, enum attr_type type, char *str);
|
201 |
void item_bin_add_attr_range(struct item_bin *ib, enum attr_type type, short min, short max);
|
202 |
void item_bin_remove_attr(struct item_bin *ib, void *ptr);
|
203 |
void item_bin_write(struct item_bin *ib, FILE *out);
|
204 |
struct item_bin *item_bin_dup(struct item_bin *ib);
|
205 |
void item_bin_write_range(struct item_bin *ib, FILE *out, int min, int max);
|
206 |
void item_bin_write_clipped(struct item_bin *ib, struct tile_parameter *param, struct item_bin_sink *out);
|
207 |
void item_bin_dump(struct item_bin *ib, FILE *out);
|
208 |
void dump_itembin(struct item_bin *ib);
|
209 |
void item_bin_set_type_by_population(struct item_bin *ib, int population);
|
210 |
void item_bin_write_match(struct item_bin *ib, enum attr_type type, enum attr_type match, FILE *out);
|
211 |
void item_bin_town_write_match(struct item_bin *ib, enum attr_type type, enum attr_type match, FILE *out);
|
212 |
int item_bin_sort_file(char *in_file, char *out_file, struct rect *r, int *size);
|
213 |
|
214 |
/* itembin_buffer.c */
|
215 |
struct node_item *read_node_item(FILE *in);
|
216 |
struct item_bin *read_item(FILE *in);
|
217 |
struct item_bin *read_item_range(FILE *in, int *min, int *max);
|
218 |
struct item_bin *init_item(enum item_type type);
|
219 |
|
220 |
/* maptool.c */
|
221 |
|
222 |
extern long long slice_size;
|
223 |
extern int attr_debug_level;
|
224 |
extern char *suffix;
|
225 |
extern int ignore_unkown;
|
226 |
extern GHashTable *dedupe_ways_hash;
|
227 |
extern int phase;
|
228 |
extern int slices;
|
229 |
extern struct buffer node_buffer;
|
230 |
extern int processed_nodes, processed_nodes_out, processed_ways, processed_relations, processed_tiles;
|
231 |
extern struct item_bin *item_bin;
|
232 |
extern int bytes_read;
|
233 |
extern int overlap;
|
234 |
extern int experimental;
|
235 |
extern int use_global_fixed_country_id;
|
236 |
extern int global_fixed_country_id;
|
237 |
extern int unknown_country;
|
238 |
void sig_alrm(int sig);
|
239 |
void sig_alrm_end(void);
|
240 |
extern int border_only_map;
|
241 |
extern int coastline_only_map;
|
242 |
|
243 |
/* misc.c */
|
244 |
extern struct rect world_bbox;
|
245 |
|
246 |
|
247 |
void bbox_extend(struct coord *c, struct rect *r);
|
248 |
void bbox(struct coord *c, int count, struct rect *r);
|
249 |
int contains_bbox(int xl, int yl, int xh, int yh, struct rect *r);
|
250 |
int bbox_contains_coord(struct rect *r, struct coord *c);
|
251 |
int bbox_contains_bbox(struct rect *out, struct rect *in);
|
252 |
long long bbox_area(struct rect const *r);
|
253 |
void phase1_map(GList *maps, FILE *out_ways, FILE *out_nodes);
|
254 |
void dump(FILE *in);
|
255 |
int phase4(FILE **in, int in_count, int with_range, char *suffix, FILE *tilesdir_out, struct zip_info *zip_info);
|
256 |
int phase5(FILE **in, FILE **references, int in_count, int with_range, char *suffix, struct zip_info *zip_info);
|
257 |
void process_binfile(FILE *in, FILE *out);
|
258 |
void add_aux_tiles(char *name, struct zip_info *info);
|
259 |
void cat(FILE *in, FILE *out);
|
260 |
|
261 |
|
262 |
/* osm.c */
|
263 |
typedef long int osmid;
|
264 |
|
265 |
struct maptool_osm {
|
266 |
FILE *boundaries;
|
267 |
FILE *turn_restrictions;
|
268 |
FILE *nodes;
|
269 |
FILE *ways;
|
270 |
FILE *line2poi;
|
271 |
FILE *poly2poi;
|
272 |
FILE *towns;
|
273 |
};
|
274 |
|
275 |
|
276 |
void osm_warning(char *type, long long id, int cont, char *fmt, ...);
|
277 |
void osm_add_tag(char *k, char *v);
|
278 |
void osm_add_node(osmid id, double lat, double lon);
|
279 |
void osm_add_way(osmid id);
|
280 |
void osm_add_relation(osmid id);
|
281 |
void osm_end_relation(struct maptool_osm *osm);
|
282 |
void osm_add_member(int type, osmid ref, char *role);
|
283 |
void osm_end_way(struct maptool_osm *osm);
|
284 |
void osm_end_node(struct maptool_osm *osm);
|
285 |
void osm_add_nd(osmid ref);
|
286 |
long long item_bin_get_id(struct item_bin *ib);
|
287 |
void flush_nodes(int final);
|
288 |
void sort_countries(int keep_tmpfiles);
|
289 |
void process_turn_restrictions(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out);
|
290 |
void clear_node_item_buffer(void);
|
291 |
void ref_ways(FILE *in);
|
292 |
void resolve_ways(FILE *in, FILE *out);
|
293 |
long long item_bin_get_nodeid(struct item_bin *ib);
|
294 |
long long item_bin_get_wayid(struct item_bin *ib);
|
295 |
long long item_bin_get_relationid(struct item_bin *ib);
|
296 |
FILE *resolve_ways_file(FILE *in, char *suffix, char *filename);
|
297 |
void process_way2poi(FILE *in, FILE *out, int type);
|
298 |
int map_find_intersections(FILE *in, FILE *out, FILE *out_index, FILE *out_graph, FILE *out_coastline, int final);
|
299 |
void write_countrydir(struct zip_info *zip_info);
|
300 |
void osm_process_towns(FILE *in, FILE *boundaries, FILE *ways);
|
301 |
void load_countries(void);
|
302 |
void remove_countryfiles(void);
|
303 |
struct country_table * country_from_iso2(char *iso);
|
304 |
void osm_init(FILE*);
|
305 |
|
306 |
/* osm_psql.c */
|
307 |
int map_collect_data_osm_db(char *dbstr, struct maptool_osm *osm);
|
308 |
|
309 |
/* osm_protobuf.c */
|
310 |
int map_collect_data_osm_protobuf(FILE *in, struct maptool_osm *osm);
|
311 |
int osm_protobufdb_load(FILE *in, char *dir);
|
312 |
|
313 |
|
314 |
/* osm_relations.c */
|
315 |
struct relations * relations_new(void);
|
316 |
struct relations_func *relations_func_new(void (*func)(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv), void *func_priv);
|
317 |
void relations_add_func(struct relations *rel, struct relations_func *func, void *relation_priv, void *member_priv, int type, osmid id);
|
318 |
void relations_process(struct relations *rel, FILE *nodes, FILE *ways, FILE *relations);
|
319 |
|
320 |
/* osm_xml.c */
|
321 |
int osm_xml_get_attribute(char *xml, char *attribute, char *buffer, int buffer_size);
|
322 |
void osm_xml_decode_entities(char *buffer);
|
323 |
int map_collect_data_osm(FILE *in, struct maptool_osm *osm);
|
324 |
|
325 |
|
326 |
/* sourcesink.c */
|
327 |
|
328 |
struct item_bin_sink *item_bin_sink_new(void);
|
329 |
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));
|
330 |
void item_bin_sink_func_destroy(struct item_bin_sink_func *func);
|
331 |
void item_bin_sink_add_func(struct item_bin_sink *sink, struct item_bin_sink_func *func);
|
332 |
void item_bin_sink_destroy(struct item_bin_sink *sink);
|
333 |
int item_bin_write_to_sink(struct item_bin *ib, struct item_bin_sink *sink, struct tile_data *tile_data);
|
334 |
struct item_bin_sink *file_reader_new(FILE *in, int limit, int offset);
|
335 |
int file_reader_finish(struct item_bin_sink *sink);
|
336 |
int file_writer_process(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data);
|
337 |
struct item_bin_sink_func *file_writer_new(FILE *out);
|
338 |
int file_writer_finish(struct item_bin_sink_func *file_writer);
|
339 |
int tile_collector_process(struct item_bin_sink_func *tile_collector, struct item_bin *ib, struct tile_data *tile_data);
|
340 |
struct item_bin_sink_func *tile_collector_new(struct item_bin_sink *out);
|
341 |
|
342 |
/* tempfile.c */
|
343 |
|
344 |
char *tempfile_name(char *suffix, char *name);
|
345 |
FILE *tempfile(char *suffix, char *name, int mode);
|
346 |
void tempfile_unlink(char *suffix, char *name);
|
347 |
void tempfile_rename(char *suffix, char *from, char *to);
|
348 |
|
349 |
/* tile.c */
|
350 |
extern GHashTable *tile_hash,*tile_hash2;
|
351 |
|
352 |
struct aux_tile {
|
353 |
char *name;
|
354 |
char *filename;
|
355 |
int size;
|
356 |
};
|
357 |
|
358 |
extern GList *aux_tile_list;
|
359 |
|
360 |
int tile(struct rect *r, char *suffix, char *ret, int max, int overlap, struct rect *tr);
|
361 |
void tile_bbox(char *tile, struct rect *r, int overlap);
|
362 |
int tile_len(char *tile);
|
363 |
void tile_write_item_to_tile(struct tile_info *info, struct item_bin *ib, FILE *reference, char *name);
|
364 |
void tile_write_item_minmax(struct tile_info *info, struct item_bin *ib, FILE *reference, int min, int max);
|
365 |
int add_aux_tile(struct zip_info *zip_info, char *name, char *filename, int size);
|
366 |
int write_aux_tiles(struct zip_info *zip_info);
|
367 |
int create_tile_hash(void);
|
368 |
void write_tilesdir(struct tile_info *info, struct zip_info *zip_info, FILE *out);
|
369 |
void merge_tiles(struct tile_info *info);
|
370 |
struct attr map_information_attrs[32];
|
371 |
void index_init(struct zip_info *info, int version);
|
372 |
void index_submap_add(struct tile_info *info, struct tile_head *th);
|
373 |
|
374 |
/* zip.c */
|
375 |
void write_zipmember(struct zip_info *zip_info, char *name, int filelen, char *data, int data_size);
|
376 |
void zip_write_index(struct zip_info *info);
|
377 |
int zip_write_directory(struct zip_info *info);
|
378 |
struct zip_info *zip_new(void);
|
379 |
void zip_set_md5(struct zip_info *info, int on);
|
380 |
int zip_get_md5(struct zip_info *info, unsigned char *out);
|
381 |
void zip_set_zip64(struct zip_info *info, int on);
|
382 |
void zip_set_compression_level(struct zip_info *info, int level);
|
383 |
void zip_set_maxnamelen(struct zip_info *info, int max);
|
384 |
int zip_get_maxnamelen(struct zip_info *info);
|
385 |
int zip_add_member(struct zip_info *info);
|
386 |
int zip_set_timestamp(struct zip_info *info, char *timestamp);
|
387 |
int zip_set_password(struct zip_info *info, char *password);
|
388 |
void zip_open(struct zip_info *info, char *out, char *dir, char *index);
|
389 |
FILE *zip_get_index(struct zip_info *info);
|
390 |
int zip_get_zipnum(struct zip_info *info);
|
391 |
void zip_set_zipnum(struct zip_info *info, int num);
|
392 |
void zip_close(struct zip_info *info);
|
393 |
void zip_destroy(struct zip_info *info);
|