Skip to content

Commit

Permalink
Add where_has_nodes filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdillah committed May 17, 2021
1 parent 45c96eb commit 9da2ca2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ impl WayQueryBuilder {
WayQueryBuilder { _qb: self._qb.clone().by_tag_eq(key, value) }
}

#[text_signature = "(self, key, value)"]
/// Filter Way that contains nodes ``nodes``
///
/// See :py:class:`Map` documentation for usage example.
///
/// Parameters
/// ----------
/// nodes : List[int]
/// A list of node ids.
pub fn where_contain_nodes(&self, nodes: Vec<osm::Id>) -> WayQueryBuilder {
WayQueryBuilder { _qb: self._qb.clone().contain_nodes(nodes) }
}

#[text_signature = "(self)"]
/// Returns the filtered Way list
pub fn get(&self) -> Vec<Way> {
Expand Down
12 changes: 12 additions & 0 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub(crate) enum FilterQuery {
// Node only:
// Way only:
IsPolygon,
HasNodes(Vec<osm::Id>),
}

trait Filter<T> {
Expand Down Expand Up @@ -41,6 +42,17 @@ impl Filter<&osm::Way> for FilterQuery {
return true;
},
Self::IsPolygon => item.is_polygon(),
Self::HasNodes(node_ids) => {
// TODO: We will create faster index later
for element in &item.nodes {
if let osm::UnresolvedReference::Node(id) = element {
if node_ids.contains(&id) {
return true;
}
}
}
return false;
},
_ => panic!("You're using exclusive filter on wrong type")
}
}
Expand Down

0 comments on commit 9da2ca2

Please sign in to comment.