Changeset 686

Show
Ignore:
Timestamp:
04/02/08 17:40:28 (8 months ago)
Author:
nickw
Message:

now distinguishes between lines and polygons for ways

Location:
trunk/plugins/input/osm
Files:
5 modified

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 -g 
     1CXXFLAGS = `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 
    22MAPNIK_OSM_OBJ = osmparser.o osm.o osm_datasource.o osm_featureset.o  
    33osm.input: $(MAPNIK_OSM_OBJ) 
  • trunk/plugins/input/osm/osm.cpp

    r664 r686  
    1010#include <iostream> 
    1111using namespace std; 
     12 
     13polygon_types osm_way::ptypes; 
    1214 
    1315bool osm_dataset::load(const char* filename,const std::string& parser) 
     
    175177        return b; 
    176178} 
     179 
     180bool 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  
    66#include <map> 
    77#include <set> 
     8#include <utility> 
    89 
    910struct bounds 
    1011{ 
    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 
     23class polygon_types 
     24{ 
     25public: 
     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    } 
    2039}; 
    2140 
    2241struct osm_item 
    2342{ 
    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(); 
    2746}; 
    2847 
     
    3049struct osm_node: public osm_item 
    3150{ 
    32         double lat, lon; 
    33         std::string to_string(); 
     51    double lat, lon; 
     52    std::string to_string(); 
    3453}; 
    3554 
    3655struct osm_way: public osm_item 
    3756{ 
    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; 
    4162}; 
    4263 
     
    4465{ 
    4566private: 
    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;  
    5273 
    5374public: 
    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; } 
    7495}; 
    7596 
  • trunk/plugins/input/osm/osm_featureset.cpp

    r665 r686  
    3131using mapnik::point_impl; 
    3232using mapnik::line_string_impl; 
     33using mapnik::polygon_impl; 
     34 
     35using std::cerr; 
     36using std::endl; 
    3337 
    3438template <typename filterT> 
     
    8589                                { 
    8690                                        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)-> 
    8998                                                                        nodes.size()); 
    90                                         line->move_to(static_cast<osm_way*>(cur_item)-> 
     99                                        geom->move_to(static_cast<osm_way*>(cur_item)-> 
    91100                                                                                nodes[0]->lon, 
    92101                                                                static_cast<osm_way*>(cur_item)-> 
     
    96105                                                                ->nodes.size(); count++) 
    97106                                        { 
    98                                                 line->line_to(static_cast<osm_way*>(cur_item) 
     107                                                geom->line_to(static_cast<osm_way*>(cur_item) 
    99108                                                                        ->nodes[count]->lon, 
    100109                                                                static_cast<osm_way*>(cur_item) 
    101110                                                                        ->nodes[count]->lat); 
    102111                                        } 
    103                                         feature->add_geometry(line); 
     112                                        feature->add_geometry(geom); 
    104113                                        success=true; 
    105114                                } 
  • trunk/plugins/input/osm/render.cpp

    r665 r686  
    2020        if(argc < 6) 
    2121        { 
    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; 
    2323                exit(0); 
    2424        } 
     
    3232        load_map(m,argv[1]); 
    3333         
    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) 
    3835        { 
    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                } 
    4245        } 
    4346