static gint way_cnt=0;
static gint seg_cnt=0;
+static gint dbnode_cnt=0;
+static gint dbnoded_cnt=0;
+static gint dbway_cnt=0;
+
typedef struct _node_data node_data;
struct _node_data {
gchar *name;
gint32 id;
way_type_t type;
guint16 ncnt;
- guint flags;
+ guint8 flags;
way_data *data;
GSList *nodes;
};
static GHashTable *osm_nodes=NULL;
static GHashTable *osm_segments=NULL;
static GHashTable *osm_ways=NULL;
+static GSList *osm_poi=NULL;
static node *cnode=NULL;
static way *cway=NULL;
-1, &sql.insert_way_ref, NULL);
sqlite3_prepare_v2(db, "delete from way_ref", -1,
&sql.delete_way_ref, NULL);
+
+/* Turn of syncing to speed up data import */
+sqlite3_exec(db, "PRAGMA synchronous = OFF;", NULL, NULL, NULL);
+
}
/********************************************************************/
gboolean
db_insert_way(way *w)
{
+if (!w)
+ return FALSE;
+
if (w->type==WAY_UNWAYED)
return TRUE;
wsegcnt=0;
g_slist_foreach(w->nodes, db_insert_way_segments, w);
-print_way(w);
osm_free_way_data(w);
return TRUE;
void
osm_node_save_node(gint key, node *value, gpointer user_data)
{
+dbnode_cnt++;
db_insert_node(value);
+if (dbnode_cnt % 262140==0)
+ g_printf("Nodes: %d\n", dbnode_cnt);
}
void
-osm_node_save_poi(gint key, node *value, gpointer user_data)
+osm_node_save_poi(node *value, gpointer user_data)
{
-if (value->data==NULL)
+if (!value) {
+ g_printf("ERROR: null poi\n");
+ return;
+}
+
+if (!value->data)
return;
if (value->data->type>NODE_POI_START && value->data->type<NODE_POI_END) {
db_insert_poi(value);
- /* Free the extra info, we don't need it anymore */
- osm_free_node_data(value);
} else if (value->data->type>NODE_PLACE_START && value->data->type<NODE_PLACE_END) {
db_insert_place(value);
- osm_free_node_data(value);
}
+/* Free the extra info, we don't need it anymore */
+osm_free_node_data(value);
+
}
void
osm_planet_poi_save_nodes(void)
{
g_print("Storing new POIs...\n");
-g_hash_table_foreach(osm_nodes, osm_node_save_poi, NULL);
+sqlite3_exec(db, "begin;", NULL, NULL, NULL);
+g_slist_foreach(osm_poi, osm_node_save_poi, NULL);
+sqlite3_exec(db, "commit;", NULL, NULL, NULL);
}
/*********************************************************************/
void
osm_node_save_way(gint key, way *value, gpointer user_data)
{
+dbway_cnt++;
db_insert_way(value);
+if (dbway_cnt % 26214==0)
+ g_printf("Ways: %d\n", dbway_cnt);
}
void
void
osm_planet_save_to_db(void)
{
+g_printf("Saving planet to database:\n");
osm_planet_poi_clear_nodes();
osm_planet_poi_save_nodes();
osm_planet_save_nodes();
osm_planet_save_ways();
+g_printf("Data saved.\n");
}
/***********************************************************************/
t=check_tag(name);
switch (t) {
case IN_NODE_TAG:
- if (node_cnt % 100000==0) {
+ if (node_cnt % 262140==0) {
g_printf("Nodes: %d/%d\n", node_cnt, noded_cnt);
}
if (cnode->data && cnode->data->type==NODE_PLAIN)
osm_free_node_data(cnode);
+ else if (cnode->data) {
+ osm_poi=g_slist_append(osm_poi, cnode);
+ }
cnode=NULL;
break;
case IN_WAY_TAG:
- if (way_cnt % 10000==0) {
+ if (way_cnt % 32767==0) {
g_printf("Ways: %d\n", way_cnt);
}
if (cway->data && cway->data->name==NULL && cway->data->ref==NULL &&
osm_planet_parse_file(argv[1]);
-g_printf("Total nodes %d/%d segments %d and ways %d\n",
+g_printf("Planet loaded.\nTotal nodes %d, POIs: %d, Segments %d and Ways %d.\n",
node_cnt, noded_cnt, seg_cnt, way_cnt);
osm_planet_save_to_db();
g_hash_table_unref(osm_ways);
sqlite3_close(db);
+sync();
}