diff --git a/plugins/input/ogr/ogr_datasource.cpp b/plugins/input/ogr/ogr_datasource.cpp index f6411102b..410f8b516 100644 --- a/plugins/input/ogr/ogr_datasource.cpp +++ b/plugins/input/ogr/ogr_datasource.cpp @@ -429,53 +429,62 @@ layer_descriptor ogr_datasource::get_descriptor() const return desc_; } +void validate_attribute_names(query const& q, std::vector const& names ) +{ + std::set const& attribute_names = q.property_names(); + std::set::const_iterator pos = attribute_names.begin(); + std::set::const_iterator end_names = attribute_names.end(); + + for ( ;pos != end_names; ++pos) + { + bool found_name = false; + + std::vector::const_iterator itr = names.begin(); + std::vector::const_iterator end = names.end(); + + for (; itr!=end; ++itr) + { + if (itr->get_name() == *pos) + { + found_name = true; + break; + } + } + + if (! found_name) + { + std::ostringstream s; + std::vector::const_iterator itr = names.begin(); + std::vector::const_iterator end = names.end(); + 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()); + } + } +} + 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 + // First we validate query fields: https://github.com/mapnik/mapnik/issues/792 + std::vector const& desc_ar = desc_.get_descriptors(); - std::vector::const_iterator it = desc_ar.begin(); - std::vector::const_iterator end = desc_ar.end(); - std::vector known_fields; + // feature context (schema) mapnik::context_ptr ctx = boost::make_shared(); - for (; it != end; ++it) - { - known_fields.push_back(it->get_name()); - ctx->push(it->get_name()); - } - const std::set& attribute_names = q.property_names(); - std::set::const_iterator pos = attribute_names.begin(); + std::vector::const_iterator itr = desc_ar.begin(); + std::vector::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); - while (pos != attribute_names.end()) - { - bool found_name = false; - for (int i = 0; i < known_fields.size(); ++i) - { - if (known_fields[i] == *pos) - { - found_name = true; - - break; - } - } - - if (! found_name) - { - std::ostringstream s; - - s << "OGR Plugin: no attribute '" << *pos << "'. Valid attributes are: " - << boost::algorithm::join(known_fields, ",") << "."; - - throw mapnik::datasource_exception(s.str()); - } - ++pos; - } - - OGRLayer* layer = layer_.layer(); if (indexed_) @@ -510,8 +519,13 @@ featureset_ptr ogr_datasource::features_at_point(coord2d const& pt) const if (dataset_ && layer_.is_valid()) { + std::vector const& desc_ar = desc_.get_descriptors(); + // feature context (schema) mapnik::context_ptr ctx = boost::make_shared(); - // TODO : push all attribute names here + + std::vector::const_iterator itr = desc_ar.begin(); + std::vector::const_iterator end = desc_ar.end(); + for (; itr!=end; ++itr) ctx->push(itr->get_name()); OGRLayer* layer = layer_.layer();