shape: throw an error if an attribute name is requested that does not exist and report out which attribute names are available - closes #604

This commit is contained in:
Dane Springmeyer 2010-09-14 17:59:50 +00:00
parent fbd0e4954c
commit 1aa05e052d
2 changed files with 30 additions and 0 deletions

View file

@ -43,14 +43,29 @@ shape_featureset<filterT>::shape_featureset(const filterT& filter,
typename std::set<std::string>::const_iterator pos=attribute_names.begin();
while (pos!=attribute_names.end())
{
bool found_name = false;
for (int i=0;i<shape_.dbf().num_fields();++i)
{
if (shape_.dbf().descriptor(i).name_ == *pos)
{
attr_ids_.push_back(i);
found_name = true;
break;
}
}
if (!found_name)
{
std::ostringstream s;
s << "Shapefile Plugin: Error: no attribute by the name of '" << *pos << "'"
<< ", available attributes are:";
for (int i=0;i<shape_.dbf().num_fields();++i)
{
s << " '" << shape_.dbf().descriptor(i).name_ << "'";
}
throw mapnik::datasource_exception( s.str() );
}
++pos;
}
}

View file

@ -60,14 +60,29 @@ shape_index_featureset<filterT>::shape_index_featureset(const filterT& filter,
std::set<std::string>::const_iterator pos=attribute_names.begin();
while (pos!=attribute_names.end())
{
bool found_name = false;
for (int i=0;i<shape_.dbf().num_fields();++i)
{
if (shape_.dbf().descriptor(i).name_ == *pos)
{
attr_ids_.insert(i);
found_name = true;
break;
}
}
if (!found_name)
{
std::ostringstream s;
s << "Shapefile Plugin: Error: no attribute by the name of '" << *pos << "'"
<< ", available attributes are:";
for (int i=0;i<shape_.dbf().num_fields();++i)
{
s << " '" << shape_.dbf().descriptor(i).name_ << "'";
}
throw mapnik::datasource_exception( s.str() );
}
++pos;
}
}