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:
parent
fbd0e4954c
commit
1aa05e052d
2 changed files with 30 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue