]> err.no Git - mapper/commitdiff
Add (start) of function to get next/prev node. Clenup struct variables.
authorKaj-Michael Lang <milang@tal.org>
Tue, 6 Nov 2007 10:37:25 +0000 (12:37 +0200)
committerKaj-Michael Lang <milang@tal.org>
Tue, 6 Nov 2007 10:37:25 +0000 (12:37 +0200)
src/osm-db.c
src/osm-db.h
src/osm.h

index 2004bf4b36c56d6acc0867ad9ddaa07c322be753..317a1b046bc66c990d64863c31d01653dba73643 100644 (file)
@@ -215,7 +215,7 @@ if (sqlite3_prepare_v2(db, "select w.wid,w.type,w.flags,w.speed,n.nid,n.rlat,n.r
 
 if (sqlite3_prepare_v2(db, "select w.wid,w.type,w.flags,w.speed,n.nid,n.rlat,n.rlon,nn.f,nn.t,n.f,n.l "
                        "from way as w, nodes as n, way_n2n as nn where w.wid=nn.wid and nn.f=n.nid and nn.t=?",
-                   -1, &sql.select_node_next, NULL)!=SQLITE_OK)
+                   -1, &sql.select_node_prev, NULL)!=SQLITE_OK)
        return FALSE;
 
 return TRUE;
@@ -415,7 +415,8 @@ if (SQLITE_ROW == sqlite3_step(sql.select_place)) {
        n->lat=sqlite3_column_int(sql.select_place, 2);
        n->lon=sqlite3_column_int(sql.select_place, 3);
        n->type=sqlite3_column_int(sql.select_place, 4);
-       n->isin=sqlite3_column_int(sql.select_place, 5);
+       n->isin_p=sqlite3_column_int(sql.select_place, 5);
+/*     n->isin_c=sqlite3_column_int(sql.select_place, 6); */
        return TRUE;
 }
 return FALSE;
@@ -459,7 +460,7 @@ if (SQLITE_OK != sqlite3_bind_int(sql.select_near_place, 1, lat) ||
 }
 
 n=osm_place_new();
-n->isin=n->lat=n->lon=n->dist=0;
+n->isin_p=n->lat=n->lon=n->dist=0;
 if (SQLITE_ROW == sqlite3_step(sql.select_near_place)) {
        const gchar *place;
        guint32 dist;
@@ -471,7 +472,8 @@ if (SQLITE_ROW == sqlite3_step(sql.select_near_place)) {
        n->lat=sqlite3_column_int(sql.select_near_place, 2);
        n->lon=sqlite3_column_int(sql.select_near_place, 3);
        n->id=sqlite3_column_int(sql.select_near_place, 4);
-       n->isin=sqlite3_column_int(sql.select_near_place, 5);
+       n->isin_p=sqlite3_column_int(sql.select_near_place, 5);
+/*     n->isin_c=sqlite3_column_int(sql.select_near_place, 6); */
        n->type=type;
 
        osm_place_cache_add(n);
@@ -544,6 +546,63 @@ return ways;
 
 /*****************************************************************************/
 
+GSList *
+osm_get_route_node(guint nid, osm_node_direction d)
+{
+GSList *r=NULL;
+osm_way *w;
+guint wc=0;
+sqlite3_stmt *psql;
+
+switch (d) {
+       case OSM_NODE_NEXT:
+               psql=sql.select_node_next;
+       break;
+       case OSM_NODE_PREV:
+               psql=sql.select_node_prev;
+       break;
+       default:
+               g_assert_not_reached();
+       break;
+}
+
+sqlite3_reset(psql);
+sqlite3_clear_bindings(psql);
+
+if (SQLITE_OK != sqlite3_bind_int(psql, 1, nid)) {
+       g_printerr("Failed to bind values for route node\n");
+       return NULL;
+}
+
+while (SQLITE_ROW == sqlite3_step(psql)) {
+       gdouble lat, lon;
+
+       wc++;
+       w=g_slice_new0(osm_way);
+       w->id=sqlite3_column_int(psql, 0);
+       w->type=sqlite3_column_int(psql, 1);
+       w->flags=sqlite3_column_int(psql, 2);
+       w->speed=sqlite3_column_int(psql, 3);
+
+       lat=sqlite3_column_double(psql, 5);
+       lon=sqlite3_column_double(psql, 6);
+
+       w->f=sqlite3_column_int(psql, 7);
+       w->t=sqlite3_column_int(psql, 8);
+#if 0
+       w->node=
+       w->node->flags=sqlite3_column_int(psql, 9);
+       w->node->links=sqlite3_column_int(psql, 10);
+#endif
+
+       r=g_slist_prepend(r, w);
+}
+
+return r;
+}
+
+
+/*****************************************************************************/
 gboolean 
 osm_way_distance(gint lat, gint lon, osm_way_node *f, osm_way_node *t, gdouble *d)
 {
@@ -905,8 +964,8 @@ if (check_place==TRUE && d>way_dist_range*4) {
        gboolean fs;
 
        fs=osm_find_nearest_place(NODE_PLACE_SUBURB, lat, lon, &map_loc->secondary);
-       if (fs==TRUE && map_loc->secondary && map_loc->secondary->isin!=0) {
-               if (osm_place_get(map_loc->secondary->isin, lat, lon, &(map_loc->primary))==FALSE) {
+       if (fs==TRUE && map_loc->secondary && map_loc->secondary->isin_p!=0) {
+               if (osm_place_get(map_loc->secondary->isin_p, lat, lon, &(map_loc->primary))==FALSE) {
                        if (osm_find_nearest_place(NODE_PLACE_CITY, lat, lon, &map_loc->primary)==TRUE)
                                g_printf("Near city: %s\n", map_loc->primary->name);
                        else if (osm_find_nearest_place(NODE_PLACE_TOWN, lat, lon, &map_loc->primary)==TRUE)
@@ -916,8 +975,8 @@ if (check_place==TRUE && d>way_dist_range*4) {
                } else {
                        g_printf("In: %s\n", map_loc->primary ? map_loc->primary->name : "?");
                }
-       } else if (map_loc->street && map_loc->street->isin!=0) {
-               if (osm_place_get(map_loc->street->isin, lat, lon, &map_loc->primary)==FALSE) {
+       } else if (map_loc->street && map_loc->street->isin_p!=0) {
+               if (osm_place_get(map_loc->street->isin_p, lat, lon, &map_loc->primary)==FALSE) {
                        g_printf("Street location not know.\n");
                } else {
                        g_printf("Street is in: %s\n", map_loc->primary ? map_loc->primary->name : "?");
index dccc2ed747c37a86f426d8299f6f2b59c5e5d6bf..92d97d5065e4b381075f30e9ce7ab5fedbeed97a 100644 (file)
 
 #define OSM_RANGE_WAY (20000)
 
+typedef enum {
+        OSM_NODE_NEXT,
+        OSM_NODE_PREV,
+} osm_node_direction;
+
 gboolean osm_init(sqlite3 **db);
 void osm_deinit(void);
 
+GSList *osm_get_route_node(guint nid, osm_node_direction d);
+
 void osm_set_way_range_from_speed(gfloat speed);
 void osm_set_way_range(guint sr);
 
index a4efefb7d2d63b3eee0d2c12529a2a36d999ff4c..84cb1f1fcee9b7979d28f58796b65bde12f9484d 100644 (file)
--- a/src/osm.h
+++ b/src/osm.h
@@ -197,14 +197,15 @@ struct _osm_place {
        gint lat;
        gint lon;
        gdouble dist;
-       guint32 isin;
+       guint32 isin_p;
+       guint32 isin_c;
 };
 
 /* Way node */
 typedef struct _osm_way_node osm_way_node;
 struct _osm_way_node {
-       guint id;
-       guint flags;
+       guint32 id;
+       guint32 flags;
        gint lat;
        gint lon;
 };
@@ -213,13 +214,14 @@ struct _osm_way_node {
 typedef struct _osm_way osm_way;
 struct _osm_way {
        guint32 id;
-       guint type;
-       guint flags;
-       guint nodecnt;
-       guint32 isin;
-       guint node_num;
-       guint f;
-       guint t;
+       guint32 isin_c;
+       guint32 isin_p;
+       gint16 type;
+       guint32 flags;
+       guint16 nodecnt;
+       guint32 f;
+       guint32 t;
+       gint8 speed;
        gdouble dist;
        gdouble distance;
        gchar *name;
@@ -227,7 +229,7 @@ struct _osm_way {
        gchar *int_ref;
        osm_way_node *node_f;
        osm_way_node *node_t;
-       gshort direction;
+       gint8 direction;
        GList *nodes;
 };