};
struct sql_stmt sql;
+struct map_bbox {
+ gdouble lat_min;
+ gdouble lon_min;
+ gdouble lat_max;
+ gdouble lon_max;
+};
+struct map_bbox bbox;
+gboolean use_bbox;
+
gint wsegcnt;
node *osm_find_node(gint nid);
sqlite3_clear_bindings(sql.insert_way_name);
}
-void
+gboolean
db_insert_way_segments(segment *s, way *w)
{
node *f;
if (!s) {
g_printf("ERROR: null segment!\n");
- return;
+ return FALSE;
}
if (!w) {
g_printf("ERROR: null way!\n");
- return;
+ return FALSE;
}
f=osm_find_node(s->from);
t=osm_find_node(s->to);
-if (!f)
- return;
-if (!t)
- return;
+if (!f) {
+ w->id=0;
+ return FALSE;
+}
+if (!t) {
+ w->id=0;
+ return FALSE;
+}
db_insert_way_seg(f,w);
if (w->ncnt==wsegcnt)
db_insert_way_seg(t,w);
+
+return TRUE;
}
gboolean
if (w->type==WAY_UNWAYED)
return TRUE;
+wsegcnt=0;
+g_slist_foreach(w->nodes, db_insert_way_segments, w);
+/* Invalid/Skipped segments/nodes in way */
+if (w->id==0)
+ return FALSE;
+
sqlite3_bind_int(sql.insert_way_data, 1, w->id);
sqlite3_bind_int(sql.insert_way_data, 2, w->ncnt);
sqlite3_bind_int(sql.insert_way_data, 3, w->type);
db_insert_way_ref(w);
db_insert_way_names(w);
-wsegcnt=0;
-g_slist_foreach(w->nodes, db_insert_way_segments, w);
osm_free_way_data(w);
return TRUE;
{
node *n;
n=g_hash_table_lookup(osm_nodes, GINT_TO_POINTER(nid));
+#if 0
if (!n)
g_printf("ERROR: Node %d not found!\n", nid);
+#endif
return n;
}
tag_state_t t;
gchar *k, *v;
guint32 id;
+gfloat nlat, nlon;
t=check_tag(name);
switch (t) {
id=atoi(get_attr_key_value(atts, "id"));
- cnode=osm_new_node(id,
- atof(get_attr_key_value(atts, "lat")),
- atof(get_attr_key_value(atts, "lon")));
- osm_node_tags=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+ osm_node_tags=NULL;
+ nlat=atof(get_attr_key_value(atts, "lat"));
+ nlon=atof(get_attr_key_value(atts, "lon"));
+ if (use_bbox==TRUE) {
+ if (nlat > bbox.lat_min && nlat < bbox.lat_max && nlon > bbox.lon_min && nlon < bbox.lon_max) {
+ cnode=osm_new_node(id, nlat, nlon);
+ osm_node_tags=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+ }
+ } else {
+ cnode=osm_new_node(id, nlat, nlon);
+ osm_node_tags=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+ }
break;
case IN_SEGMENT_TAG:
tag_parent=IS_SEGMENT;
{
gint i;
+ if (!osm_node_tags)
+ return;
+
k=get_attr_key_value(atts, "k");
v=get_attr_key_value(atts, "v");
if (cnode==NULL) {
g_printf("In node tags but current node is NULL\n");
return;
- }
+ }
g_hash_table_insert(osm_node_tags, g_strdup(k), g_strdup(v));
}
break;
g_printf("Nodes: %d/%d\n", node_cnt, noded_cnt);
}
+ if (!osm_node_tags)
+ return;
+
osm_new_node_data(cnode);
for (i=0; nodeinfo[i].k; i++) {
int main (int argc, char **argv)
{
-if (argc!=2) {
+if (argc<2) {
return print_fail("No planet XML file given", 1);
} else {
g_printf("Using file: %s\n", argv[1]);
}
+if (argc==6) {
+ use_bbox=TRUE;
+
+ bbox.lat_min=atof(argv[2]);
+ bbox.lon_min=atof(argv[3]);
+ bbox.lat_max=atof(argv[4]);
+ bbox.lon_max=atof(argv[5]);
+ g_printf("Skipping data outside of box: %f,%f - %f,%f\n",
+ bbox.lat_min, bbox.lon_min,
+ bbox.lat_max, bbox.lon_max);
+} else use_bbox=FALSE;
+
if (db_open()!=TRUE)
return print_fail("Database open failed", 2);
db_prepare();