2011-10-22 16:04:05 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Artem Pavlenko
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2008-03-01 12:49:37 +01:00
|
|
|
#ifndef OSM_H
|
|
|
|
#define OSM_H
|
|
|
|
|
2013-01-08 23:17:31 +01:00
|
|
|
#include <mapnik/value_types.hpp>
|
2008-03-01 12:49:37 +01:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
2008-04-02 23:40:28 +02:00
|
|
|
#include <utility>
|
2008-03-01 12:49:37 +01:00
|
|
|
|
|
|
|
struct bounds
|
|
|
|
{
|
2011-10-22 16:04:05 +02:00
|
|
|
double w, s, e, n;
|
|
|
|
bounds() { w = -180; s = -90; e = 180; n = 90; }
|
2013-01-03 21:37:45 +01:00
|
|
|
bounds(double w_, double s_, double e_, double n_)
|
2008-04-02 23:40:28 +02:00
|
|
|
{
|
2013-01-03 21:37:45 +01:00
|
|
|
this->w = w_;
|
|
|
|
this->s = s_;
|
|
|
|
this->e = e_;
|
|
|
|
this->n = n_;
|
2008-04-02 23:40:28 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class polygon_types
|
|
|
|
{
|
|
|
|
public:
|
2011-10-22 16:04:05 +02:00
|
|
|
std::vector<std::pair<std::string, std::string> > ptypes;
|
2008-04-02 23:40:28 +02:00
|
|
|
|
|
|
|
polygon_types()
|
|
|
|
{
|
2012-11-28 03:15:56 +01:00
|
|
|
ptypes.push_back(std::pair<std::string, std::string>("water", ""));
|
|
|
|
ptypes.push_back(std::pair<std::string, std::string>("aeroway", ""));
|
|
|
|
ptypes.push_back(std::pair<std::string, std::string>("building", ""));
|
2011-10-22 16:04:05 +02:00
|
|
|
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"));
|
|
|
|
ptypes.push_back(std::pair<std::string, std::string>("military", "danger_area"));
|
2012-10-17 02:46:24 +02:00
|
|
|
ptypes.push_back(std::pair<std::string, std::string>("landuse", "forest"));
|
|
|
|
ptypes.push_back(std::pair<std::string, std::string>("landuse", "industrial"));
|
|
|
|
ptypes.push_back(std::pair<std::string, std::string>("leisure", "park"));
|
2014-07-05 16:56:22 +02:00
|
|
|
ptypes.push_back(std::pair<std::string, std::string>("area", "yes"));
|
2008-04-02 23:40:28 +02:00
|
|
|
}
|
2008-03-01 12:49:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct osm_item
|
|
|
|
{
|
2012-12-20 04:24:52 +01:00
|
|
|
mapnik::value_integer id;
|
2011-10-22 16:04:05 +02:00
|
|
|
std::map<std::string, std::string> keyvals;
|
2008-04-02 23:40:28 +02:00
|
|
|
virtual std::string to_string();
|
2011-10-22 16:04:05 +02:00
|
|
|
virtual ~osm_item() {}
|
2008-03-01 12:49:37 +01:00
|
|
|
};
|
|
|
|
|
2011-10-22 16:04:05 +02:00
|
|
|
struct osm_node : public osm_item
|
2008-03-01 12:49:37 +01:00
|
|
|
{
|
2008-04-02 23:40:28 +02:00
|
|
|
double lat, lon;
|
|
|
|
std::string to_string();
|
2008-03-01 12:49:37 +01:00
|
|
|
};
|
|
|
|
|
2011-10-22 16:04:05 +02:00
|
|
|
struct osm_way : public osm_item
|
2008-03-01 12:49:37 +01:00
|
|
|
{
|
2008-04-02 23:40:28 +02:00
|
|
|
std::vector<osm_node*> nodes;
|
|
|
|
std::string to_string();
|
|
|
|
bounds get_bounds();
|
|
|
|
bool is_polygon();
|
|
|
|
static polygon_types ptypes;
|
2008-03-01 12:49:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class osm_dataset
|
|
|
|
{
|
|
|
|
public:
|
2011-10-22 16:04:05 +02: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);
|
|
|
|
}
|
|
|
|
|
2008-04-02 23:40:28 +02:00
|
|
|
~osm_dataset();
|
2011-10-22 16:04:05 +02:00
|
|
|
|
2012-09-03 19:27:48 +02:00
|
|
|
bool load(const char* name, std::string const& parser = "libxml2");
|
2009-02-17 00:10:58 +01:00
|
|
|
void clear();
|
2008-04-02 23:40:28 +02: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();
|
2011-10-22 16:04:05 +02:00
|
|
|
void rewind_nodes() { node_i = nodes.begin(); }
|
|
|
|
void rewind_ways() { way_i = ways.begin(); }
|
|
|
|
void rewind() { rewind_nodes(); rewind_ways(); next_item_mode = Node; }
|
2008-04-02 23:40:28 +02:00
|
|
|
osm_node * next_node();
|
|
|
|
osm_way * next_way();
|
|
|
|
osm_item * next_item();
|
2011-10-22 16:04:05 +02:00
|
|
|
bool current_item_is_node() { return next_item_mode == Node; }
|
|
|
|
bool current_item_is_way() { return next_item_mode == Way; }
|
2012-04-09 03:00:51 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
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 12:49:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // OSM_H
|