Skip to content

Commit f806cc9

Browse files
committed
add bbox for capital node
1 parent 2053102 commit f806cc9

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cosmogony_builder"
3-
version = "0.14.4"
3+
version = "0.14.5"
44
authors = ["Adrien Matissart <[email protected]>", "Antoine Desbordes <[email protected]>"]
55
license = "Apache-2.0"
66
repository = "https://github.com/osm-without-borders/cosmogony"

cosmogony/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cosmogony"
3-
version = "0.14.4"
3+
version = "0.14.5"
44
authors = ["Adrien Matissart <[email protected]>", "Antoine Desbordes <[email protected]>"]
55
license = "Apache-2.0"
66
repository = "https://github.com/osm-without-borders/cosmogony"

src/additional_zones.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::hierarchy_builder::ZonesTree;
2-
use crate::is_place;
2+
use crate::is_additional_place;
33
use crate::zone_ext::ZoneExt;
44
use anyhow::{Context, Result};
55
use cosmogony::{Zone, ZoneIndex, ZoneType};
@@ -46,7 +46,8 @@ pub fn compute_additional_places(
4646
let candidate_parent_zones = place_zones
4747
.par_iter()
4848
.filter(|place| {
49-
place.admin_level.is_none() && place.zone_type == Option::from(ZoneType::Suburb)
49+
(place.admin_level.is_none() && place.zone_type == Option::from(ZoneType::Suburb))
50+
| place.tags.get("capital").map_or(false, |v| v == "yes")
5051
})
5152
.filter_map(|place| {
5253
place.zone_type?;
@@ -56,7 +57,7 @@ pub fn compute_additional_places(
5657
(parent.zone_type)
5758
.map(|parent_zone| {
5859
if parent_zone == ZoneType::Country {
59-
info!(
60+
println!(
6061
"Ignoring place with id {} and country {} as parent",
6162
place.osm_id, parent.osm_id
6263
);
@@ -65,7 +66,7 @@ pub fn compute_additional_places(
6566
// Ensuring zones are strictly increasing also ensures there will be no
6667
// duplicates, for example by adding an admin label which is inside its
6768
// boundary.
68-
parent_zone > place.zone_type.unwrap_or(parent_zone)
69+
parent_zone >= place.zone_type.unwrap_or(parent_zone)
6970
&& parent_zone < ZoneType::Country
7071
})
7172
.unwrap_or(false)
@@ -81,7 +82,7 @@ pub fn compute_additional_places(
8182
map1
8283
});
8384

84-
info!(
85+
println!(
8586
"We'll compute voronois partitions for {} parent zones",
8687
candidate_parent_zones.len()
8788
);
@@ -123,7 +124,7 @@ fn read_places(parsed_pbf: &BTreeMap<OsmId, OsmObj>) -> Vec<Zone> {
123124
.values()
124125
.enumerate()
125126
.filter_map(|(index, obj)| {
126-
if !is_place(obj) {
127+
if !is_additional_place(obj) {
127128
return None;
128129
}
129130

src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ pub fn is_place(obj: &OsmObj) -> bool {
5151
}
5252
}
5353

54+
pub fn is_additional_place(obj: &OsmObj) -> bool {
55+
match *obj {
56+
OsmObj::Node(ref node) => {
57+
matches!(
58+
node.tags.get("place").and_then(|s| ZoneType::parse(s)),
59+
Some(ZoneType::City | ZoneType::Suburb)
60+
) | node.tags.get("capital").map_or(false, |v| v == "yes")
61+
}
62+
_ => false,
63+
}
64+
}
65+
5466
pub fn get_zones_and_stats(
5567
pbf: &BTreeMap<OsmId, OsmObj>,
5668
) -> Result<(Vec<Zone>, CosmogonyStats), Error> {

0 commit comments

Comments
 (0)