Navit SVN

/work/compile/navit/src/navit/maptool/maptool.h

00001 
00019 #include <glib.h>
00020 #include "config.h"
00021 #include "coord.h"
00022 #include "item.h"
00023 #include "attr.h"
00024 #ifdef HAVE_LIBCRYPTO
00025 #include <openssl/md5.h>
00026 #endif
00027 
00028 
00029 #ifdef HAVE_API_WIN32_BASE
00030 #define LONGLONG_FMT "%I64d"
00031 #else
00032 #define LONGLONG_FMT "%lld"
00033 #endif
00034 
00035 #define sq(x) ((double)(x)*(x))
00036 
00037 #define BUFFER_SIZE 1280
00038 
00039 #define debug_tile(x) 0
00040 #define debug_itembin(x) 0
00041 
00042 struct rect {
00043         struct coord l,h;
00044 };
00045 
00046 struct tile_data {
00047         char buffer[1024];
00048         int tile_depth;
00049         struct rect item_bbox;
00050         struct rect tile_bbox;
00051 };
00052 
00053 struct tile_parameter {
00054         int min;
00055         int max;
00056         int overlap;
00057         enum attr_type attr_to_copy;
00058 };
00059 
00060 struct tile_info {
00061         int write;
00062         int maxlen;
00063         char *suffix;
00064         GList **tiles_list;
00065         FILE *tilesdir_out;
00066 };
00067 
00068 extern struct tile_head {
00069         int num_subtiles;
00070         int total_size;
00071         char *name;
00072         char *zip_data;
00073         int total_size_used;
00074         int zipnum;
00075         int process;
00076         struct tile_head *next;
00077         // char subtiles[0];
00078 } *tile_head_root;
00079 
00080 
00081 
00082 struct item_bin {
00083         int len;
00084         enum item_type type;
00085         int clen;
00086 };
00087 
00088 struct attr_bin {
00089         int len;
00090         enum attr_type type;
00091 };
00092 
00093 
00094 struct item_bin_sink_func {
00095         int (*func)(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data);
00096         void *priv_data[8];
00097 };
00098 
00099 struct item_bin_sink {
00100         void *priv_data[8];
00101         GList *sink_funcs;
00102 };
00103 
00104 struct node_item {
00105         int id;
00106         char ref_node;
00107         char ref_way;
00108         char ref_ref;
00109         char dummy;
00110         struct coord c;
00111 };
00112 
00113 struct zip_info;
00114 
00115 struct country_table;
00116 
00117 typedef long int osmid;
00118 
00119 /* boundaries.c */
00120 
00121 struct boundary {
00122         struct item_bin *ib;
00123         struct country_table *country;
00124         char *iso2;
00125         GList *segments,*sorted_segments;
00126         GList *children;
00127         struct rect r;
00128 };
00129 
00130 char *osm_tag_value(struct item_bin *ib, char *key);
00131 
00132 osmid boundary_relid(struct boundary *b);
00133 
00134 GList *process_boundaries(FILE *boundaries, FILE *ways);
00135 
00136 GList *boundary_find_matches(GList *bl, struct coord *c);
00137 
00138 /* buffer.c */
00139 struct buffer {
00140         int malloced_step;
00141         long long malloced;
00142         unsigned char *base;
00143         long long size;
00144 };
00145 
00146 void save_buffer(char *filename, struct buffer *b, long long offset);
00147 void load_buffer(char *filename, struct buffer *b, long long offset, long long size);
00148 long long sizeof_buffer(char *filename);
00149 
00150 /* ch.c */
00151 
00152 void ch_generate_tiles(char *map_suffix, char *suffix, FILE *tilesdir_out, struct zip_info *zip_info);
00153 void ch_assemble_map(char *map_suffix, char *suffix, struct zip_info *zip_info);
00154 
00155 /* coastline.c */
00156 
00157 void process_coastlines(FILE *in, FILE *out);
00158 
00159 /* geom.c */
00160 
00161 enum geom_poly_segment_type {
00162         geom_poly_segment_type_none,
00163         geom_poly_segment_type_way_inner,
00164         geom_poly_segment_type_way_outer,
00165         geom_poly_segment_type_way_left_side,
00166         geom_poly_segment_type_way_right_side,
00167         geom_poly_segment_type_way_unknown,
00168 
00169 };
00170 
00171 struct geom_poly_segment {
00172         enum geom_poly_segment_type type;
00173         struct coord *first,*last;
00174 };
00175 
00176 void geom_coord_copy(struct coord *from, struct coord *to, int count, int reverse);
00177 void geom_coord_revert(struct coord *c, int count);
00178 int geom_line_middle(struct coord *p, int count, struct coord *c);
00179 long long geom_poly_area(struct coord *c, int count);
00180 int geom_poly_centroid(struct coord *c, int count, struct coord *r);
00181 int geom_poly_point_inside(struct coord *cp, int count, struct coord *c);
00182 int geom_poly_closest_point(struct coord *pl, int count, struct coord *p, struct coord *c);
00183 GList *geom_poly_segments_insert(GList *list, struct geom_poly_segment *first, struct geom_poly_segment *second, struct geom_poly_segment *third);
00184 void geom_poly_segment_destroy(struct geom_poly_segment *seg);
00185 GList *geom_poly_segments_remove(GList *list, struct geom_poly_segment *seg);
00186 int geom_poly_segment_compatible(struct geom_poly_segment *s1, struct geom_poly_segment *s2, int dir);
00187 GList *geom_poly_segments_sort(GList *in, enum geom_poly_segment_type type);
00188 struct geom_poly_segment *item_bin_to_poly_segment(struct item_bin *ib, int type);
00189 int geom_poly_segments_point_inside(GList *in, struct coord *c);
00190 void clip_line(struct item_bin *ib, struct rect *r, struct tile_parameter *param, struct item_bin_sink *out);
00191 void clip_polygon(struct item_bin *ib, struct rect *r, struct tile_parameter *param, struct item_bin_sink *out);
00192 
00193 /* itembin.c */
00194 
00195 int item_bin_read(struct item_bin *ib, FILE *in);
00196 void item_bin_set_type(struct item_bin *ib, enum item_type type);
00197 void item_bin_init(struct item_bin *ib, enum item_type type);
00198 void item_bin_add_coord(struct item_bin *ib, struct coord *c, int count);
00199 void item_bin_add_coord_reverse(struct item_bin *ib, struct coord *c, int count);
00200 void item_bin_bbox(struct item_bin *ib, struct rect *r);
00201 void item_bin_copy_coord(struct item_bin *ib, struct item_bin *from, int dir);
00202 void item_bin_copy_attr(struct item_bin *ib, struct item_bin *from, enum attr_type attr);
00203 void item_bin_add_coord_rect(struct item_bin *ib, struct rect *r);
00204 int attr_bin_write_data(struct attr_bin *ab, enum attr_type type, void *data, int size);
00205 int attr_bin_write_attr(struct attr_bin *ab, struct attr *attr);
00206 void item_bin_add_attr_data(struct item_bin *ib, enum attr_type type, void *data, int size);
00207 void item_bin_add_attr(struct item_bin *ib, struct attr *attr);
00208 void item_bin_add_attr_int(struct item_bin *ib, enum attr_type type, int val);
00209 void *item_bin_get_attr(struct item_bin *ib, enum attr_type type, void *last);
00210 struct attr_bin * item_bin_get_attr_bin(struct item_bin *ib, enum attr_type type, void *last);
00211 struct attr_bin * item_bin_get_attr_bin_last(struct item_bin *ib);
00212 void item_bin_add_attr_longlong(struct item_bin *ib, enum attr_type type, long long val);
00213 void item_bin_add_attr_string(struct item_bin *ib, enum attr_type type, char *str);
00214 void item_bin_add_attr_range(struct item_bin *ib, enum attr_type type, short min, short max);
00215 void item_bin_remove_attr(struct item_bin *ib, void *ptr);
00216 void item_bin_write(struct item_bin *ib, FILE *out);
00217 struct item_bin *item_bin_dup(struct item_bin *ib);
00218 void item_bin_write_range(struct item_bin *ib, FILE *out, int min, int max);
00219 void item_bin_write_clipped(struct item_bin *ib, struct tile_parameter *param, struct item_bin_sink *out);
00220 void item_bin_dump(struct item_bin *ib, FILE *out);
00221 void dump_itembin(struct item_bin *ib);
00222 void item_bin_set_type_by_population(struct item_bin *ib, int population);
00223 void item_bin_write_match(struct item_bin *ib, enum attr_type type, enum attr_type match, FILE *out);
00224 int item_bin_sort_file(char *in_file, char *out_file, struct rect *r, int *size);
00225 
00226 /* itembin_buffer.c */
00227 struct node_item *read_node_item(FILE *in);
00228 struct item_bin *read_item(FILE *in);
00229 struct item_bin *read_item_range(FILE *in, int *min, int *max);
00230 struct item_bin *init_item(enum item_type type);
00231 
00232 /* maptool.c */
00233 
00234 extern long long slice_size;
00235 extern int attr_debug_level;
00236 extern char *suffix;
00237 extern int ignore_unkown;
00238 extern GHashTable *dedupe_ways_hash;
00239 extern int slices;
00240 extern struct buffer node_buffer;
00241 extern int processed_nodes, processed_nodes_out, processed_ways, processed_relations, processed_tiles;
00242 extern struct item_bin *item_bin;
00243 extern int bytes_read;
00244 extern int overlap;
00245 extern int unknown_country;
00246 extern int experimental;
00247 void sig_alrm(int sig);
00248 void sig_alrm_end(void);
00249 
00250 /* misc.c */
00251 extern struct rect world_bbox;
00252 
00253 
00254 void bbox_extend(struct coord *c, struct rect *r);
00255 void bbox(struct coord *c, int count, struct rect *r);
00256 int contains_bbox(int xl, int yl, int xh, int yh, struct rect *r);
00257 int bbox_contains_coord(struct rect *r, struct coord *c);
00258 int bbox_contains_bbox(struct rect *out, struct rect *in);
00259 long long bbox_area(struct rect const *r);
00260 void phase1_map(GList *maps, FILE *out_ways, FILE *out_nodes);
00261 void dump(FILE *in);
00262 int phase4(FILE **in, int in_count, int with_range, char *suffix, FILE *tilesdir_out, struct zip_info *zip_info);
00263 int phase5(FILE **in, FILE **references, int in_count, int with_range, char *suffix, struct zip_info *zip_info);
00264 void process_binfile(FILE *in, FILE *out);
00265 void add_aux_tiles(char *name, struct zip_info *info);
00266 void cat(FILE *in, FILE *out);
00267 
00268 
00269 /* osm.c */
00270 struct maptool_osm {
00271         FILE *boundaries;
00272         FILE *turn_restrictions;
00273         FILE *nodes;
00274         FILE *ways;
00275         FILE *line2poi;
00276         FILE *poly2poi;
00277         FILE *towns;
00278 };
00279 
00280 void osm_warning(char *type, long long id, int cont, char *fmt, ...);
00281 void osm_info(char *type, long long id, int cont, char *fmt, ...);
00282 void osm_add_tag(char *k, char *v);
00283 void osm_add_node(osmid id, double lat, double lon);
00284 void osm_add_way(osmid id);
00285 void osm_add_relation(osmid id);
00286 void osm_end_relation(struct maptool_osm *osm);
00287 void osm_add_member(int type, osmid ref, char *role);
00288 void osm_end_way(struct maptool_osm *osm);
00289 void osm_end_node(struct maptool_osm *osm);
00290 void osm_add_nd(osmid ref);
00291 long long item_bin_get_id(struct item_bin *ib);
00292 void flush_nodes(int final);
00293 void sort_countries(int keep_tmpfiles);
00294 void process_turn_restrictions(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out);
00295 void process_turn_restrictions_old(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out);
00296 void clear_node_item_buffer(void);
00297 void ref_ways(FILE *in);
00298 void resolve_ways(FILE *in, FILE *out);
00299 long long item_bin_get_nodeid(struct item_bin *ib);
00300 long long item_bin_get_wayid(struct item_bin *ib);
00301 long long item_bin_get_relationid(struct item_bin *ib);
00302 FILE *resolve_ways_file(FILE *in, char *suffix, char *filename);
00303 void process_way2poi(FILE *in, FILE *out, int type);
00304 int map_find_intersections(FILE *in, FILE *out, FILE *out_index, FILE *out_graph, FILE *out_coastline, int final);
00305 void write_countrydir(struct zip_info *zip_info);
00306 void osm_process_towns(FILE *in, FILE *boundaries, FILE *ways);
00307 void load_countries(void);
00308 void remove_countryfiles(void);
00309 struct country_table * country_from_iso2(char *iso);
00310 void osm_init(FILE*);
00311 
00312 /* osm_o5m.c */
00313 int map_collect_data_osm_o5m(FILE *in, struct maptool_osm *osm);
00314 
00315 /* osm_psql.c */
00316 int map_collect_data_osm_db(char *dbstr, struct maptool_osm *osm);
00317 
00318 /* osm_protobuf.c */
00319 int map_collect_data_osm_protobuf(FILE *in, struct maptool_osm *osm);
00320 int osm_protobufdb_load(FILE *in, char *dir);
00321 
00322 /* osm_relations.c */
00323 struct relations * relations_new(void);
00324 struct relations_func *relations_func_new(void (*func)(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv), void *func_priv);
00325 void relations_add_func(struct relations *rel, struct relations_func *func, void *relation_priv, void *member_priv, int type, osmid id);
00326 void relations_process(struct relations *rel, FILE *nodes, FILE *ways, FILE *relations);
00327 
00328 
00329 /* osm_xml.c */
00330 int osm_xml_get_attribute(char *xml, char *attribute, char *buffer, int buffer_size);
00331 void osm_xml_decode_entities(char *buffer);
00332 int map_collect_data_osm(FILE *in, struct maptool_osm *osm);
00333 
00334 
00335 /* sourcesink.c */
00336 
00337 struct item_bin_sink *item_bin_sink_new(void);
00338 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));
00339 void item_bin_sink_func_destroy(struct item_bin_sink_func *func);
00340 void item_bin_sink_add_func(struct item_bin_sink *sink, struct item_bin_sink_func *func);
00341 void item_bin_sink_destroy(struct item_bin_sink *sink);
00342 int item_bin_write_to_sink(struct item_bin *ib, struct item_bin_sink *sink, struct tile_data *tile_data);
00343 struct item_bin_sink *file_reader_new(FILE *in, int limit, int offset);
00344 int file_reader_finish(struct item_bin_sink *sink);
00345 int file_writer_process(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data);
00346 struct item_bin_sink_func *file_writer_new(FILE *out);
00347 int file_writer_finish(struct item_bin_sink_func *file_writer);
00348 int tile_collector_process(struct item_bin_sink_func *tile_collector, struct item_bin *ib, struct tile_data *tile_data);
00349 struct item_bin_sink_func *tile_collector_new(struct item_bin_sink *out);
00350 
00351 /* tempfile.c */
00352 
00353 char *tempfile_name(char *suffix, char *name);
00354 FILE *tempfile(char *suffix, char *name, int mode);
00355 void tempfile_unlink(char *suffix, char *name);
00356 void tempfile_rename(char *suffix, char *from, char *to);
00357 
00358 /* tile.c */
00359 extern GHashTable *tile_hash,*tile_hash2;
00360 
00361 struct aux_tile {
00362         char *name;
00363         char *filename;
00364         int size;
00365 };
00366 
00367 extern GList *aux_tile_list;
00368 
00369 int tile(struct rect *r, char *suffix, char *ret, int max, int overlap, struct rect *tr);
00370 void tile_bbox(char *tile, struct rect *r, int overlap);
00371 int tile_len(char *tile);
00372 void load_tilesdir(FILE *in);
00373 void tile_write_item_to_tile(struct tile_info *info, struct item_bin *ib, FILE *reference, char *name);
00374 void tile_write_item_minmax(struct tile_info *info, struct item_bin *ib, FILE *reference, int min, int max);
00375 int add_aux_tile(struct zip_info *zip_info, char *name, char *filename, int size);
00376 int write_aux_tiles(struct zip_info *zip_info);
00377 int create_tile_hash(void);
00378 void write_tilesdir(struct tile_info *info, struct zip_info *zip_info, FILE *out);
00379 void merge_tiles(struct tile_info *info);
00380 struct attr map_information_attrs[32];
00381 void index_init(struct zip_info *info, int version);
00382 void index_submap_add(struct tile_info *info, struct tile_head *th);
00383 
00384 /* zip.c */
00385 void write_zipmember(struct zip_info *zip_info, char *name, int filelen, char *data, int data_size);
00386 void zip_write_index(struct zip_info *info);
00387 int zip_write_directory(struct zip_info *info);
00388 struct zip_info *zip_new(void);
00389 void zip_set_md5(struct zip_info *info, int on);
00390 int zip_get_md5(struct zip_info *info, unsigned char *out);
00391 void zip_set_zip64(struct zip_info *info, int on);
00392 void zip_set_compression_level(struct zip_info *info, int level);
00393 void zip_set_maxnamelen(struct zip_info *info, int max);
00394 int zip_get_maxnamelen(struct zip_info *info);
00395 int zip_add_member(struct zip_info *info);
00396 int zip_set_timestamp(struct zip_info *info, char *timestamp);
00397 int zip_set_password(struct zip_info *info, char *password);
00398 void zip_open(struct zip_info *info, char *out, char *dir, char *index);
00399 FILE *zip_get_index(struct zip_info *info);
00400 int zip_get_zipnum(struct zip_info *info);
00401 void zip_set_zipnum(struct zip_info *info, int num);
00402 void zip_close(struct zip_info *info);
00403 void zip_destroy(struct zip_info *info);