gboolean osm_way_get_name(osm_way *w);
gboolean osm_way_get_ref(osm_way *w);
+static GTimer *dbt;
+
/* Cache hash tables */
static GHashTable *_place_cache;
/*****************************************************************************/
+int
+osm_progress(void *ud)
+{
+g_print(".");
+return 0;
+}
+
gboolean
osm_db_prepare(sqlite3 *db)
{
+#ifdef DEBUG
+sqlite3_progress_handler(db, 1000, osm_progress, NULL);
+#endif
+
/* Place */
/* Select nearest place inside lat,lon+-range */
if (sqlite3_prepare_v2(db, "select name,(($LAT-lat)*($LAT-lat))+(($LON-lon)*($LON-lon)) as dist,"
" where wid=wsid and way_seg.node=nodes.nid "
" and lat between $LAT-$RANGE and $LAT+$RANGE "
" and lon between $LON-$RANGE and $LON+$RANGE "
+ " and type between $WTS and $WTY "
" order by dist",
-1, &sql.select_way, NULL)!=SQLITE_OK)
return FALSE;
osm_init(void)
{
_place_cache=g_hash_table_new(g_direct_hash, g_direct_equal);
+dbt=g_timer_new();
return TRUE;
}
osm_deinit(void)
{
g_hash_table_destroy(_place_cache);
+g_timer_destroy(dbt);
}
/*****************************************************************************/
{
GList *ways=NULL;
osm_way *w;
+gulong tms;
+gint wc=0;
sqlite3_reset(sql.select_way);
sqlite3_clear_bindings(sql.select_way);
if (SQLITE_OK != sqlite3_bind_int(sql.select_way, 1, lat) ||
SQLITE_OK != sqlite3_bind_int(sql.select_way, 2, lon) ||
- SQLITE_OK != sqlite3_bind_int(sql.select_way, 3, range)) {
+ SQLITE_OK != sqlite3_bind_int(sql.select_way, 3, range) ||
+ SQLITE_OK != sqlite3_bind_int(sql.select_way, 4, WAY_ROAD_START) ||
+ SQLITE_OK != sqlite3_bind_int(sql.select_way, 5, WAY_ROAD_END)) {
g_printerr("Failed to bind values for way\n");
return NULL;
}
+g_timer_start(dbt);
+
while (SQLITE_ROW == sqlite3_step(sql.select_way)) {
guint32 dist;
+ wc++;
w=g_slice_new0(osm_way);
w->id=sqlite3_column_int(sql.select_way, 0);
w->type=sqlite3_column_int(sql.select_way, 1);
ways=g_list_prepend(ways, w);
}
+g_timer_stop(dbt);
+g_printf("Query took: %f sec, found: %d ways\n", g_timer_elapsed(dbt, &tms), wc);
+
return ways;
}