]> mj.ucw.cz Git - leo.git/blobdiff - osm.c
Průvodce: Bi-directional Dijkstra balanced by distance
[leo.git] / osm.c
diff --git a/osm.c b/osm.c
index 325b592322287858a064f46faa10bd538b5fac96..17f2001ec10e6ea69a4cfa2ad2a84ceb167047e2 100644 (file)
--- a/osm.c
+++ b/osm.c
@@ -4,7 +4,8 @@
  *     (c) 2014 Martin Mares <mj@ucw.cz>
  */
 
-#include <ucw/lib.h>
+#include "leo.h"
+
 #include <ucw/gary.h>
 #include <ucw/mempool.h>
 #include <ucw/stkstring.h>
 
 #include <stdarg.h>
 #include <stdio.h>
+
+#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
 #include <proj_api.h>
 
-#include "leo.h"
 #include "osm.h"
 
 struct osm *osm_this;
@@ -74,6 +76,7 @@ static void *osm_obj_new(enum osm_object_type type, osm_id_t id, uns size)
 
   struct osm_object *o = mp_alloc_zero(osm_this->pool, size);
   clist_add_tail(&osm_this->obj_list[type], &o->n);
+  osm_this->obj_cnt[type]++;
   o->type = type;
   o->id = id;
   clist_init(&o->tags);
@@ -143,6 +146,23 @@ void osm_obj_add_tag(struct osm_object *o, const char *key, const char *val)
   osm_obj_add_tag_raw(o, osm_key_encode(key), osm_val_encode(val));
 }
 
+void osm_obj_set_tag_raw(struct osm_object *o, osm_key_t key, osm_val_t val)
+{
+  CLIST_FOR_EACH(struct osm_tag *, t, o->tags)
+    if (t->key == key)
+      {
+       t->val = val;
+       return;
+      }
+
+  osm_obj_add_tag_raw(o, key, val);
+}
+
+void osm_obj_set_tag(struct osm_object *o, const char *key, const char *val)
+{
+  osm_obj_set_tag_raw(o, osm_key_encode(key), osm_val_encode(val));
+}
+
 osm_val_t osm_obj_find_tag(struct osm_object *o, osm_key_t key)
 {
   CLIST_FOR_EACH(struct osm_tag *, t, o->tags)
@@ -381,7 +401,7 @@ static void mpg_walk_boundary(struct osm_multipolygon *m, bool inner)
          clist_init(&b->nodes);
 
          struct mpg_vertex *w = v;
-         while (!w->visited)
+         while (w && !w->visited)
            {
              w->visited = 1;
              struct osm_ref *f = mp_alloc(osm_this->pool, sizeof(*f));
@@ -411,7 +431,9 @@ static void mpg_walk_boundary(struct osm_multipolygon *m, bool inner)
              w = dest;
            }
 
-         if (w != v)
+         if (!w)
+           osm_obj_warn(&mpg_current->o, "Boundary not closed");
+         else if (w != v)
            osm_obj_warn(&mpg_current->o, "Boundary not closed at node %ju", (uintmax_t) w->o->id);
 
          struct osm_ref *f = mp_alloc(osm_this->pool, sizeof(*f));
@@ -444,7 +466,7 @@ static void osm_multipolygon_make(struct osm_relation *r)
          if (f->role != VALUE_INNER && f->role != VALUE_OUTER)
            {
              if (!inner)
-               osm_obj_warn(o, "Unknown role %s in multipolygon relation", osm_val_decode(f->role));
+               osm_obj_warn(o, "Unknown role %s in multipolygon relation", f->role ? osm_val_decode(f->role) : "<none>");
              continue;
            }
          if ((f->role == VALUE_INNER) != inner)
@@ -585,3 +607,11 @@ void osm_dump(void)
   osm_relation_dump_all();
   osm_multipolygon_dump_all();
 }
+
+void osm_stats(void)
+{
+  msg(L_INFO, "Loaded %u nodes, %u ways, %u relations",
+    osm_this->obj_cnt[OSM_TYPE_NODE],
+    osm_this->obj_cnt[OSM_TYPE_WAY],
+    osm_this->obj_cnt[OSM_TYPE_RELATION]);
+}