From: Kaj-Michael Lang Date: Mon, 16 Jul 2007 13:35:24 +0000 (+0300) Subject: Add start of functions for getting usefull way/route data out from the database. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f68b3183b8d6e1e6ca5f57cbecffb90bf0f90ab;p=mapper Add start of functions for getting usefull way/route data out from the database. --- diff --git a/src/osm-db.c b/src/osm-db.c new file mode 100644 index 0000000..71ef84a --- /dev/null +++ b/src/osm-db.c @@ -0,0 +1,79 @@ +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "osm.h" + +struct sql_select_stmt { + sqlite3_stmt *select_way; + sqlite3_stmt *select_way_nodes; + sqlite3_stmt *select_way_name; + sqlite3_stmt *select_way_ref; + sqlite3_stmt *select_place; +}; +static struct sql_select_stmt sql; + +gboolean +osm_init_sql_selects(void) +{ +/* Place */ +/* Select nearest place inside lat,lon+-range */ +sqlite3_prepare(db, "select name from place where type=? " + " and lat between $LAT-$RANGE and $LAT+$RANGE" + " and lon between $LON-$RANGE and $LON+$RANGE", + -1, &sql.select_place, NULL); + +/* Ways */ +/* Select neareset ways inside lat,lon+-range */ +sqlite3_prepare(db, "select wid from way,way_seg,nodes where wid=wsid and way_seg.node=nodes.nid " + " and nodes.lat between $LAT-$RANGE and $LAT+$RANGE " + " and nodes.lon between $LON-$RANGE and $LON+$RANGE " + " order by (($LAT-lat)*($LAT-lan))+(($LON-lon)*($LON-lon))", + -1, &sql.select_way_name, NULL); + +/* Select way nodes */ +sqlite3_prepare(db, "select wsid,lat,lon from way_seg,nodes where wsid=? and way_seg.node=nodes.nid", + -1, &sql.select_way_nodes, NULL); + +/* Way name and ref */ +sqlite3_prepare(db, "select name from way_names where wid=?", + -1, &sql.select_way_name, NULL); +sqlite3_prepare(db, "select ref,int_ref from way_ref where rid=?", + -1, &sql.select_way_ref, NULL); + +return TRUE; +} + +gboolean +osm_init() +{ +return TRUE; +} + +/** + * Search for the nearest place, type + */ +osm_place * +osm_find_nearest_place(gint type, gint lat, gint lon) +{ + +} + +/** + * Search for the nearest way (road) + */ +osm_way * +osm_find_nearest_way(gint lat, gint lon) +{ + +}