Skip to content

Commit 124221d

Browse files
jbgriesneramatissart
authored andcommitted
Add role label as zone center (#80)
* add label role as admin wcenter * add test * relation.refs otherwise we never enter the second find * fmt + version 0.5.2
1 parent 7234da2 commit 124221d

File tree

6 files changed

+40
-7
lines changed

6 files changed

+40
-7
lines changed

Cargo.lock

Lines changed: 4 additions & 4 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"
3-
version = "0.5.1"
3+
version = "0.5.2"
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/zone.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,11 @@ impl Zone {
216216
result.boundary = build_boundary(relation, objects);
217217
result.bbox = result.boundary.as_ref().and_then(|b| b.bounding_rect());
218218

219-
let center = relation
220-
.refs
219+
let refs = &relation.refs;
220+
let center = refs
221221
.iter()
222222
.find(|r| r.role == "admin_centre")
223+
.or(refs.iter().find(|r| r.role == "label"))
223224
.and_then(|r| objects.get(&r.member))
224225
.and_then(|o| o.node());
225226

tests/cosmogony_lux_test.rs renamed to tests/cosmogony_test.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ use cosmogony::{Cosmogony, Zone, ZoneIndex, ZoneType};
44
use std::collections::BTreeMap;
55
use std::process::{Command, Output};
66

7+
use geo_types::Point;
8+
type Coord = Point<f64>;
9+
710
fn launch_command_line(args: Vec<&str>) -> Output {
811
let cosmogony_bin = concat!(env!("OUT_DIR"), "/../../../cosmogony");
912
Command::new(cosmogony_bin)
@@ -265,3 +268,28 @@ fn test_lux_zone_types() {
265268
Some(&"Laksembɛg".to_string())
266269
);
267270
}
271+
272+
#[test]
273+
fn test_center_label() {
274+
let ottawa_test_file = concat!(
275+
env!("OUT_DIR"),
276+
"/../../../../../tests/data/gatineau.osm.pbf"
277+
);
278+
let cosmogony = cosmogony::build_cosmogony(ottawa_test_file.into(), true, Some("ca".into()))
279+
.expect("invalid cosmogony");
280+
281+
let gati = cosmogony
282+
.zones
283+
.iter()
284+
.find(|z| z.name == "Gatineau" && z.zone_type == Some(ZoneType::City))
285+
.unwrap();
286+
287+
assert_eq!(gati.osm_id, "relation:5356213");
288+
assert_eq!(gati.admin_level, Some(8));
289+
assert!(gati.center.is_some());
290+
let gati_center = gati.center.unwrap();
291+
assert_eq!(
292+
gati_center,
293+
Coord::new(-75.72326699999999, 45.457240999999996)
294+
);
295+
}

tests/data/gatineau.osm.pbf

18.8 KB
Binary file not shown.

tests/data/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ Expected relations:
1515
* `admin_level = 8`: 104 (and a few incomplete ones. One of them only have the admin center missing out)
1616
* `admin_level = 9`: 79 (and a few incomplete ones)
1717
* `admin_level = 10`: 2 (and many incomplete ones)
18+
19+
## gatineau pbf
20+
21+
This PBF contains a single relation that has no "admin_center" role node but a "label" one.

0 commit comments

Comments
 (0)