]> err.no Git - mapper/commitdiff
Some more way search stuff
authorKaj-Michael Lang <milang@tal.org>
Thu, 1 Nov 2007 00:39:35 +0000 (02:39 +0200)
committerKaj-Michael Lang <milang@tal.org>
Thu, 1 Nov 2007 00:39:35 +0000 (02:39 +0200)
src/osm-db.c

index 0d111d27f88ea723afd9dccae12c1fb09c3c95b3..354b441b90f5c0a80b8e99c140eb4bb17cb81c37 100644 (file)
@@ -139,12 +139,12 @@ osm_db_prepare(sqlite3 *db)
 {
 /* 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,"
-                                       " lat,lon,places.nid,isin "
+if (sqlite3_prepare_v2(db, "select name,(($LAT-ilat)*($LAT-ilat))+(($LON-ilon)*($LON-ilon)) as dist,"
+                                       " ilat,ilon,places.nid,isin "
                                        " from places,nodes where type=$TYPE "
                                        " and nodes.nid=places.nid "
-                                       " and lat between $LAT-$RANGE and $LAT+$RANGE"
-                                       " and lon between $LON-$RANGE and $LON+$RANGE order by dist limit 1",
+                                       " and ilat between $LAT-$RANGE and $LAT+$RANGE"
+                                       " and ilon between $LON-$RANGE and $LON+$RANGE order by dist limit 1",
                    -1, &sql.select_near_place, NULL)!=SQLITE_OK)
        return FALSE;
 
@@ -160,7 +160,7 @@ if (sqlite3_prepare_v2(db, "select name,(($LAT-lat)*($LAT-lat))+(($LON-lon)*($LO
 /* Ways */
 /* Select nearest ways inside lat,lon+-range */
 if (sqlite3_prepare_v2(db, "select wid,type,nodes,flags,"
-                                       "(($LAT-lat)*($LAT-lat))+(($LON-lon)*($LON-lon)) as d,wn.f,wn.t,n.lat,n.lon "
+                                       "(($LAT-n.lat)*($LAT-n.lat))+(($LON-n.lon)*($LON-n.lon)) as d,wn.f,wn.t,n.lat,n.lon "
                                        " from way as w,way_n2n as wn,nodes as n "
                                        " where w.wid=wn.wsid and wn.f=n.nid "
                                        " and n.lat between $LAT-$RANGE and $LAT+$RANGE "
@@ -171,18 +171,18 @@ if (sqlite3_prepare_v2(db, "select wid,type,nodes,flags,"
        return FALSE;
 
 if (sqlite3_prepare_v2(db, "select w.wid,w.name as name,"
-                                       "(($LAT-lat)*($LAT-lat))+(($LON-lon)*($LON-lon)) as d,wn.f,w.lat,wlon "
+                                       "(($LAT-ww.lat)*($LAT-ww.lat))+(($LON-ww.lon)*($LON-ww.lon)) as d,ww.lat,ww.lon "
                                        " from way_names as w,way as ww where "
                                        " ww.type between $WTS and $WTY and w.wid=ww.wid and w.name like $NAME "
-                                       " and w.lat between $LAT-$RANGE and $LAT+$RANGE "
-                                       " and w.lon between $LON-$RANGE and $LON+$RANGE "
+                                       " and ww.lat between $LAT-$RANGE and $LAT+$RANGE "
+                                       " and ww.lon between $LON-$RANGE and $LON+$RANGE "
                                        " union "
                                        " select w.wid,n.name as name,"
-                                       "(($LAT-w.lat)*($LAT-w.lat))+(($LON-w.lon)*($LON-w.lon)) as d,wn.f,w.lat,wlon "
+                                       "(($LAT-ww.lat)*($LAT-ww.lat))+(($LON-ww.lon)*($LON-w.lon)) as d,ww.lat,ww.lon "
                                        " from way_names as w, way as ww,way_names_nls as n on w.wid=n.wid where "
                                        " ww.type between $WTS and $WTY and w.wid=ww.wid and n.name like $NAME "
-                                       " and w.lat between $LAT-$RANGE and $LAT+$RANGE "
-                                       " and w.lon between $LON-$RANGE and $LON+$RANGE "
+                                       " and ww.lat between $LAT-$RANGE and $LAT+$RANGE "
+                                       " and ww.lon between $LON-$RANGE and $LON+$RANGE "
                                        " order by d",
                        -1, &sql.select_way_name_search, NULL)!=SQLITE_OK)
        return FALSE;
@@ -920,6 +920,12 @@ if (check_place==TRUE && d>way_dist_range*4) {
 return map_loc->street ? TRUE : FALSE;
 }
 
+/**
+ * osm_way_search
+ *
+ * Search for a street(way) starting with given 'text', next given lat/lon
+ *
+ */
 gboolean
 osm_way_search(gdouble lat, gdouble lon, gchar *text, GtkListStore **store)
 {
@@ -933,7 +939,6 @@ g_printf("Way Search: [%s] around %.6f %.6f\n", text, lat, lon);
 
 ltext=g_strdup_printf("%s%%", text);
 
-
 if (SQLITE_OK != sqlite3_bind_double(sql.select_way_name_search, 1, lat) ||
     SQLITE_OK != sqlite3_bind_double(sql.select_way_name_search, 2, lon) ||
     SQLITE_OK != sqlite3_bind_int(sql.select_way_name_search,   3, WAY_ROAD_START) ||
@@ -946,6 +951,9 @@ if (SQLITE_OK != sqlite3_bind_double(sql.select_way_name_search, 1, lat) ||
                return FALSE;
 }
 
+if (ltext)
+       g_free(ltext);
+
 *store = gtk_list_store_new(ITEM_NUM_COLUMNS, 
                                G_TYPE_INT,             /* ID */
                                G_TYPE_INT,             /* Category ID */
@@ -955,28 +963,26 @@ if (SQLITE_OK != sqlite3_bind_double(sql.select_way_name_search, 1, lat) ||
                                G_TYPE_STRING,  /* Lat/Lon */
                                G_TYPE_STRING,  /* Label */
                                G_TYPE_STRING,  /* Desc. */
-                               G_TYPE_STRING); /* Category Label */
+                               G_TYPE_STRING); /* Category */
 
 while (SQLITE_ROW == sqlite3_step(sql.select_way_name_search)) {
        gdouble rlat, rlon, dist;
 
-       rlat=sqlite3_column_double(sql.select_way_name_search, 0);
-       rlon=sqlite3_column_double(sql.select_way_name_search, 1);
+       rlat=sqlite3_column_double(sql.select_way_name_search, 2);
+       rlon=sqlite3_column_double(sql.select_way_name_search, 3);
        lat_format(rlat, tmp1);
        lon_format(rlon, tmp2);
        dist=0.0;
 
        gtk_list_store_append(*store, &iter);
        gtk_list_store_set(*store, &iter,
-               ITEM_ID, sqlite3_column_int(sql.select_way_name_search, 2),
-               ITEM_CATID, sqlite3_column_int(sql.select_way_name_search, 5),
+               ITEM_ID, sqlite3_column_int(sql.select_way_name_search, 0),
                ITEM_LAT, rlat,
                ITEM_LON, rlon,
                ITEM_DIST, dist,
                ITEM_LATLON, g_strdup_printf("%s, %s", tmp1, tmp2),
-               ITEM_LABEL, sqlite3_column_text(sql.select_way_name_search, 3),
+               ITEM_LABEL, sqlite3_column_text(sql.select_way_name_search, 1),
                ITEM_DESC, sqlite3_column_text(sql.select_way_name_search, 4),
-               ITEM_CATLAB, sqlite3_column_text(sql.select_way_name_search, 6),
                -1);
        rows++;
 }
@@ -986,9 +992,6 @@ g_printf("Found: %d items\n", rows);
 sqlite3_reset(sql.select_way_name_search);
 sqlite3_clear_bindings(sql.select_way_name_search);
 
-if (ltext)
-       g_free(ltext);
-
 return TRUE;
 }