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 |
#define BUFFER_SIZE 1280
|
36 |
|
37 |
#define debug_tile(x) 0
|
38 |
#define debug_itembin(x) 0
|
39 |
|
40 |
struct rect {
|
41 |
struct coord l,h;
|
42 |
};
|
43 |
|
44 |
struct tile_data {
|
45 |
char buffer[1024];
|
46 |
int tile_depth;
|
47 |
struct rect item_bbox;
|
48 |
struct rect tile_bbox;
|
49 |
};
|
50 |
|
51 |
struct tile_parameter {
|
52 |
int min;
|
53 |
int max;
|
54 |
int overlap;
|
55 |
};
|
56 |
|
57 |
struct tile_info {
|
58 |
int write;
|
59 |
int maxlen;
|
60 |
char *suffix;
|
61 |
GList **tiles_list;
|
62 |
FILE *tilesdir_out;
|
63 |
};
|
64 |
|
65 |
extern struct tile_head {
|
66 |
int num_subtiles;
|
67 |
int total_size;
|
68 |
char *name;
|
69 |
char *zip_data;
|
70 |
int total_size_used;
|
71 |
int zipnum;
|
72 |
int process;
|
73 |
struct tile_head *next;
|
74 |
// char subtiles[0];
|
75 |
} *tile_head_root;
|
76 |
|
77 |
|
78 |
|
79 |
struct item_bin {
|
80 |
int len;
|
81 |
enum item_type type;
|
82 |
int clen;
|
83 |
};
|
84 |
|
85 |
struct attr_bin {
|
86 |
int len;
|
87 |
enum attr_type type;
|
88 |
};
|
89 |
|
90 |
|
91 |
struct item_bin_sink_func {
|
92 |
int (*func)(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data);
|
93 |
void *priv_data[8];
|
94 |
};
|
95 |
|
96 |
struct item_bin_sink {
|
97 |
void *priv_data[8];
|
98 |
GList *sink_funcs;
|
99 |
};
|
100 |
|
101 |
struct zip_info;
|
102 |
|
103 |
/* boundaries.c */
|
104 |
|
105 |
int process_boundaries(FILE *boundaries, FILE *ways);
|
106 |
|
107 |
/* buffer.c */
|
108 |
struct buffer {
|
109 |
int malloced_step;
|
110 |
long long malloced;
|
111 |
unsigned char *base;
|
112 |
long long size;
|
113 |
};
|
114 |
|
115 |
void save_buffer(char *filename, struct buffer *b, long long offset);
|
116 |
void load_buffer(char *filename, struct buffer *b, long long offset, long long size);
|
117 |
|
118 |
/* ch.c */
|
119 |
|
120 |
void ch_generate_tiles(char *map_suffix, char *suffix, FILE *tilesdir_out, struct zip_info *zip_info);
|
121 |
void ch_assemble_map(char *map_suffix, char *suffix, struct zip_info *zip_info);
|
122 |
|
123 |
/* coastline.c */
|
124 |
|
125 |
void process_coastlines(FILE *in, FILE *out);
|
126 |
|
127 |
/* geom.c */
|
128 |
|
129 |
enum geom_poly_segment_type {
|
130 |
geom_poly_segment_type_none,
|
131 |
geom_poly_segment_type_way_inner,
|
132 |
geom_poly_segment_type_way_outer,
|
133 |
geom_poly_segment_type_way_left_side,
|
134 |
geom_poly_segment_type_way_right_side,
|
135 |
geom_poly_segment_type_way_unknown,
|
136 |
|
137 |
};
|
138 |
|
139 |
struct geom_poly_segment {
|
140 |
enum geom_poly_segment_type type;
|
141 |
struct coord *first,*last;
|
142 |
};
|
143 |
|
144 |
void geom_coord_copy(struct coord *from, struct coord *to, int count, int reverse);
|
145 |
void geom_coord_revert(struct coord *c, int count);
|
146 |
long long geom_poly_area(struct coord *c, int count);
|
147 |
GList *geom_poly_segments_insert(GList *list, struct geom_poly_segment *first, struct geom_poly_segment *second, struct geom_poly_segment *third);
|
148 |
void geom_poly_segment_destroy(struct geom_poly_segment *seg);
|
149 |
GList *geom_poly_segments_remove(GList *list, struct geom_poly_segment *seg);
|
150 |
int geom_poly_segment_compatible(struct geom_poly_segment *s1, struct geom_poly_segment *s2, int dir);
|
151 |
GList *geom_poly_segments_sort(GList *in, enum geom_poly_segment_type type);
|
152 |
struct geom_poly_segment *item_bin_to_poly_segment(struct item_bin *ib, int type);
|
153 |
int geom_poly_segments_point_inside(GList *in, struct coord *c);
|
154 |
void clip_line(struct item_bin *ib, struct rect *r, struct tile_parameter *param, struct item_bin_sink *out);
|
155 |
void clip_polygon(struct item_bin *ib, struct rect *r, struct tile_parameter *param, struct item_bin_sink *out);
|
156 |
|
157 |
/* itembin.c */
|
158 |
|
159 |
int item_bin_read(struct item_bin *ib, FILE *in);
|
160 |
void item_bin_set_type(struct item_bin *ib, enum item_type type);
|
161 |
void item_bin_init(struct item_bin *ib, enum item_type type);
|
162 |
void item_bin_add_coord(struct item_bin *ib, struct coord *c, int count);
|
163 |
void item_bin_add_coord_reverse(struct item_bin *ib, struct coord *c, int count);
|
164 |
void item_bin_bbox(struct item_bin *ib, struct rect *r);
|
165 |
void item_bin_copy_coord(struct item_bin *ib, struct item_bin *from, int dir);
|
166 |
void item_bin_add_coord_rect(struct item_bin *ib, struct rect *r);
|
167 |
int attr_bin_write_data(struct attr_bin *ab, enum attr_type type, void *data, int size);
|
168 |
int attr_bin_write_attr(struct attr_bin *ab, struct attr *attr);
|
169 |
void item_bin_add_attr_data(struct item_bin *ib, enum attr_type type, void *data, int size);
|
170 |
void item_bin_add_attr(struct item_bin *ib, struct attr *attr);
|
171 |
void item_bin_add_attr_int(struct item_bin *ib, enum attr_type type, int val);
|
172 |
void *item_bin_get_attr(struct item_bin *ib, enum attr_type type, void *last);
|
173 |
struct attr_bin * item_bin_get_attr_bin_last(struct item_bin *ib);
|
174 |
void item_bin_add_attr_longlong(struct item_bin *ib, enum attr_type type, long long val);
|
175 |
void item_bin_add_attr_string(struct item_bin *ib, enum attr_type type, char *str);
|
176 |
void item_bin_add_attr_range(struct item_bin *ib, enum attr_type type, short min, short max);
|
177 |
void item_bin_write(struct item_bin *ib, FILE *out);
|
178 |
struct item_bin *item_bin_dup(struct item_bin *ib);
|
179 |
void item_bin_write_range(struct item_bin *ib, FILE *out, int min, int max);
|
180 |
void item_bin_write_clipped(struct item_bin *ib, struct tile_parameter *param, struct item_bin_sink *out);
|
181 |
void item_bin_dump(struct item_bin *ib, FILE *out);
|
182 |
void dump_itembin(struct item_bin *ib);
|
183 |
void item_bin_set_type_by_population(struct item_bin *ib, int population);
|
184 |
void item_bin_write_match(struct item_bin *ib, enum attr_type type, enum attr_type match, FILE *out);
|
185 |
int item_bin_sort_file(char *in_file, char *out_file, struct rect *r, int *size);
|
186 |
|
187 |
/* itembin_buffer.c */
|
188 |
struct item_bin *read_item(FILE *in);
|
189 |
struct item_bin *read_item_range(FILE *in, int *min, int *max);
|
190 |
struct item_bin *init_item(enum item_type type);
|
191 |
|
192 |
/* maptool.c */
|
193 |
|
194 |
extern long long slice_size;
|
195 |
extern int attr_debug_level;
|
196 |
extern char *suffix;
|
197 |
extern int ignore_unkown;
|
198 |
extern GHashTable *dedupe_ways_hash;
|
199 |
extern int phase;
|
200 |
extern int slices;
|
201 |
extern struct buffer node_buffer;
|
202 |
extern int processed_nodes, processed_nodes_out, processed_ways, processed_relations, processed_tiles;
|
203 |
extern struct item_bin *item_bin;
|
204 |
extern int bytes_read;
|
205 |
extern int overlap;
|
206 |
void sig_alrm(int sig);
|
207 |
void sig_alrm_end(void);
|
208 |
|
209 |
/* misc.c */
|
210 |
extern struct rect world_bbox;
|
211 |
|
212 |
|
213 |
void bbox_extend(struct coord *c, struct rect *r);
|
214 |
void bbox(struct coord *c, int count, struct rect *r);
|
215 |
int contains_bbox(int xl, int yl, int xh, int yh, struct rect *r);
|
216 |
int bbox_contains_coord(struct rect *r, struct coord *c);
|
217 |
int bbox_contains_bbox(struct rect *out, struct rect *in);
|
218 |
long long bbox_area(struct rect const *r);
|
219 |
void phase1_map(GList *maps, FILE *out_ways, FILE *out_nodes);
|
220 |
void dump(FILE *in);
|
221 |
int phase4(FILE **in, int in_count, int with_range, char *suffix, FILE *tilesdir_out, struct zip_info *zip_info);
|
222 |
int phase5(FILE **in, FILE **references, int in_count, int with_range, char *suffix, struct zip_info *zip_info);
|
223 |
void process_binfile(FILE *in, FILE *out);
|
224 |
void add_aux_tiles(char *name, struct zip_info *info);
|
225 |
void cat(FILE *in, FILE *out);
|
226 |
|
227 |
|
228 |
/* osm.c */
|
229 |
typedef long int osmid;
|
230 |
|
231 |
void osm_add_tag(char *k, char *v);
|
232 |
void osm_add_node(osmid id, double lat, double lon);
|
233 |
void osm_add_way(osmid id);
|
234 |
void osm_add_relation(osmid id);
|
235 |
void osm_end_relation(FILE *turn_restrictions, FILE *boundaries);
|
236 |
void osm_add_member(int type, osmid ref, char *role);
|
237 |
void osm_end_way(FILE *out);
|
238 |
void osm_end_node(FILE *out);
|
239 |
void osm_add_nd(osmid ref);
|
240 |
long long item_bin_get_id(struct item_bin *ib);
|
241 |
void flush_nodes(int final);
|
242 |
void sort_countries(int keep_tmpfiles);
|
243 |
void process_turn_restrictions(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out);
|
244 |
int resolve_ways(FILE *in, FILE *out);
|
245 |
int map_find_intersections(FILE *in, FILE *out, FILE *out_index, FILE *out_graph, FILE *out_coastline, int final);
|
246 |
void write_countrydir(struct zip_info *zip_info);
|
247 |
void remove_countryfiles(void);
|
248 |
void osm_init(FILE*);
|
249 |
|
250 |
/* osm_psql.c */
|
251 |
int map_collect_data_osm_db(char *dbstr, FILE *out_ways, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries);
|
252 |
|
253 |
/* osm_protobuf.c */
|
254 |
int map_collect_data_osm_protobuf(FILE *in, FILE *out_ways, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries);
|
255 |
int osm_protobufdb_load(FILE *in, char *dir);
|
256 |
|
257 |
/* osm_xml.c */
|
258 |
int osm_xml_get_attribute(char *xml, char *attribute, char *buffer, int buffer_size);
|
259 |
void osm_xml_decode_entities(char *buffer);
|
260 |
int map_collect_data_osm(FILE *in, FILE *out_ways, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries);
|
261 |
|
262 |
|
263 |
/* sourcesink.c */
|
264 |
|
265 |
struct item_bin_sink *item_bin_sink_new(void);
|
266 |
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));
|
267 |
void item_bin_sink_func_destroy(struct item_bin_sink_func *func);
|
268 |
void item_bin_sink_add_func(struct item_bin_sink *sink, struct item_bin_sink_func *func);
|
269 |
void item_bin_sink_destroy(struct item_bin_sink *sink);
|
270 |
int item_bin_write_to_sink(struct item_bin *ib, struct item_bin_sink *sink, struct tile_data *tile_data);
|
271 |
struct item_bin_sink *file_reader_new(FILE *in, int limit, int offset);
|
272 |
int file_reader_finish(struct item_bin_sink *sink);
|
273 |
int file_writer_process(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data);
|
274 |
struct item_bin_sink_func *file_writer_new(FILE *out);
|
275 |
int file_writer_finish(struct item_bin_sink_func *file_writer);
|
276 |
int tile_collector_process(struct item_bin_sink_func *tile_collector, struct item_bin *ib, struct tile_data *tile_data);
|
277 |
struct item_bin_sink_func *tile_collector_new(struct item_bin_sink *out);
|
278 |
|
279 |
/* tempfile.c */
|
280 |
|
281 |
char *tempfile_name(char *suffix, char *name);
|
282 |
FILE *tempfile(char *suffix, char *name, int mode);
|
283 |
void tempfile_unlink(char *suffix, char *name);
|
284 |
void tempfile_rename(char *suffix, char *from, char *to);
|
285 |
|
286 |
/* tile.c */
|
287 |
extern GHashTable *tile_hash,*tile_hash2;
|
288 |
|
289 |
struct aux_tile {
|
290 |
char *name;
|
291 |
char *filename;
|
292 |
int size;
|
293 |
};
|
294 |
|
295 |
extern GList *aux_tile_list;
|
296 |
|
297 |
int tile(struct rect *r, char *suffix, char *ret, int max, int overlap, struct rect *tr);
|
298 |
void tile_bbox(char *tile, struct rect *r, int overlap);
|
299 |
int tile_len(char *tile);
|
300 |
void tile_write_item_to_tile(struct tile_info *info, struct item_bin *ib, FILE *reference, char *name);
|
301 |
void tile_write_item_minmax(struct tile_info *info, struct item_bin *ib, FILE *reference, int min, int max);
|
302 |
int add_aux_tile(struct zip_info *zip_info, char *name, char *filename, int size);
|
303 |
int write_aux_tiles(struct zip_info *zip_info);
|
304 |
int create_tile_hash(void);
|
305 |
void write_tilesdir(struct tile_info *info, struct zip_info *zip_info, FILE *out);
|
306 |
void merge_tiles(struct tile_info *info);
|
307 |
struct attr map_information_attrs[32];
|
308 |
void index_init(struct zip_info *info, int version);
|
309 |
void index_submap_add(struct tile_info *info, struct tile_head *th);
|
310 |
|
311 |
/* zip.c */
|
312 |
void write_zipmember(struct zip_info *zip_info, char *name, int filelen, char *data, int data_size);
|
313 |
void zip_write_index(struct zip_info *info);
|
314 |
int zip_write_directory(struct zip_info *info);
|
315 |
struct zip_info *zip_new(void);
|
316 |
void zip_set_md5(struct zip_info *info, int on);
|
317 |
int zip_get_md5(struct zip_info *info, unsigned char *out);
|
318 |
void zip_set_zip64(struct zip_info *info, int on);
|
319 |
void zip_set_compression_level(struct zip_info *info, int level);
|
320 |
void zip_set_maxnamelen(struct zip_info *info, int max);
|
321 |
int zip_get_maxnamelen(struct zip_info *info);
|
322 |
int zip_add_member(struct zip_info *info);
|
323 |
int zip_set_timestamp(struct zip_info *info, char *timestamp);
|
324 |
int zip_set_password(struct zip_info *info, char *password);
|
325 |
void zip_open(struct zip_info *info, char *out, char *dir, char *index);
|
326 |
FILE *zip_get_index(struct zip_info *info);
|
327 |
int zip_get_zipnum(struct zip_info *info);
|
328 |
void zip_set_zipnum(struct zip_info *info, int num);
|
329 |
void zip_close(struct zip_info *info);
|
330 |
void zip_destroy(struct zip_info *info);
|