/* Node type */
typedef struct _node node;
struct _node {
- gint32 id;
+ guint32 id;
gfloat lat;
gfloat lon;
node_data *data;
/* Segment */
typedef struct _segment segment;
struct _segment {
- gint32 id;
- gint32 from;
- gint32 to;
+ guint32 id;
+ guint32 from;
+ guint32 to;
};
typedef struct _way_data way_data;
/* Segment/Way structure */
typedef struct _way way;
struct _way {
- gint32 id;
+ guint32 id;
way_type_t type;
guint16 ncnt;
guint8 flags;
static GHashTable *osm_nodes=NULL;
static GHashTable *osm_segments=NULL;
-static GHashTable *osm_ways=NULL;
+static GSList *osm_ways=NULL;
static GSList *osm_poi=NULL;
static node *cnode=NULL;
if (n->data->desc)
sqlite3_bind_text(sql.insert_poi, 5, n->data->desc, -1, SQLITE_TRANSIENT);
#endif
+
sqlite3_bind_int(sql.insert_poi, 6, n->data->type);
sqlite3_bind_int(sql.insert_poi, 7, n->data->type/100);
sqlite3_step(sql.insert_way_seg);
sqlite3_reset(sql.insert_way_seg);
sqlite3_clear_bindings(sql.insert_way_seg);
+/* XXX: make this sooner ? */
db_update_node_links(n);
wsegcnt++;
node *f;
node *t;
+if (!s) {
+ g_printf("ERROR: null segment!\n");
+ return;
+}
+
+if (!w) {
+ g_printf("ERROR: null way!\n");
+ return;
+}
+
f=osm_find_node(s->from);
t=osm_find_node(s->to);
if (!f)
segment *
osm_get_segment_for_way(gint sid)
{
-return g_hash_table_lookup(osm_segments, GINT_TO_POINTER(sid));
+segment *s;
+s=g_hash_table_lookup(osm_segments, GINT_TO_POINTER(sid));
+if (!s)
+ g_printf("ERROR: Segment %d not found!\n", sid);
+return s;
}
node *
osm_find_node(gint nid)
{
-return g_hash_table_lookup(osm_nodes, GINT_TO_POINTER(nid));
+node *n;
+n=g_hash_table_lookup(osm_nodes, GINT_TO_POINTER(nid));
+if (!n)
+ g_printf("ERROR: Node %d not found!\n", nid);
+return n;
}
void
w->ncnt=0;
w->flags=0;
-g_hash_table_insert(osm_ways, GINT_TO_POINTER(id), w);
+osm_ways=g_slist_prepend(osm_ways, w);
return w;
}
segment *s;
s=osm_get_segment_for_way(id);
-w->nodes=g_slist_append(w->nodes, s);
+w->nodes=g_slist_prepend(w->nodes, s);
w->ncnt++;
}
{
dbnode_cnt++;
db_insert_node(value);
-if (dbnode_cnt % 262140==0)
- g_printf("Nodes: %d\n", dbnode_cnt);
+if (dbnode_cnt % 26214==0)
+ g_printf("Nodes: %f%%\n",((float)dbnode_cnt/(float)node_cnt)*100);
}
void
/*********************************************************************/
void
-osm_node_save_way(gint key, way *value, gpointer user_data)
+osm_node_save_way(way *value, gpointer user_data)
{
dbway_cnt++;
db_insert_way(value);
-if (dbway_cnt % 26214==0)
- g_printf("Ways: %d\n", dbway_cnt);
+if (dbway_cnt % 8192==0) {
+ g_printf("Ways: %f%%\n",(((float)dbway_cnt/(float)way_cnt)*100));
+ print_way(value);
+}
}
void
{
g_print("Storing ways...\n");
-sqlite3_exec(db, "begin;", NULL, NULL, NULL);
+g_print("Clearing old data:\n");
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);
+
+g_print("Inserting new ways:\n");
+sqlite3_exec(db, "begin;", NULL, NULL, NULL);
+g_slist_foreach(osm_ways, osm_node_save_way, NULL);
sqlite3_exec(db, "commit;", NULL, NULL, NULL);
}
{
tag_state_t t;
gchar *k, *v;
+guint32 id;
t=check_tag(name);
switch (t) {
case IN_NODE_TAG:
tag_parent=IS_NODE;
node_cnt++;
- cnode=osm_new_node(atoi(get_attr_key_value(atts, "id")),
+
+ id=atoi(get_attr_key_value(atts, "id"));
+
+ cnode=osm_new_node(id,
atof(get_attr_key_value(atts, "lat")),
atof(get_attr_key_value(atts, "lon")));
break;
case IN_SEGMENT_TAG:
tag_parent=IS_SEGMENT;
seg_cnt++;
- osm_new_segment(atoi(get_attr_key_value(atts, "id")),
- atof(get_attr_key_value(atts, "from")),
- atof(get_attr_key_value(atts, "to")));
+
+ id=atoi(get_attr_key_value(atts, "id"));
+
+ osm_new_segment(id,
+ atoi(get_attr_key_value(atts, "from")),
+ atoi(get_attr_key_value(atts, "to")));
break;
case IN_WAY_TAG:
tag_parent=IS_WAY;
way_cnt++;
- cway=osm_new_way(atoi(get_attr_key_value(atts, "id")));
+ id=atoi(get_attr_key_value(atts, "id"));
+ cway=osm_new_way(id);
break;
case IN_SEG_TAG:
- osm_way_new_seg(cway, atoi(get_attr_key_value(atts, "id")));
+ id=atoi(get_attr_key_value(atts, "id"));
+ osm_way_new_seg(cway, id);
break;
case IN_KEY_TAG:
switch (tag_parent) {
if (way_cnt % 32767==0) {
g_printf("Ways: %d\n", way_cnt);
}
+ cway->nodes=g_slist_reverse(cway->nodes);
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);
osm_nodes=g_hash_table_new(g_direct_hash, g_direct_equal);
osm_segments=g_hash_table_new(g_direct_hash, g_direct_equal);
-osm_ways=g_hash_table_new(g_direct_hash, g_direct_equal);
osm_planet_parse_file(argv[1]);
g_hash_table_unref(osm_nodes);
g_hash_table_unref(osm_segments);
-g_hash_table_unref(osm_ways);
sqlite3_close(db);
sync();