Skip to content

Commit

Permalink
add bbox for capital node
Browse files Browse the repository at this point in the history
  • Loading branch information
sdrll committed Jan 25, 2024
1 parent 2053102 commit f806cc9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cosmogony_builder"
version = "0.14.4"
version = "0.14.5"
authors = ["Adrien Matissart <a.matissart@qwantresearch.com>", "Antoine Desbordes <antoine.desbordes@gmail.com>"]
license = "Apache-2.0"
repository = "https://github.com/osm-without-borders/cosmogony"
Expand Down
2 changes: 1 addition & 1 deletion cosmogony/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cosmogony"
version = "0.14.4"
version = "0.14.5"
authors = ["Adrien Matissart <a.matissart@qwantresearch.com>", "Antoine Desbordes <antoine.desbordes@gmail.com>"]
license = "Apache-2.0"
repository = "https://github.com/osm-without-borders/cosmogony"
Expand Down
13 changes: 7 additions & 6 deletions src/additional_zones.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::hierarchy_builder::ZonesTree;
use crate::is_place;
use crate::is_additional_place;
use crate::zone_ext::ZoneExt;
use anyhow::{Context, Result};
use cosmogony::{Zone, ZoneIndex, ZoneType};
Expand Down Expand Up @@ -46,7 +46,8 @@ pub fn compute_additional_places(
let candidate_parent_zones = place_zones
.par_iter()
.filter(|place| {
place.admin_level.is_none() && place.zone_type == Option::from(ZoneType::Suburb)
(place.admin_level.is_none() && place.zone_type == Option::from(ZoneType::Suburb))
| place.tags.get("capital").map_or(false, |v| v == "yes")
})
.filter_map(|place| {
place.zone_type?;
Expand All @@ -56,7 +57,7 @@ pub fn compute_additional_places(
(parent.zone_type)
.map(|parent_zone| {
if parent_zone == ZoneType::Country {
info!(
println!(
"Ignoring place with id {} and country {} as parent",
place.osm_id, parent.osm_id
);
Expand All @@ -65,7 +66,7 @@ pub fn compute_additional_places(
// Ensuring zones are strictly increasing also ensures there will be no
// duplicates, for example by adding an admin label which is inside its
// boundary.
parent_zone > place.zone_type.unwrap_or(parent_zone)
parent_zone >= place.zone_type.unwrap_or(parent_zone)
&& parent_zone < ZoneType::Country
})
.unwrap_or(false)
Expand All @@ -81,7 +82,7 @@ pub fn compute_additional_places(
map1
});

info!(
println!(
"We'll compute voronois partitions for {} parent zones",
candidate_parent_zones.len()
);
Expand Down Expand Up @@ -123,7 +124,7 @@ fn read_places(parsed_pbf: &BTreeMap<OsmId, OsmObj>) -> Vec<Zone> {
.values()
.enumerate()
.filter_map(|(index, obj)| {
if !is_place(obj) {
if !is_additional_place(obj) {
return None;
}

Expand Down
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ pub fn is_place(obj: &OsmObj) -> bool {
}
}

pub fn is_additional_place(obj: &OsmObj) -> bool {
match *obj {
OsmObj::Node(ref node) => {
matches!(
node.tags.get("place").and_then(|s| ZoneType::parse(s)),
Some(ZoneType::City | ZoneType::Suburb)
) | node.tags.get("capital").map_or(false, |v| v == "yes")
}
_ => false,
}
}

pub fn get_zones_and_stats(
pbf: &BTreeMap<OsmId, OsmObj>,
) -> Result<(Vec<Zone>, CosmogonyStats), Error> {
Expand Down

0 comments on commit f806cc9

Please sign in to comment.