2 * Hic Est Leo -- Representation of OSM Data
4 * (c) 2014 Martin Mares <mj@ucw.cz>
13 #define OSM_INVALID_ID ~(osm_id_t)0
15 typedef u32 osm_key_t, osm_val_t;
18 cnode n; // In the per-type list
19 byte type; // OSM_TYPE_xxx
23 clist backrefs; // Objects pointing to this one
26 enum osm_object_type {
31 OSM_TYPE_MULTIPOLYGON,
32 // Remember to update osm_obj_type_names[], too
37 cnode n; // In object->tags
52 * For WGS84 coordinates, x is longitude and y latitude.
53 * For UTM, x is easting and y northing.
54 * After map scaling, x is horizontal (left-to-right) and y vertical (top-to-bottom) on the paper.
60 clist nodes; // List of osm_ref's
65 clist members; // List of osm_ref's
68 struct osm_multipolygon { // Virtual object constructed from multipolygon relations
70 struct osm_relation *rel; // Original relation
71 clist boundaries; // List of osm_mpg_boundary's
74 struct osm_mpg_boundary {
77 clist nodes; // List of osm_ref's (without back-references, since the boundary is not a regular object)
82 clist obj_list[OSM_TYPE_MAX];
83 struct osm_id_hash_table *id_hash[OSM_TYPE_MAX];
84 uint obj_cnt[OSM_TYPE_MAX];
87 extern struct osm *osm_this;
89 struct osm *osm_init(void);
93 osm_id_t osm_parse_id(const char *str);
94 struct osm_object *osm_obj_find_by_id(enum osm_object_type type, osm_id_t id);
95 void osm_obj_add_tag(struct osm_object *o, const char *key, const char *val);
96 void osm_obj_add_tag_raw(struct osm_object *o, osm_key_t key, osm_val_t val);
97 osm_val_t osm_obj_find_tag(struct osm_object *o, osm_val_t key);
98 void osm_obj_dump(struct osm_object *o);
99 void osm_obj_warn(struct osm_object *o, const char *msg, ...);
100 extern const char * const osm_obj_type_names[OSM_TYPE_MAX];
101 #define STK_OSM_NAME(o) stk_printf("%s:%ju", osm_obj_type_names[(o)->type], (uintmax_t) (o)->id)
103 void osm_ref_add(struct osm_object *parent, clist *list, struct osm_object *son, osm_val_t role);
104 #define OSM_FOR_EACH_BEGIN(_type, _var, _list) CLIST_FOR_EACH(struct osm_ref *, _ref, _list) { _type _var = (_type) _ref->o;
105 #define OSM_FOR_EACH_END }
107 struct osm_node *osm_node_new(osm_id_t id);
108 void osm_node_dump(struct osm_node *n);
109 void osm_node_dump_all(void);
111 struct osm_way *osm_way_new(osm_id_t id);
112 void osm_way_add_node(struct osm_way *w, struct osm_node *n);
113 void osm_way_dump(struct osm_way *w);
114 void osm_way_dump_all(void);
115 bool osm_way_cyclic_p(struct osm_way *w);
117 struct osm_relation *osm_relation_new(osm_id_t id);
118 void osm_relation_add_member(struct osm_relation *r, struct osm_object *o, const char *role);
119 void osm_relation_dump(struct osm_relation *w);
120 void osm_relation_dump_all(void);
122 void osm_multipolygon_dump(struct osm_multipolygon *w);
123 void osm_multipolygon_dump_all(void);
124 void osm_make_multipolygons(void);
126 void osm_project(const char *spec);
128 bool osm_obj_center(struct osm_object *o, double *xp, double *yp);
132 extern struct dict osm_key_dict, osm_value_dict;
134 static inline osm_key_t osm_key_encode(const char *key)
136 return dict_encode(&osm_key_dict, key);
139 static inline const char *osm_key_decode(osm_key_t key)
141 return dict_decode(&osm_key_dict, key);
144 static inline osm_val_t osm_val_encode(const char *val)
146 return dict_encode(&osm_value_dict, val);
149 static inline const char *osm_val_decode(osm_val_t key)
151 return dict_decode(&osm_value_dict, key);
154 void osm_tag_dump(struct osm_tag *t);
156 /* Well-known tags and values */
160 #define P(x,y) KEY_##x,
161 #include "dict-keys.h"
167 #define P(x,y) VALUE_##x,
168 #include "dict-values.h"
174 void osm_xml_parse(const char *name);