Changeset 686
- Timestamp:
- 04/02/08 17:40:28 (8 months ago)
- Location:
- trunk/plugins/input/osm
- Files:
-
- 5 modified
-
libMakefile (modified) (1 diff)
-
osm.cpp (modified) (2 diffs)
-
osm.h (modified) (3 diffs)
-
osm_featureset.cpp (modified) (3 diffs)
-
render.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/input/osm/libMakefile
r664 r686 1 CXXFLAGS = `xml2-config --cflags` -I/usr/local/include/mapnik -I/usr/include/boost -I/usr/include/freetype2 -fPIC -g1 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 2 2 MAPNIK_OSM_OBJ = osmparser.o osm.o osm_datasource.o osm_featureset.o 3 3 osm.input: $(MAPNIK_OSM_OBJ) -
trunk/plugins/input/osm/osm.cpp
r664 r686 10 10 #include <iostream> 11 11 using namespace std; 12 13 polygon_types osm_way::ptypes; 12 14 13 15 bool osm_dataset::load(const char* filename,const std::string& parser) … … 175 177 return b; 176 178 } 179 180 bool osm_way::is_polygon() 181 { 182 for(int count=0; count<ptypes.ptypes.size(); count++) 183 { 184 if(keyvals.find(ptypes.ptypes[count].first) != keyvals.end() && 185 keyvals[ptypes.ptypes[count].first] == ptypes.ptypes[count].second) 186 { 187 return true; 188 } 189 } 190 return false; 191 } -
trunk/plugins/input/osm/osm.h
r664 r686 6 6 #include <map> 7 7 #include <set> 8 #include <utility> 8 9 9 10 struct bounds 10 11 { 11 double w,s,e,n; 12 bounds() { w=-180; s=-90; e=180; n=90; } 13 bounds(double w, double s, double e, double n ) 14 { 15 this->w = w; 16 this->s = s; 17 this->e = e; 18 this->n = n; 19 } 12 double w,s,e,n; 13 bounds() { w=-180; s=-90; e=180; n=90; } 14 bounds(double w, double s, double e, double n ) 15 { 16 this->w = w; 17 this->s = s; 18 this->e = e; 19 this->n = n; 20 } 21 }; 22 23 class polygon_types 24 { 25 public: 26 std::vector<std::pair<std::string,std::string> > ptypes; 27 28 polygon_types() 29 { 30 ptypes.push_back(std::pair<std::string,std::string>("natural","wood")); 31 ptypes.push_back(std::pair<std::string,std::string>("natural","water")); 32 ptypes.push_back(std::pair<std::string,std::string>("natural","heath")); 33 ptypes.push_back(std::pair<std::string,std::string>("natural","marsh")); 34 ptypes.push_back(std::pair<std::string,std::string> 35 ("landuse","forest")); 36 ptypes.push_back(std::pair<std::string,std::string> 37 ("landuse","industrial")); 38 } 20 39 }; 21 40 22 41 struct osm_item 23 42 { 24 long id;25 std::map<std::string,std::string> keyvals; 26 virtual std::string to_string();43 long id; 44 std::map<std::string,std::string> keyvals; 45 virtual std::string to_string(); 27 46 }; 28 47 … … 30 49 struct osm_node: public osm_item 31 50 { 32 double lat, lon;33 std::string to_string();51 double lat, lon; 52 std::string to_string(); 34 53 }; 35 54 36 55 struct osm_way: public osm_item 37 56 { 38 std::vector<osm_node*> nodes; 39 std::string to_string(); 40 bounds get_bounds(); 57 std::vector<osm_node*> nodes; 58 std::string to_string(); 59 bounds get_bounds(); 60 bool is_polygon(); 61 static polygon_types ptypes; 41 62 }; 42 63 … … 44 65 { 45 66 private: 46 int next_item_mode;47 enum {Node, Way };48 std::vector<osm_node*>::iterator node_i;49 std::vector<osm_way*>::iterator way_i;50 std::vector<osm_node*> nodes;51 std::vector<osm_way*> ways;67 int next_item_mode; 68 enum {Node, Way }; 69 std::vector<osm_node*>::iterator node_i; 70 std::vector<osm_way*>::iterator way_i; 71 std::vector<osm_node*> nodes; 72 std::vector<osm_way*> ways; 52 73 53 74 public: 54 osm_dataset() { node_i=nodes.begin(); way_i=ways.begin();55 next_item_mode=Node; }56 osm_dataset(const char* name)57 { node_i=nodes.begin(); way_i=ways.begin();58 next_item_mode=Node; load(name); }59 bool load(const char* name,const std::string& parser="libxml2");60 ~osm_dataset();61 void add_node(osm_node* n) { nodes.push_back(n); }62 void add_way(osm_way* w) { ways.push_back(w); }63 std::string to_string();64 bounds get_bounds();65 std::set<std::string> get_keys();66 void rewind_nodes() { node_i=nodes.begin(); }67 void rewind_ways() { way_i=ways.begin(); }68 void rewind() { rewind_nodes(); rewind_ways(); next_item_mode=Node; }69 osm_node * next_node();70 osm_way * next_way();71 osm_item * next_item();72 bool current_item_is_node() { return next_item_mode==Node; }73 bool current_item_is_way() { return next_item_mode==Way; }75 osm_dataset() { node_i=nodes.begin(); way_i=ways.begin(); 76 next_item_mode=Node; } 77 osm_dataset(const char* name) 78 { node_i=nodes.begin(); way_i=ways.begin(); 79 next_item_mode=Node; load(name); } 80 bool load(const char* name,const std::string& parser="libxml2"); 81 ~osm_dataset(); 82 void add_node(osm_node* n) { nodes.push_back(n); } 83 void add_way(osm_way* w) { ways.push_back(w); } 84 std::string to_string(); 85 bounds get_bounds(); 86 std::set<std::string> get_keys(); 87 void rewind_nodes() { node_i=nodes.begin(); } 88 void rewind_ways() { way_i=ways.begin(); } 89 void rewind() { rewind_nodes(); rewind_ways(); next_item_mode=Node; } 90 osm_node * next_node(); 91 osm_way * next_way(); 92 osm_item * next_item(); 93 bool current_item_is_node() { return next_item_mode==Node; } 94 bool current_item_is_way() { return next_item_mode==Way; } 74 95 }; 75 96 -
trunk/plugins/input/osm/osm_featureset.cpp
r665 r686 31 31 using mapnik::point_impl; 32 32 using mapnik::line_string_impl; 33 using mapnik::polygon_impl; 34 35 using std::cerr; 36 using std::endl; 33 37 34 38 template <typename filterT> … … 85 89 { 86 90 feature=feature_ptr(new Feature(count_++)); 87 geometry2d *line = new line_string_impl; 88 line->set_capacity(static_cast<osm_way*>(cur_item)-> 91 geometry2d *geom; 92 if(static_cast<osm_way*>(cur_item)->is_polygon()) 93 geom=new polygon_impl; 94 else 95 geom=new line_string_impl; 96 97 geom->set_capacity(static_cast<osm_way*>(cur_item)-> 89 98 nodes.size()); 90 line->move_to(static_cast<osm_way*>(cur_item)->99 geom->move_to(static_cast<osm_way*>(cur_item)-> 91 100 nodes[0]->lon, 92 101 static_cast<osm_way*>(cur_item)-> … … 96 105 ->nodes.size(); count++) 97 106 { 98 line->line_to(static_cast<osm_way*>(cur_item)107 geom->line_to(static_cast<osm_way*>(cur_item) 99 108 ->nodes[count]->lon, 100 109 static_cast<osm_way*>(cur_item) 101 110 ->nodes[count]->lat); 102 111 } 103 feature->add_geometry( line);112 feature->add_geometry(geom); 104 113 success=true; 105 114 } -
trunk/plugins/input/osm/render.cpp
r665 r686 20 20 if(argc < 6) 21 21 { 22 std::cerr<<"Usage: render XMLfile w s e n OSMfile" << std::endl;22 std::cerr<<"Usage: render XMLfile w s e n [OSMfile]" << std::endl; 23 23 exit(0); 24 24 } … … 32 32 load_map(m,argv[1]); 33 33 34 parameters p; 35 p["type"] = "osm"; 36 p["file"] = argv[6]; 37 for(int count=0; count<m.layerCount(); count++) 34 if(argc>6) 38 35 { 39 parameters q = m.getLayer(count).datasource()->params(); 40 m.getLayer(count).set_datasource(datasource_cache::instance()-> 41 create(p)); 36 parameters p; 37 p["type"] = "osm"; 38 p["file"] = argv[6]; 39 for(int count=0; count<m.layerCount(); count++) 40 { 41 parameters q = m.getLayer(count).datasource()->params(); 42 m.getLayer(count).set_datasource(datasource_cache::instance()-> 43 create(p)); 44 } 42 45 } 43 46
