shape: improve the error message when an invalid attribute is requested

This commit is contained in:
Dane Springmeyer 2011-08-05 21:20:21 +00:00
parent 518444a627
commit 17854e6c4f
5 changed files with 25 additions and 12 deletions

View file

@ -252,7 +252,8 @@ featureset_ptr shape_datasource::features(const query& q) const
(new shape_index_featureset<filter_in_box>(filter, (new shape_index_featureset<filter_in_box>(filter,
*shape_, *shape_,
q.property_names(), q.property_names(),
desc_.get_encoding())); desc_.get_encoding(),
shape_name_));
} }
else else
{ {
@ -289,7 +290,8 @@ featureset_ptr shape_datasource::features_at_point(coord2d const& pt) const
(new shape_index_featureset<filter_at_point>(filter, (new shape_index_featureset<filter_at_point>(filter,
*shape_, *shape_,
names, names,
desc_.get_encoding())); desc_.get_encoding(),
shape_name_));
} }
else else
{ {

View file

@ -24,6 +24,9 @@
// mapnik // mapnik
#include <mapnik/feature_factory.hpp> #include <mapnik/feature_factory.hpp>
// boost
#include <boost/algorithm/string.hpp>
// stl // stl
#include <iostream> #include <iostream>
@ -34,13 +37,13 @@ using mapnik::feature_factory;
template <typename filterT> template <typename filterT>
shape_featureset<filterT>::shape_featureset(const filterT& filter, shape_featureset<filterT>::shape_featureset(const filterT& filter,
const std::string& shape_file, const std::string& shape_name,
const std::set<std::string>& attribute_names, const std::set<std::string>& attribute_names,
std::string const& encoding, std::string const& encoding,
long file_length ) long file_length )
: filter_(filter), : filter_(filter),
//shape_type_(shape_io::shape_null), //shape_type_(shape_io::shape_null),
shape_(shape_file, false), shape_(shape_name, false),
query_ext_(), query_ext_(),
tr_(new transcoder(encoding)), tr_(new transcoder(encoding)),
file_length_(file_length), file_length_(file_length),
@ -65,12 +68,14 @@ shape_featureset<filterT>::shape_featureset(const filterT& filter,
{ {
std::ostringstream s; std::ostringstream s;
s << "error no attribute by the name of '" << *pos << "'" s << "no attribute '" << *pos << "' in '"
<< ", available attributes are:"; << shape_name << "'. Valid attributes are: ";
std::vector<std::string> list;
for (int i=0;i<shape_.dbf().num_fields();++i) for (int i=0;i<shape_.dbf().num_fields();++i)
{ {
s << " '" << shape_.dbf().descriptor(i).name_ << "'"; list.push_back(shape_.dbf().descriptor(i).name_);
} }
s << boost::algorithm::join(list, ",") << ".";
throw mapnik::datasource_exception( "Shape Plugin: " + s.str() ); throw mapnik::datasource_exception( "Shape Plugin: " + s.str() );
} }

View file

@ -26,6 +26,7 @@
#include <mapnik/feature_factory.hpp> #include <mapnik/feature_factory.hpp>
// boost // boost
#include <boost/algorithm/string.hpp>
#include <boost/interprocess/streams/bufferstream.hpp> #include <boost/interprocess/streams/bufferstream.hpp>
// stl // stl
@ -41,7 +42,8 @@ template <typename filterT>
shape_index_featureset<filterT>::shape_index_featureset(const filterT& filter, shape_index_featureset<filterT>::shape_index_featureset(const filterT& filter,
shape_io& shape, shape_io& shape,
const std::set<std::string>& attribute_names, const std::set<std::string>& attribute_names,
std::string const& encoding) std::string const& encoding,
std::string const& shape_name)
: filter_(filter), : filter_(filter),
//shape_type_(0), //shape_type_(0),
shape_(shape), shape_(shape),
@ -86,12 +88,14 @@ shape_index_featureset<filterT>::shape_index_featureset(const filterT& filter,
{ {
std::ostringstream s; std::ostringstream s;
s << "error no attribute by the name of '" << *pos << "'" s << "no attribute '" << *pos << "' in '"
<< ", available attributes are:"; << shape_name << "'. Valid attributes are: ";
std::vector<std::string> list;
for (int i=0;i<shape_.dbf().num_fields();++i) for (int i=0;i<shape_.dbf().num_fields();++i)
{ {
s << " '" << shape_.dbf().descriptor(i).name_ << "'"; list.push_back(shape_.dbf().descriptor(i).name_);
} }
s << boost::algorithm::join(list, ",") << ".";
throw mapnik::datasource_exception( "Shape Plugin: " + s.str() ); throw mapnik::datasource_exception( "Shape Plugin: " + s.str() );
} }

View file

@ -53,7 +53,8 @@ class shape_index_featureset : public Featureset
shape_index_featureset(const filterT& filter, shape_index_featureset(const filterT& filter,
shape_io& shape, shape_io& shape,
const std::set<std::string>& attribute_names, const std::set<std::string>& attribute_names,
std::string const& encoding); std::string const& encoding,
std::string const& shape_name);
virtual ~shape_index_featureset(); virtual ~shape_index_featureset();
feature_ptr next(); feature_ptr next();
private: private:

View file

@ -80,6 +80,7 @@ public:
{ {
return (index_ && index_->is_open()); return (index_ && index_->is_open());
} }
void move_to(int id); void move_to(int id);
int type() const; int type() const;
const box2d<double>& current_extent() const; const box2d<double>& current_extent() const;