#include <expat.h>
#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 {
{ "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 },
{ 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;
sqlite3_stmt *delete_way_ref;
sqlite3_stmt *insert_place;
+ sqlite3_stmt *delete_place;
};
struct sql_stmt sql;
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);
{
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);
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)
{
/********************************************************************/
-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)
{
db_insert_poi(value);
/* Free the extra info, we don't need it anymore */
osm_free_node_data(value);
+} else if (value->data->type>NODE_PLACE_START && value->data->type<NODE_PLACE_END) {
+ db_insert_place(value);
+ osm_free_node_data(value);
}
}