Throw in OSM datasource if not all parameters are specified but bind is requested.

This commit is contained in:
Hermann Kraus 2012-03-20 23:02:19 +01:00
parent eb911deca5
commit bd9fe739e5

View file

@ -52,6 +52,7 @@ DATASOURCE_PLUGIN(osm_datasource)
osm_datasource::osm_datasource(const parameters& params, bool bind) osm_datasource::osm_datasource(const parameters& params, bool bind)
: datasource (params), : datasource (params),
extent_(),
type_(datasource::Vector), type_(datasource::Vector),
desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding", "utf-8")) desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding", "utf-8"))
{ {
@ -71,13 +72,11 @@ void osm_datasource::bind() const
std::string url = *params_.get<std::string>("url", ""); std::string url = *params_.get<std::string>("url", "");
std::string bbox = *params_.get<std::string>("bbox", ""); std::string bbox = *params_.get<std::string>("bbox", "");
bool do_process = false;
// load the data // load the data
// if we supplied a filename, load from file
if (url != "" && bbox != "") if (url != "" && bbox != "")
{ {
// otherwise if we supplied a url and a bounding box, load from the url // if we supplied a url and a bounding box, load from the url
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
std::clog << "Osm Plugin: loading_from_url: url=" << url << " bbox=" << bbox << std::endl; std::clog << "Osm Plugin: loading_from_url: url=" << url << " bbox=" << bbox << std::endl;
#endif #endif
@ -85,23 +84,21 @@ void osm_datasource::bind() const
{ {
throw datasource_exception("Error loading from URL"); throw datasource_exception("Error loading from URL");
} }
do_process = true;
} }
else if (osm_filename != "") else if (osm_filename != "")
{ {
// if we supplied a filename, load from file
if ((osm_data_ = dataset_deliverer::load_from_file(osm_filename, parser)) == NULL) if ((osm_data_ = dataset_deliverer::load_from_file(osm_filename, parser)) == NULL)
{ {
std::ostringstream s; std::ostringstream s;
s << "OSM Plugin: Error loading from file '" << osm_filename << "'"; s << "OSM Plugin: Error loading from file '" << osm_filename << "'";
throw datasource_exception(s.str()); throw datasource_exception(s.str());
} }
} else {
do_process = true; throw datasource_exception("OSM Plugin: Neither 'file' nor 'url' and 'bbox' specified");
} }
if (do_process == true)
{
osm_tag_types tagtypes; osm_tag_types tagtypes;
tagtypes.add_type("maxspeed", mapnik::Integer); tagtypes.add_type("maxspeed", mapnik::Integer);
tagtypes.add_type("z_order", mapnik::Integer); tagtypes.add_type("z_order", mapnik::Integer);
@ -121,8 +118,6 @@ void osm_datasource::bind() const
// Get the bounds of the data and set extent_ accordingly // Get the bounds of the data and set extent_ accordingly
bounds b = osm_data_->get_bounds(); bounds b = osm_data_->get_bounds();
extent_ = box2d<double>(b.w, b.s, b.e, b.n); extent_ = box2d<double>(b.w, b.s, b.e, b.n);
}
is_bound_ = true; is_bound_ = true;
} }
@ -186,7 +181,6 @@ featureset_ptr osm_datasource::features_at_point(coord2d const& pt) const
box2d<double> osm_datasource::envelope() const box2d<double> osm_datasource::envelope() const
{ {
if (!is_bound_) bind(); if (!is_bound_) bind();
return extent_; return extent_;
} }