+ refactor attribute validating
+ fix context in feature_at_point
This commit is contained in:
parent
e49fcb83b1
commit
07a1b420cc
1 changed files with 52 additions and 38 deletions
|
@ -429,36 +429,24 @@ layer_descriptor ogr_datasource::get_descriptor() const
|
||||||
return desc_;
|
return desc_;
|
||||||
}
|
}
|
||||||
|
|
||||||
featureset_ptr ogr_datasource::features(query const& q) const
|
void validate_attribute_names(query const& q, std::vector<attribute_descriptor> const& names )
|
||||||
{
|
{
|
||||||
if (! is_bound_) bind();
|
std::set<std::string> const& attribute_names = q.property_names();
|
||||||
|
|
||||||
if (dataset_ && layer_.is_valid())
|
|
||||||
{
|
|
||||||
// First we validate query fields: https://github.com/mapnik/mapnik/issues/792
|
|
||||||
std::vector<attribute_descriptor> const& desc_ar = desc_.get_descriptors();
|
|
||||||
std::vector<attribute_descriptor>::const_iterator it = desc_ar.begin();
|
|
||||||
std::vector<attribute_descriptor>::const_iterator end = desc_ar.end();
|
|
||||||
std::vector<std::string> known_fields;
|
|
||||||
mapnik::context_ptr ctx = boost::make_shared<mapnik::context_type>();
|
|
||||||
for (; it != end; ++it)
|
|
||||||
{
|
|
||||||
known_fields.push_back(it->get_name());
|
|
||||||
ctx->push(it->get_name());
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::set<std::string>& attribute_names = q.property_names();
|
|
||||||
std::set<std::string>::const_iterator pos = attribute_names.begin();
|
std::set<std::string>::const_iterator pos = attribute_names.begin();
|
||||||
|
std::set<std::string>::const_iterator end_names = attribute_names.end();
|
||||||
|
|
||||||
while (pos != attribute_names.end())
|
for ( ;pos != end_names; ++pos)
|
||||||
{
|
{
|
||||||
bool found_name = false;
|
bool found_name = false;
|
||||||
for (int i = 0; i < known_fields.size(); ++i)
|
|
||||||
|
std::vector<attribute_descriptor>::const_iterator itr = names.begin();
|
||||||
|
std::vector<attribute_descriptor>::const_iterator end = names.end();
|
||||||
|
|
||||||
|
for (; itr!=end; ++itr)
|
||||||
{
|
{
|
||||||
if (known_fields[i] == *pos)
|
if (itr->get_name() == *pos)
|
||||||
{
|
{
|
||||||
found_name = true;
|
found_name = true;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -466,15 +454,36 @@ featureset_ptr ogr_datasource::features(query const& q) const
|
||||||
if (! found_name)
|
if (! found_name)
|
||||||
{
|
{
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
|
std::vector<attribute_descriptor>::const_iterator itr = names.begin();
|
||||||
s << "OGR Plugin: no attribute '" << *pos << "'. Valid attributes are: "
|
std::vector<attribute_descriptor>::const_iterator end = names.end();
|
||||||
<< boost::algorithm::join(known_fields, ",") << ".";
|
s << "OGR Plugin: no attribute '" << *pos << "'. Valid attributes are: ";
|
||||||
|
for ( ;itr!=end;++itr)
|
||||||
|
{
|
||||||
|
s << itr->get_name() << std::endl;
|
||||||
|
}
|
||||||
throw mapnik::datasource_exception(s.str());
|
throw mapnik::datasource_exception(s.str());
|
||||||
}
|
}
|
||||||
++pos;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
featureset_ptr ogr_datasource::features(query const& q) const
|
||||||
|
{
|
||||||
|
if (! is_bound_) bind();
|
||||||
|
|
||||||
|
if (dataset_ && layer_.is_valid())
|
||||||
|
{
|
||||||
|
// First we validate query fields: https://github.com/mapnik/mapnik/issues/792
|
||||||
|
|
||||||
|
std::vector<attribute_descriptor> const& desc_ar = desc_.get_descriptors();
|
||||||
|
// feature context (schema)
|
||||||
|
mapnik::context_ptr ctx = boost::make_shared<mapnik::context_type>();
|
||||||
|
|
||||||
|
std::vector<attribute_descriptor>::const_iterator itr = desc_ar.begin();
|
||||||
|
std::vector<attribute_descriptor>::const_iterator end = desc_ar.end();
|
||||||
|
|
||||||
|
for (; itr!=end; ++itr) ctx->push(itr->get_name()); // TODO only push query attributes
|
||||||
|
|
||||||
|
validate_attribute_names(q, desc_ar);
|
||||||
|
|
||||||
OGRLayer* layer = layer_.layer();
|
OGRLayer* layer = layer_.layer();
|
||||||
|
|
||||||
|
@ -510,8 +519,13 @@ featureset_ptr ogr_datasource::features_at_point(coord2d const& pt) const
|
||||||
|
|
||||||
if (dataset_ && layer_.is_valid())
|
if (dataset_ && layer_.is_valid())
|
||||||
{
|
{
|
||||||
|
std::vector<attribute_descriptor> const& desc_ar = desc_.get_descriptors();
|
||||||
|
// feature context (schema)
|
||||||
mapnik::context_ptr ctx = boost::make_shared<mapnik::context_type>();
|
mapnik::context_ptr ctx = boost::make_shared<mapnik::context_type>();
|
||||||
// TODO : push all attribute names here
|
|
||||||
|
std::vector<attribute_descriptor>::const_iterator itr = desc_ar.begin();
|
||||||
|
std::vector<attribute_descriptor>::const_iterator end = desc_ar.end();
|
||||||
|
for (; itr!=end; ++itr) ctx->push(itr->get_name());
|
||||||
|
|
||||||
OGRLayer* layer = layer_.layer();
|
OGRLayer* layer = layer_.layer();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue