static struct map_bbox bbox;
static gboolean use_bbox;
-void osm_free_way_data(way *w);
-void print_way(way *w);
+static void osm_free_way_data(way *w);
+static void print_way(way *w);
-void db_prepare(sqlite3 *db);
-gboolean db_insert_node(node *n);
-guint32 osm_find_way_place(way *w, node_type_t nt);
+static void db_prepare(sqlite3 *db);
+static gboolean db_insert_node(node *n);
+static guint32 osm_find_way_place(way *w, node_type_t nt);
/****************************************************/
/* Functions */
/**
* Insert way ref and int_ref
*/
-static void
+static gboolean
db_insert_way_ref(way *w)
{
if (!w->data)
- return;
+ return TRUE;
if (!w->data->ref && !w->data->int_ref)
- return;
+ return TRUE;
way_refs++;
if (w->data->int_ref)
sqlite3_bind_text(sql.insert_way_ref, 3, w->data->int_ref, -1, SQLITE_TRANSIENT);
-db_exec(db,sql.insert_way_ref);
+return db_exec(db,sql.insert_way_ref);
}
/**
* Insert way name
*/
-static void
+static gboolean
db_insert_way_name(way *w)
{
gchar *norm;
if (!w->data)
- return;
+ return TRUE;
if (!w->data->name)
- return;
+ return TRUE;
way_names++;
g_free(norm);
#endif
-db_exec(db,sql.insert_way_name);
+return db_exec(db,sql.insert_way_name);
}
-static void
+static gboolean
db_delete_way_names_nls(way *w)
{
sqlite3_bind_int(sql.delete_way_names_nls, 1, w->id);
-db_exec(db,sql.delete_way_names_nls);
+return db_exec(db,sql.delete_way_names_nls);
}
-static void
+static gboolean
db_insert_way_pc(way *w)
{
if (!w->data)
- return;
+ return TRUE;
if (!w->data->postal_code)
- return;
+ return TRUE;
sqlite3_bind_int(sql.insert_way_pc, 1, w->id);
sqlite3_bind_text(sql.insert_way_pc, 2, w->data->postal_code, -1, SQLITE_TRANSIENT);
-db_exec(db,sql.insert_way_pc);
+return db_exec(db,sql.insert_way_pc);
}
-static void
+static gboolean
db_delete_way_pc(way *w)
{
sqlite3_bind_int(sql.delete_way_pc, 1, w->id);
-db_exec(db,sql.delete_way_pc);
+return db_exec(db,sql.delete_way_pc);
}
static void
print_way(w);
-/* Get middle node, use it as way location */
-ncnt=g_slist_length(w->nodes);
-if (ncnt>1)
- wmn=g_slist_nth_data(w->nodes, ncnt/2);
-else
- wmn=0;
-
sqlite3_bind_int(sql.insert_way_data, 1, w->id);
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, 6, w->data->isin_c);
sqlite3_bind_int(sql.insert_way_data, 7, w->data->isin_p);
}
-if (wmn) {
- sqlite3_bind_double(sql.insert_way_data, 8, wmn->lat);
- sqlite3_bind_double(sql.insert_way_data, 9, wmn->lon);
-} else {
- g_printerr("Failed to get way location node!\n");
+
+/* Get middle node, use it as a rough way location */
+ncnt=g_slist_length(w->nodes);
+if (ncnt>1) {
+ wmn=g_slist_nth_data(w->nodes, ncnt/2);
+ if (wmn) {
+ sqlite3_bind_double(sql.insert_way_data, 8, wmn->lat);
+ sqlite3_bind_double(sql.insert_way_data, 9, wmn->lon);
+ } else {
+ g_printerr("Failed to get way middlepoint node for location information!\n");
+ }
}
db_exec(db,sql.insert_way_data);
node *n;
g_assert(osm_nodes);
-n=g_hash_table_lookup(osm_nodes, GINT_TO_POINTER(nid));
-#if 0
-if (!n)
- g_printerr("ERROR: Node %d not found!\n", nid);
-#endif
-return n;
+return g_hash_table_lookup(osm_nodes, GINT_TO_POINTER(nid));
}
static void
return w;
}
+static void
+osm_free_way(way *w)
+{
+if (w->nodes)
+ g_slist_free(w->nodes);
+g_slice_free(way, w);
+}
+
static void
osm_way_add_to_list(way *w)
{
static gboolean
osm_planet_save_nodes(void)
{
-g_print("Storing nodes\n");
+g_print("Storing nodes...\n");
db_transaction_begin(db);
g_hash_table_foreach(osm_nodes, osm_node_save_node, NULL);
return db_transaction_commit(db);
if (cway->id!=0)
osm_way_add_to_list(cway);
+ else
+ osm_free_way(cway);
cway=NULL;
g_hash_table_destroy(osm_way_tags);
return res;
}
+/**
+ * Set up bounding box for import.
+ *
+ */
void
osm_import_set_bbox(gboolean use_bb, gdouble latmin, gdouble lonmin, gdouble latmax, gdouble lonmax)
{
bbox.lat_min, bbox.lon_min, bbox.lat_max, bbox.lon_max);
}
+/**
+ * Simple helper to do all preparations and importing from planet -> database
+ *
+ */
gboolean
osm_import(const gchar *planet, const gchar *database)
{