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

View file

@ -24,6 +24,9 @@
// mapnik
#include <mapnik/feature_factory.hpp>
// boost
#include <boost/algorithm/string.hpp>
// stl
#include <iostream>
@ -34,13 +37,13 @@ using mapnik::feature_factory;
template <typename filterT>
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,
std::string const& encoding,
long file_length )
: filter_(filter),
//shape_type_(shape_io::shape_null),
shape_(shape_file, false),
shape_(shape_name, false),
query_ext_(),
tr_(new transcoder(encoding)),
file_length_(file_length),
@ -65,12 +68,14 @@ shape_featureset<filterT>::shape_featureset(const filterT& filter,
{
std::ostringstream s;
s << "error no attribute by the name of '" << *pos << "'"
<< ", available attributes are:";
s << "no attribute '" << *pos << "' in '"
<< shape_name << "'. Valid attributes are: ";
std::vector<std::string> list;
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() );
}

View file

@ -26,6 +26,7 @@
#include <mapnik/feature_factory.hpp>
// boost
#include <boost/algorithm/string.hpp>
#include <boost/interprocess/streams/bufferstream.hpp>
// stl
@ -41,7 +42,8 @@ template <typename filterT>
shape_index_featureset<filterT>::shape_index_featureset(const filterT& filter,
shape_io& shape,
const std::set<std::string>& attribute_names,
std::string const& encoding)
std::string const& encoding,
std::string const& shape_name)
: filter_(filter),
//shape_type_(0),
shape_(shape),
@ -86,12 +88,14 @@ shape_index_featureset<filterT>::shape_index_featureset(const filterT& filter,
{
std::ostringstream s;
s << "error no attribute by the name of '" << *pos << "'"
<< ", available attributes are:";
s << "no attribute '" << *pos << "' in '"
<< shape_name << "'. Valid attributes are: ";
std::vector<std::string> list;
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() );
}

View file

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

View file

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