diff --git a/plugins/input/osm/libMakefile b/plugins/input/osm/libMakefile index b603e0e03..5bc37a943 100644 --- a/plugins/input/osm/libMakefile +++ b/plugins/input/osm/libMakefile @@ -1,4 +1,4 @@ -CXXFLAGS = `xml2-config --cflags` -I/usr/local/include/mapnik -I/usr/include/boost -I/usr/include/freetype2 -fPIC -g +CXXFLAGS = `xml2-config --cflags` -I/usr/local/include/mapnik -I/usr/include/boost -I/usr/include/freetype2 -I/home/nick/mapnik-osm/agg/include -fPIC -g MAPNIK_OSM_OBJ = osmparser.o osm.o osm_datasource.o osm_featureset.o osm.input: $(MAPNIK_OSM_OBJ) g++ -shared -o osm.input $(MAPNIK_OSM_OBJ) diff --git a/plugins/input/osm/osm.cpp b/plugins/input/osm/osm.cpp index a51279039..82c455c57 100644 --- a/plugins/input/osm/osm.cpp +++ b/plugins/input/osm/osm.cpp @@ -10,6 +10,8 @@ #include using namespace std; +polygon_types osm_way::ptypes; + bool osm_dataset::load(const char* filename,const std::string& parser) { if (parser=="libxml2") @@ -174,3 +176,16 @@ bounds osm_way::get_bounds() } return b; } + +bool osm_way::is_polygon() +{ + for(int count=0; count #include #include +#include struct bounds { - 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; - } + 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 > ptypes; + + polygon_types() + { + ptypes.push_back(std::pair("natural","wood")); + ptypes.push_back(std::pair("natural","water")); + ptypes.push_back(std::pair("natural","heath")); + ptypes.push_back(std::pair("natural","marsh")); + ptypes.push_back(std::pair + ("landuse","forest")); + ptypes.push_back(std::pair + ("landuse","industrial")); + } }; struct osm_item { - long id; - std::map keyvals; - virtual std::string to_string(); + long id; + std::map keyvals; + virtual std::string to_string(); }; struct osm_node: public osm_item { - double lat, lon; - std::string to_string(); + double lat, lon; + std::string to_string(); }; struct osm_way: public osm_item { - std::vector nodes; - std::string to_string(); - bounds get_bounds(); + std::vector nodes; + std::string to_string(); + bounds get_bounds(); + bool is_polygon(); + static polygon_types ptypes; }; class osm_dataset { private: - int next_item_mode; - enum {Node, Way }; - std::vector::iterator node_i; - std::vector::iterator way_i; - std::vector nodes; - std::vector ways; + int next_item_mode; + enum {Node, Way }; + std::vector::iterator node_i; + std::vector::iterator way_i; + std::vector nodes; + std::vector ways; public: - 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"); - ~osm_dataset(); - 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 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; } + 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"); + ~osm_dataset(); + 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 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; } }; #endif // OSM_H diff --git a/plugins/input/osm/osm_featureset.cpp b/plugins/input/osm/osm_featureset.cpp index 4e9f359ac..7bbda9359 100644 --- a/plugins/input/osm/osm_featureset.cpp +++ b/plugins/input/osm/osm_featureset.cpp @@ -30,6 +30,10 @@ using mapnik::feature_ptr; using mapnik::geometry2d; using mapnik::point_impl; using mapnik::line_string_impl; +using mapnik::polygon_impl; + +using std::cerr; +using std::endl; template osm_featureset::osm_featureset(const filterT& filter, @@ -84,10 +88,15 @@ feature_ptr osm_featureset::next() if(static_cast(cur_item)->nodes.size()) { feature=feature_ptr(new Feature(count_++)); - geometry2d *line = new line_string_impl; - line->set_capacity(static_cast(cur_item)-> + geometry2d *geom; + if(static_cast(cur_item)->is_polygon()) + geom=new polygon_impl; + else + geom=new line_string_impl; + + geom->set_capacity(static_cast(cur_item)-> nodes.size()); - line->move_to(static_cast(cur_item)-> + geom->move_to(static_cast(cur_item)-> nodes[0]->lon, static_cast(cur_item)-> nodes[0]->lat); @@ -95,12 +104,12 @@ feature_ptr osm_featureset::next() for(int count=1; count(cur_item) ->nodes.size(); count++) { - line->line_to(static_cast(cur_item) + geom->line_to(static_cast(cur_item) ->nodes[count]->lon, static_cast(cur_item) ->nodes[count]->lat); } - feature->add_geometry(line); + feature->add_geometry(geom); success=true; } } diff --git a/plugins/input/osm/render.cpp b/plugins/input/osm/render.cpp index 7900586b3..5d00b315f 100644 --- a/plugins/input/osm/render.cpp +++ b/plugins/input/osm/render.cpp @@ -19,7 +19,7 @@ int main(int argc,char *argv[]) { if(argc < 6) { - std::cerr<<"Usage: render XMLfile w s e n OSMfile" << std::endl; + std::cerr<<"Usage: render XMLfile w s e n [OSMfile]" << std::endl; exit(0); } @@ -31,14 +31,17 @@ int main(int argc,char *argv[]) Map m (800,800); load_map(m,argv[1]); - parameters p; - p["type"] = "osm"; - p["file"] = argv[6]; - for(int count=0; count6) { - parameters q = m.getLayer(count).datasource()->params(); - m.getLayer(count).set_datasource(datasource_cache::instance()-> - create(p)); + parameters p; + p["type"] = "osm"; + p["file"] = argv[6]; + for(int count=0; countparams(); + m.getLayer(count).set_datasource(datasource_cache::instance()-> + create(p)); + } } Envelope bbox (atof(argv[2]),atof(argv[3]),