gchar *ref;
gchar *int_ref;
gchar *is_in;
+ gint8 layer;
};
/* Segment/Way structure */
struct _way {
gint32 id;
way_type_t type;
- gshort layer;
- gchar *name;
+ guint16 ncnt;
guint flags;
+ way_data *data;
GSList *nodes;
};
gint wsegcnt;
node *osm_find_node(gint nid);
+void osm_free_way_data(way *w);
+void print_way(way *w);
/****************************************************/
/* Functions */
sqlite3_prepare(db, "delete from way_seg", -1,
&sql.delete_way_seg, NULL);
-sqlite3_prepare(db, "insert into name (nid,name,lang) values (?, ?, ?)",
+sqlite3_prepare(db, "insert into way_names (wid,name) values (?, ?)",
-1, &sql.insert_way_name, NULL);
-sqlite3_prepare(db, "delete from name", -1,
+sqlite3_prepare(db, "delete from way_names", -1,
&sql.delete_way_name, NULL);
-sqlite3_prepare(db, "insert into ref (rid,ref,int_ref) values (?, ?, ?)",
+sqlite3_prepare(db, "insert into way_ref (rid,ref,int_ref) values (?, ?, ?)",
-1, &sql.insert_way_ref, NULL);
-sqlite3_prepare(db, "delete from ref", -1,
+sqlite3_prepare(db, "delete from way_ref", -1,
&sql.delete_way_ref, NULL);
}
sqlite3_bind_int(sql.insert_node, 3, lon);
sqlite3_step(sql.insert_node);
sqlite3_reset(sql.insert_node);
+sqlite3_clear_bindings(sql.insert_node);
return TRUE;
}
sqlite3_step(sql.insert_poi);
sqlite3_reset(sql.insert_poi);
+sqlite3_clear_bindings(sql.insert_poi);
return TRUE;
}
sqlite3_step(sql.update_node);
sqlite3_reset(sql.update_node);
+sqlite3_clear_bindings(sql.update_node);
}
void
sqlite3_step(sql.insert_way_seg);
sqlite3_reset(sql.insert_way_seg);
-
+sqlite3_clear_bindings(sql.insert_way_seg);
db_update_node_links(n);
wsegcnt++;
}
+void
+db_insert_way_ref(way *w)
+{
+if (!w->data)
+ return;
+
+if (!w->data->ref && !w->data->int_ref)
+ return;
+
+sqlite3_bind_int(sql.insert_way_ref, 1, w->id);
+if (w->data->ref)
+ sqlite3_bind_text(sql.insert_way_ref, 2, w->data->ref, -1, SQLITE_TRANSIENT);
+if (w->data->int_ref)
+ sqlite3_bind_text(sql.insert_way_ref, 3, w->data->int_ref, -1, SQLITE_TRANSIENT);
+
+sqlite3_step(sql.insert_way_ref);
+sqlite3_reset(sql.insert_way_ref);
+sqlite3_clear_bindings(sql.insert_way_ref);
+}
+
+void
+db_insert_way_names(way *w)
+{
+if (!w->data)
+ return;
+if (!w->data->name)
+ return;
+sqlite3_bind_int(sql.insert_way_name, 1, w->id);
+sqlite3_bind_text(sql.insert_way_name, 2, w->data->name, -1, SQLITE_TRANSIENT);
+
+sqlite3_step(sql.insert_way_name);
+sqlite3_reset(sql.insert_way_name);
+sqlite3_clear_bindings(sql.insert_way_name);
+}
+
void
db_insert_way_segments(segment *s, way *w)
{
return;
db_insert_way_seg(f,w);
-if (g_slist_length(w->nodes)==wsegcnt)
+if (w->ncnt==wsegcnt)
db_insert_way_seg(t,w);
}
return TRUE;
sqlite3_bind_int(sql.insert_way_data, 1, w->id);
-sqlite3_bind_int(sql.insert_way_data, 2, g_slist_length(w->nodes));
+sqlite3_bind_int(sql.insert_way_data, 2, w->ncnt);
sqlite3_bind_int(sql.insert_way_data, 3, w->type);
sqlite3_bind_int(sql.insert_way_data, 4, w->flags);
sqlite3_step(sql.insert_way_data);
sqlite3_reset(sql.insert_way_data);
+sqlite3_clear_bindings(sql.insert_way_data);
+
+db_insert_way_ref(w);
+db_insert_way_names(w);
wsegcnt=0;
-if (w->flags & W_AREA) {
-#if 1
- g_print("Areas not handled yet\n");
-#else
- g_slist_foreach(w->nodes, db_insert_area_segments, w);
-#endif
-} else {
- g_slist_foreach(w->nodes, db_insert_way_segments, w);
-}
+g_slist_foreach(w->nodes, db_insert_way_segments, w);
+print_way(w);
+osm_free_way_data(w);
return TRUE;
}
w->id,
g_slist_length(w->nodes),
w->type,
- w->name ? w->name : "",
+ w->data ? w->data->name ? w->data->name : "" : "",
w->flags & W_ONEWAY ? "-" : "=",
w->flags & W_ROUNDABOUT ? "O" : "-",
w->flags & W_LINK ? "|" : " ");
g_hash_table_insert(osm_segments, GINT_TO_POINTER(id), s);
}
+void
+osm_new_way_data(way *w)
+{
+if (w==NULL) return;
+if (w->data!=NULL) return;
+w->data=g_slice_new(way_data);
+w->data->name=NULL;
+w->data->ref=NULL;
+w->data->int_ref=NULL;
+w->data->layer=0;
+}
+
+void
+osm_free_way_data(way *w)
+{
+if (!w->data)
+ return;
+if (w->data->name)
+ g_free(w->data->name);
+if (w->data->ref)
+ g_free(w->data->ref);
+if (w->data->int_ref)
+ g_free(w->data->int_ref);
+g_slice_free(way_data, w->data);
+w->data=NULL;
+}
+
way *
osm_new_way(gint id)
{
w->id=id;
w->nodes=NULL;
w->type=WAY_UNWAYED;
-w->name=NULL;
-w->layer=0;
+w->data=NULL;
+w->ncnt=0;
w->flags=0;
g_hash_table_insert(osm_ways, GINT_TO_POINTER(id), w);
s=osm_get_segment_for_way(id);
w->nodes=g_slist_append(w->nodes, s);
+w->ncnt++;
}
/***********************************************************************/
sqlite3_exec(db, "begin;", NULL, NULL, NULL);
sqlite3_step(sql.delete_way);
+sqlite3_step(sql.delete_way_seg);
+sqlite3_step(sql.delete_way_name);
+sqlite3_step(sql.delete_way_ref);
g_hash_table_foreach(osm_ways, osm_node_save_way, NULL);
sqlite3_exec(db, "commit;", NULL, NULL, NULL);
}
k=get_attr_key_value(atts, "k");
v=get_attr_key_value(atts, "v");
+ osm_new_way_data(cway);
+
if (strcasecmp(k, "name")==0)
- cway->name=g_strdup(v);
-#if 0
+ cway->data->name=g_strdup(v);
else if (strcasecmp(k, "ref")==0)
- cway->ref=g_strdup(v);
+ cway->data->ref=g_strdup(v);
else if (strcasecmp(k, "int_ref")==0)
- cway->int_ref=g_strdup(v);
-#endif
-
- if (cway->type==WAY_UNWAYED) {
+ cway->data->int_ref=g_strdup(v);
+ else if (strcasecmp(k, "oneway")==0)
+ cway->flags|=W_ONEWAY;
+ else if (strcasecmp(k, "layer")==0)
+ cway->data->layer=atoi(v);
+ else if ((strcasecmp(k, "junction")==0) && (strcasecmp(v, "roundabout")==0)) {
+ cway->flags|=W_ROUNDABOUT;
+ cway->flags|=W_ONEWAY;
+ } else if ((strcasecmp(k, "junction")==0) && (strcasecmp(v, "mini_roundabout")==0)) {
+ cway->flags|=W_ROUNDABOUT;
+ cway->flags|=W_ONEWAY;
+ } else if (cway->type==WAY_UNWAYED) {
for (i=0; wayinfo[i].k; i++) {
if (strcasecmp (wayinfo[i].k, k)==0 && strcasecmp (v, wayinfo[i].v)==0) {
if (wayinfo[i].link==TRUE)
}
}
- if ((strcasecmp(k, "junction")==0) && (strcasecmp(v, "roundabout")==0)) {
- cway->flags|=W_ROUNDABOUT;
- cway->flags|=W_ONEWAY;
- } else if (strcasecmp(k, "oneway")==0)
- cway->flags|=W_ONEWAY;
- else if (strcasecmp(k, "layer")==0)
- cway->layer=atoi(v);
}
break;
case IS_SEGMENT:
if (way_cnt % 10000==0) {
g_printf("Ways: %d\n", way_cnt);
}
+ if (cway->data && cway->data->name==NULL && cway->data->ref==NULL &&
+ cway->data->int_ref==NULL && cway->data->layer==0)
+ osm_free_way_data(cway);
cway=NULL;
break;
case IN_SEGMENT_TAG: