From: Kaj-Michael Lang Date: Mon, 30 Jul 2007 11:01:08 +0000 (+0300) Subject: Limit the way types queried to roads only. Add some timing debuging. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9558e16ecf1d0c288191b771da1127f562559e2d;p=mapper Limit the way types queried to roads only. Add some timing debuging. --- diff --git a/src/osm-db.c b/src/osm-db.c index 5b4ae8f..abff6cb 100644 --- a/src/osm-db.c +++ b/src/osm-db.c @@ -33,14 +33,27 @@ gboolean osm_way_get_nodes(osm_way *w); 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," @@ -69,6 +82,7 @@ if (sqlite3_prepare_v2(db, "select wid,type,nodes,flags," " 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; @@ -94,6 +108,7 @@ gboolean osm_init(void) { _place_cache=g_hash_table_new(g_direct_hash, g_direct_equal); +dbt=g_timer_new(); return TRUE; } @@ -101,6 +116,7 @@ void osm_deinit(void) { g_hash_table_destroy(_place_cache); +g_timer_destroy(dbt); } /*****************************************************************************/ @@ -310,20 +326,27 @@ osm_find_nearest_way_nodes(gint lat, gint lon, guint range) { 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); @@ -335,6 +358,9 @@ while (SQLITE_ROW == sqlite3_step(sql.select_way)) { 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; }