]> err.no Git - mapper/commitdiff
Limit the way types queried to roads only. Add some timing debuging.
authorKaj-Michael Lang <milang@angel.tal.org>
Mon, 30 Jul 2007 11:01:08 +0000 (14:01 +0300)
committerKaj-Michael Lang <milang@angel.tal.org>
Mon, 30 Jul 2007 11:01:08 +0000 (14:01 +0300)
src/osm-db.c

index 5b4ae8f4d481c17705cc2c2f62061ed077a3c4f9..abff6cb2170a94f9cd46109c7ff8c1f1ff2b99ab 100644 (file)
@@ -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;
 }