diff --git a/plugins/input/osm/osm_datasource.cpp b/plugins/input/osm/osm_datasource.cpp index 3c7e6343c..f99699ad2 100644 --- a/plugins/input/osm/osm_datasource.cpp +++ b/plugins/input/osm/osm_datasource.cpp @@ -27,6 +27,7 @@ #include #include "osm_datasource.hpp" #include "osm_featureset.hpp" +#include "osmtagtypes.h" #include DATASOURCE_PLUGIN(osm_datasource) @@ -52,9 +53,14 @@ osm_datasource::osm_datasource(const parameters ¶ms) // load the data if (osm_data_->load(osm_filename.c_str(),parser)==false) { - throw datasource_exception("Error loading OSM data"); + //throw datasource_exception("Error loading OSM data"); + return ; } + osm_tag_types tagtypes; + tagtypes.add_type("maxspeed",mapnik::Integer); + tagtypes.add_type("z_order",mapnik::Integer); + osm_data_->rewind(); // Need code to get the attributes of all the data std::set keys= osm_data_->get_keys(); @@ -62,7 +68,7 @@ osm_datasource::osm_datasource(const parameters ¶ms) // Add the attributes to the datasource descriptor - assume they're // all of type String for(std::set::iterator i=keys.begin(); i!=keys.end(); i++) - desc_.add_descriptor(attribute_descriptor(*i,String)); + desc_.add_descriptor(attribute_descriptor(*i,tagtypes.get_type(*i))); // Get the bounds of the data and set extent_ accordingly bounds b = osm_data_->get_bounds(); diff --git a/plugins/input/osm/osm_featureset.cpp b/plugins/input/osm/osm_featureset.cpp index 48bf236c4..4e9f359ac 100644 --- a/plugins/input/osm/osm_featureset.cpp +++ b/plugins/input/osm/osm_featureset.cpp @@ -118,7 +118,7 @@ feature_ptr osm_featureset::next() { //only add if in the specified set of attribute names if(attribute_names_.find(i->first) != attribute_names_.end()) - (*feature)[i->first] = tr_->transcode(i->second); + (*feature)[i->first] = tr_->transcode(i->second.c_str()); i++; } return feature; diff --git a/plugins/input/osm/osmparser.cpp b/plugins/input/osm/osmparser.cpp index cccdd4d3f..ceb911183 100644 --- a/plugins/input/osm/osmparser.cpp +++ b/plugins/input/osm/osmparser.cpp @@ -71,6 +71,8 @@ void osmparser::startElement(xmlTextReaderPtr reader, const xmlChar *name) assert(xid); way->id = atol((char*)xid); cur_item = way; + // Prevent ways with no name being assigned a name of "0" + cur_item->keyvals["name"] = ""; xmlFree(xid); } else if (xmlStrEqual(name,BAD_CAST "nd")) diff --git a/plugins/input/osm/osmtagtypes.h b/plugins/input/osm/osmtagtypes.h new file mode 100644 index 000000000..1d48f2bcd --- /dev/null +++ b/plugins/input/osm/osmtagtypes.h @@ -0,0 +1,28 @@ +#ifndef OSMTAGTYPES_H +#define OSMTAGTYPES_H + +// osmtagtypes.h +// for finding the types of particular tags + +#include + +class osm_tag_types +{ +private: + std::map types; + +public: + void add_type(std::string tag, mapnik::eAttributeType type) + { + types[tag]=type; + } + + mapnik::eAttributeType get_type(std::string tag) + { + std::map::iterator i = + types.find(tag); + return (i==types.end()) ? mapnik::String: i->second; + } +}; + +#endif // OSMTAGTYPES_H diff --git a/plugins/input/osm/render.cpp b/plugins/input/osm/render.cpp index 20b25d06d..7900586b3 100644 --- a/plugins/input/osm/render.cpp +++ b/plugins/input/osm/render.cpp @@ -15,17 +15,34 @@ using namespace mapnik; using namespace std; -int main() +int main(int argc,char *argv[]) { + if(argc < 6) + { + std::cerr<<"Usage: render XMLfile w s e n OSMfile" << std::endl; + exit(0); + } + datasource_cache::instance()->register_datasources ("/usr/local/lib/mapnik/input"); freetype_engine::register_font - ("/usr/local/lib/mapnik/fonts/Vera.ttf"); + ("/usr/local/lib/mapnik/fonts/DejaVuSans.ttf"); Map m (800,800); - load_map(m,"test.xml"); + load_map(m,argv[1]); + + 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 (-1.45,50.90,-1.35,51.00); + Envelope bbox (atof(argv[2]),atof(argv[3]), + atof(argv[4]),atof(argv[5])); m.zoomToBox(bbox); diff --git a/plugins/input/osm/test2.xml b/plugins/input/osm/test2.xml new file mode 100644 index 000000000..07c4e67a9 --- /dev/null +++ b/plugins/input/osm/test2.xml @@ -0,0 +1,538 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + leisure + + osm + test2.osm + + + + + river + stream + + osm + test2.osm + + + + + lakes + + osm + test2.osm + + + + + roads-casing + footway + cycleway + bridleway + byway + railway + residential + unclassified + tertiary + secondary + primary + trunk + motorway + + osm + test2.osm + + + + + amenity + + osm + test2.osm + + + + + roads-text + + osm + test2.osm + + + + + text + + osm + test2.osm + + + + diff --git a/plugins/input/osm/test3.xml b/plugins/input/osm/test3.xml new file mode 100644 index 000000000..4350f5787 --- /dev/null +++ b/plugins/input/osm/test3.xml @@ -0,0 +1,531 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + leisure + + osm + + + + + river + stream + + osm + + + + + lakes + + osm + + + + + roads-casing + footway + cycleway + bridleway + byway + railway + residential + unclassified + tertiary + secondary + primary + trunk + motorway + + osm + + + + + amenity + + osm + + + + + roads-text + + osm + + + + + text + + osm + + + +