2008-03-01 11:49:37 +00:00
|
|
|
#ifndef OSM_H
|
|
|
|
#define OSM_H
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
2008-04-02 21:40:28 +00:00
|
|
|
#include <utility>
|
2008-03-01 11:49:37 +00:00
|
|
|
|
|
|
|
struct bounds
|
|
|
|
{
|
2008-04-02 21:40:28 +00:00
|
|
|
double w,s,e,n;
|
|
|
|
bounds() { w=-180; s=-90; e=180; n=90; }
|
|
|
|
bounds(double w, double s, double e, double n )
|
|
|
|
{
|
|
|
|
this->w = w;
|
|
|
|
this->s = s;
|
|
|
|
this->e = e;
|
|
|
|
this->n = n;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class polygon_types
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::vector<std::pair<std::string,std::string> > ptypes;
|
|
|
|
|
|
|
|
polygon_types()
|
|
|
|
{
|
|
|
|
ptypes.push_back(std::pair<std::string,std::string>("natural","wood"));
|
|
|
|
ptypes.push_back(std::pair<std::string,std::string>("natural","water"));
|
|
|
|
ptypes.push_back(std::pair<std::string,std::string>("natural","heath"));
|
|
|
|
ptypes.push_back(std::pair<std::string,std::string>("natural","marsh"));
|
2009-02-15 13:51:07 +00:00
|
|
|
ptypes.push_back(std::pair<std::string,std::string>("military",
|
2011-04-02 03:45:50 +00:00
|
|
|
"danger_area"));
|
2008-04-02 21:40:28 +00:00
|
|
|
ptypes.push_back(std::pair<std::string,std::string>
|
|
|
|
("landuse","forest"));
|
|
|
|
ptypes.push_back(std::pair<std::string,std::string>
|
|
|
|
("landuse","industrial"));
|
|
|
|
}
|
2008-03-01 11:49:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct osm_item
|
|
|
|
{
|
2008-04-02 21:40:28 +00:00
|
|
|
long id;
|
|
|
|
std::map<std::string,std::string> keyvals;
|
|
|
|
virtual std::string to_string();
|
2009-02-15 13:51:07 +00:00
|
|
|
virtual ~osm_item() { }
|
2008-03-01 11:49:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct osm_node: public osm_item
|
|
|
|
{
|
2008-04-02 21:40:28 +00:00
|
|
|
double lat, lon;
|
|
|
|
std::string to_string();
|
2008-03-01 11:49:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct osm_way: public osm_item
|
|
|
|
{
|
2008-04-02 21:40:28 +00:00
|
|
|
std::vector<osm_node*> nodes;
|
|
|
|
std::string to_string();
|
|
|
|
bounds get_bounds();
|
|
|
|
bool is_polygon();
|
|
|
|
static polygon_types ptypes;
|
2008-03-01 11:49:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class osm_dataset
|
|
|
|
{
|
|
|
|
private:
|
2008-04-02 21:40:28 +00:00
|
|
|
int next_item_mode;
|
|
|
|
enum {Node, Way };
|
|
|
|
std::vector<osm_node*>::iterator node_i;
|
|
|
|
std::vector<osm_way*>::iterator way_i;
|
|
|
|
std::vector<osm_node*> nodes;
|
|
|
|
std::vector<osm_way*> ways;
|
2008-03-01 11:49:37 +00:00
|
|
|
|
|
|
|
public:
|
2008-04-02 21:40:28 +00:00
|
|
|
osm_dataset() { node_i=nodes.begin(); way_i=ways.begin();
|
|
|
|
next_item_mode=Node; }
|
|
|
|
osm_dataset(const char* name)
|
|
|
|
{ node_i=nodes.begin(); way_i=ways.begin();
|
|
|
|
next_item_mode=Node; load(name); }
|
|
|
|
bool load(const char* name,const std::string& parser="libxml2");
|
2009-02-15 13:51:07 +00:00
|
|
|
bool load_from_url(const std::string&,const std::string&,
|
|
|
|
const std::string& parser="libxml2");
|
2008-04-02 21:40:28 +00:00
|
|
|
~osm_dataset();
|
2009-02-16 23:10:58 +00:00
|
|
|
void clear();
|
2008-04-02 21:40:28 +00:00
|
|
|
void add_node(osm_node* n) { nodes.push_back(n); }
|
|
|
|
void add_way(osm_way* w) { ways.push_back(w); }
|
|
|
|
std::string to_string();
|
|
|
|
bounds get_bounds();
|
|
|
|
std::set<std::string> get_keys();
|
|
|
|
void rewind_nodes() { node_i=nodes.begin(); }
|
|
|
|
void rewind_ways() { way_i=ways.begin(); }
|
|
|
|
void rewind() { rewind_nodes(); rewind_ways(); next_item_mode=Node; }
|
|
|
|
osm_node * next_node();
|
|
|
|
osm_way * next_way();
|
|
|
|
osm_item * next_item();
|
|
|
|
bool current_item_is_node() { return next_item_mode==Node; }
|
|
|
|
bool current_item_is_way() { return next_item_mode==Way; }
|
2008-03-01 11:49:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // OSM_H
|