From 69debb61152d11912c10513db3e7de38b23c8ece Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Mon, 16 Jul 2007 15:37:24 +0300 Subject: [PATCH] Handle all different place types instead of mergeing some. Use conversion helper in latlon.c/h --- src/osm.c | 76 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/src/osm.c b/src/osm.c index fde0b6b..0cd853d 100644 --- a/src/osm.c +++ b/src/osm.c @@ -13,11 +13,16 @@ #include #include "osm.h" +#include "latlon.h" -gint node_cnt=0; -gint noded_cnt=0; -gint way_cnt=0; -gint seg_cnt=0; +/* #define VERBOSE */ +#define FILE_BUFFER 65535 +#define OSM_DB_FILE "osm-planet.db" + +static gint node_cnt=0; +static gint noded_cnt=0; +static gint way_cnt=0; +static gint seg_cnt=0; typedef struct _node_data node_data; struct _node_data { @@ -106,9 +111,9 @@ struct _nodeinfo { { "railway", "halt", NODE_AMENITY_RAILWAY_HALT }, { "place", "city", NODE_PLACE_CITY }, - { "place", "town", NODE_PLACE_CITY }, + { "place", "town", NODE_PLACE_TOWN }, { "place", "village", NODE_PLACE_VILLAGE }, - { "place", "hamlet", NODE_PLACE_VILLAGE }, + { "place", "hamlet", NODE_PLACE_HAMLET }, { "place", "suburb", NODE_PLACE_SUBURB }, { "highway", "traffic_signals", NODE_TRAFFIC_SIGNALS }, @@ -146,15 +151,15 @@ struct _wayinfo { { NULL, NULL, WAY_UNWAYED, FALSE, FALSE, FALSE } }; -sqlite3 *db; +static sqlite3 *db; tag_parent_t tag_parent=IS_NONE; -GHashTable *osm_nodes=NULL; -GHashTable *osm_segments=NULL; -GHashTable *osm_ways=NULL; +static GHashTable *osm_nodes=NULL; +static GHashTable *osm_segments=NULL; +static GHashTable *osm_ways=NULL; -node *cnode=NULL; -way *cway=NULL; +static node *cnode=NULL; +static way *cway=NULL; struct sql_stmt { sqlite3_stmt *insert_poi; @@ -175,6 +180,7 @@ struct sql_stmt { sqlite3_stmt *delete_way_ref; sqlite3_stmt *insert_place; + sqlite3_stmt *delete_place; }; struct sql_stmt sql; @@ -209,6 +215,11 @@ sqlite3_prepare(db, "select lat,lon,l from nodes where nid=?", sqlite3_prepare(db, "delete from nodes", -1, &sql.delete_nodes, NULL); sqlite3_prepare(db, "update nodes set l=l+1 where nid=?", -1, &sql.update_node, NULL); +/* Places */ +sqlite3_prepare(db, "insert into places (nid,type,name,isin) values (?, ?, ?, ?)", + -1, &sql.insert_place, NULL); +sqlite3_prepare(db, "delete from places", -1, &sql.delete_place, NULL); + /* POI nodes */ sqlite3_prepare(db, "insert into poi (osm_id, lat, lon, label, desc, cat_id, public, priority)" " values (?, ?, ?, ?, ?, ?, 1, ?)", -1, &sql.insert_poi, NULL); @@ -243,8 +254,8 @@ db_insert_node(node *n) { gint32 lat, lon; -lat=osm_dlat2ilat(n->lat); -lon=osm_dlon2ilon(n->lon); +lat=lat2mp_int(n->lat); +lon=lon2mp_int(n->lon); sqlite3_bind_int(sql.insert_node, 1, n->id); sqlite3_bind_int(sql.insert_node, 2, lat); @@ -255,6 +266,25 @@ sqlite3_clear_bindings(sql.insert_node); return TRUE; } +gboolean +db_insert_place(node *n) +{ +if (!n->data) + return; +if (!n->data->name) + return; +sqlite3_bind_int(sql.insert_place, 1, n->id); +sqlite3_bind_int(sql.insert_place, 2, n->data->type); +sqlite3_bind_text(sql.insert_place, 3, n->data->name, -1, SQLITE_TRANSIENT); +/* Until we care enough, just use 0 */ +sqlite3_bind_int(sql.insert_place, 4, 0); +sqlite3_step(sql.insert_place); +sqlite3_reset(sql.insert_place); +sqlite3_clear_bindings(sql.insert_place); + +return TRUE; +} + gboolean db_insert_poi(node *n) { @@ -422,21 +452,6 @@ else return ERROR; /********************************************************************/ -gint32 -osm_dlat2ilat(gdouble lat) -{ -return lat > 85.051128779 ? INT_MAX : lat < -85.051128779 ? INT_MIN : - lrint(log(tan(M_PI_4l+lat*M_PIl/360))/M_PIl*INT_MAX); -} - -gint32 -osm_dlon2ilon(gdouble lon) -{ -return lrint(lon/180*INT_MAX); -} - -/********************************************************************/ - void print_node (node *n) { @@ -616,6 +631,9 @@ if (value->data->type>NODE_POI_START && value->data->typedata->type>NODE_PLACE_START && value->data->type