Update geo, and copy in some popgetter code here temporarily, while the

upstream repo is in flux.
This commit is contained in:
Dustin Carlino 2023-11-27 19:34:22 +00:00
parent 26d68c77ce
commit 817e2203fe
8 changed files with 249 additions and 67 deletions

182
Cargo.lock generated
View File

@ -72,13 +72,14 @@ dependencies = [
[[package]]
name = "ahash"
version = "0.8.3"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f"
checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a"
dependencies = [
"cfg-if",
"once_cell",
"version_check",
"zerocopy",
]
[[package]]
@ -90,6 +91,12 @@ dependencies = [
"memchr",
]
[[package]]
name = "allocator-api2"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
[[package]]
name = "alsa"
version = "0.7.0"
@ -147,9 +154,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.69"
version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800"
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
[[package]]
name = "approx"
@ -209,13 +216,13 @@ dependencies = [
[[package]]
name = "async-trait"
version = "0.1.57"
version = "0.1.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76464446b8bc32758d7e88ee1a804d9914cd9b1cb264c029899680b0be29826f"
checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.99",
"syn 2.0.39",
]
[[package]]
@ -582,7 +589,7 @@ version = "3.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65"
dependencies = [
"heck 0.4.0",
"heck 0.4.1",
"proc-macro-error",
"proc-macro2",
"quote",
@ -873,7 +880,7 @@ dependencies = [
[[package]]
name = "country-geocoder"
version = "0.1.0"
source = "git+https://github.com/a-b-street/country-geocoder#395e847748f1db955e96ecbdbad2fedea3ceeb74"
source = "git+https://github.com/a-b-street/country-geocoder#4a9b736340f7824f24f4e35cede1ffbceac2ec84"
dependencies = [
"geo",
"geojson",
@ -908,9 +915,9 @@ dependencies = [
[[package]]
name = "crc32fast"
version = "1.2.1"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a"
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
dependencies = [
"cfg-if",
]
@ -966,7 +973,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af91f40b7355f82b0a891f50e70399475945bb0b0da4f1700ce60761c9d3e359"
dependencies = [
"csv-core",
"itoa 1.0.2",
"itoa 1.0.9",
"ryu",
"serde",
]
@ -1286,9 +1293,9 @@ dependencies = [
[[package]]
name = "either"
version = "1.6.1"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
[[package]]
name = "embedded-hal"
@ -1456,6 +1463,12 @@ dependencies = [
"instant",
]
[[package]]
name = "fastrand"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
[[package]]
name = "fifteen_min"
version = "0.1.0"
@ -1641,9 +1654,12 @@ dependencies = [
[[package]]
name = "fs-err"
version = "2.9.0"
version = "2.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0845fa252299212f0389d64ba26f34fa32cfe41588355f21ed507c59a0f64541"
checksum = "88a41f105fe1d5b6b34b2055e3dc59bb79b46b48b2040b9e6c7b4b5de097aa41"
dependencies = [
"autocfg",
]
[[package]]
name = "futures"
@ -1699,7 +1715,7 @@ version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce"
dependencies = [
"fastrand",
"fastrand 1.8.0",
"futures-core",
"futures-io",
"memchr",
@ -1851,9 +1867,9 @@ dependencies = [
[[package]]
name = "geo"
version = "0.26.0"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1645cf1d7fea7dac1a66f7357f3df2677ada708b8d9db8e9b043878930095a96"
checksum = "4841b40fdbccd4b7042bd6195e4de91da54af34c50632e371bcbfcdfb558b873"
dependencies = [
"earcutr",
"float_next_after 1.0.0",
@ -1863,13 +1879,14 @@ dependencies = [
"num-traits",
"robust",
"rstar",
"spade",
]
[[package]]
name = "geo-types"
version = "0.7.11"
version = "0.7.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9705398c5c7b26132e74513f4ee7c1d7dafd786004991b375c172be2be0eecaa"
checksum = "567495020b114f1ce9bed679b29975aa0bfae06ac22beacd5cfde5dabe7b05d6"
dependencies = [
"approx",
"num-traits",
@ -1902,7 +1919,7 @@ dependencies = [
[[package]]
name = "geom"
version = "0.1.0"
source = "git+https://github.com/a-b-street/geom#34194e73db3fd6343ad223e8a4b1075201094f1a"
source = "git+https://github.com/a-b-street/geom#97d271a536fc5877e778189512b2f65212b8c8ed"
dependencies = [
"anyhow",
"earcutr",
@ -2151,7 +2168,7 @@ version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e"
dependencies = [
"ahash 0.8.3",
"ahash 0.8.6",
]
[[package]]
@ -2159,6 +2176,10 @@ name = "hashbrown"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156"
dependencies = [
"ahash 0.8.6",
"allocator-api2",
]
[[package]]
name = "hashlink"
@ -2217,9 +2238,9 @@ dependencies = [
[[package]]
name = "heck"
version = "0.4.0"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "hermit-abi"
@ -2325,7 +2346,7 @@ dependencies = [
"http-body",
"httparse",
"httpdate",
"itoa 1.0.2",
"itoa 1.0.9",
"pin-project-lite",
"socket2 0.4.9",
"tokio",
@ -2562,9 +2583,9 @@ checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
[[package]]
name = "itoa"
version = "1.0.2"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d"
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
[[package]]
name = "jni"
@ -2750,6 +2771,12 @@ version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b64f40e5e03e0d54f03845c8197d0291253cdbedfb1cb46b13c2c117554a9f4c"
[[package]]
name = "linux-raw-sys"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829"
[[package]]
name = "lock_api"
version = "0.4.7"
@ -3345,9 +3372,9 @@ checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66"
[[package]]
name = "ordered-float"
version = "3.7.0"
version = "4.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fc2dbde8f8a79f2102cc474ceb0ad68e3b80b85289ea62389b60e66777e4213"
checksum = "536900a8093134cf9ccf00a27deb3532421099e958d9dd431135d0c7543ca1e8"
dependencies = [
"num-traits",
"rand",
@ -3363,7 +3390,7 @@ checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"
[[package]]
name = "osm2lanes"
version = "0.1.0"
source = "git+https://github.com/a-b-street/osm2streets#086a347e6cad7c556d7f7d5bf57d4b270c8a030f"
source = "git+https://github.com/a-b-street/osm2streets#ee4d022879169687ca8d97a9553f1c17251324f8"
dependencies = [
"abstutil",
"anyhow",
@ -3375,7 +3402,7 @@ dependencies = [
[[package]]
name = "osm2streets"
version = "0.1.0"
source = "git+https://github.com/a-b-street/osm2streets#086a347e6cad7c556d7f7d5bf57d4b270c8a030f"
source = "git+https://github.com/a-b-street/osm2streets#ee4d022879169687ca8d97a9553f1c17251324f8"
dependencies = [
"abstutil",
"anyhow",
@ -3610,12 +3637,10 @@ dependencies = [
[[package]]
name = "polylabel"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61132847769c5a4f41a977fd56e58e7e7a3c8ca602008dd124c0928c7387bfcb"
version = "3.0.0"
source = "git+https://github.com/dabreegster/polylabel-rs?branch=update_geo#f01b75acbc5ef9c8b1f61af8f74e3403c1ee9d0b"
dependencies = [
"geo",
"libc",
"num-traits",
"thiserror",
]
@ -3647,7 +3672,6 @@ dependencies = [
[[package]]
name = "popgetter"
version = "0.1.0"
source = "git+https://github.com/dabreegster/popgetter/#d0e8167e37cedb773377dc96f325fba3ab5026b2"
dependencies = [
"anyhow",
"fs-err",
@ -3926,15 +3950,6 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]]
name = "remove_dir_all"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
dependencies = [
"winapi",
]
[[package]]
name = "reqwest"
version = "0.11.22"
@ -4178,6 +4193,19 @@ dependencies = [
"windows-sys 0.45.0",
]
[[package]]
name = "rustix"
version = "0.38.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc99bc2d4f1fed22595588a013687477aedf3cdcfb26558c559edb67b4d9b22e"
dependencies = [
"bitflags 2.4.1",
"errno 0.3.1",
"libc",
"linux-raw-sys 0.4.11",
"windows-sys 0.48.0",
]
[[package]]
name = "rustls"
version = "0.21.9"
@ -4233,9 +4261,9 @@ dependencies = [
[[package]]
name = "ryu"
version = "1.0.5"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
[[package]]
name = "safe_arch"
@ -4375,7 +4403,7 @@ version = "1.0.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b"
dependencies = [
"itoa 1.0.2",
"itoa 1.0.9",
"ryu",
"serde",
]
@ -4387,7 +4415,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"
dependencies = [
"form_urlencoded",
"itoa 1.0.2",
"itoa 1.0.9",
"ryu",
"serde",
]
@ -4542,6 +4570,18 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "spade"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d3bf265ec2d5dd1ddf87863252123447c550491adba2c70c574173a95cd8ba"
dependencies = [
"hashbrown 0.14.2",
"num-traits",
"robust",
"smallvec",
]
[[package]]
name = "spin"
version = "0.5.2"
@ -4566,7 +4606,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "streets_reader"
version = "0.1.0"
source = "git+https://github.com/a-b-street/osm2streets#086a347e6cad7c556d7f7d5bf57d4b270c8a030f"
source = "git+https://github.com/a-b-street/osm2streets#ee4d022879169687ca8d97a9553f1c17251324f8"
dependencies = [
"abstutil",
"anyhow",
@ -4634,7 +4674,7 @@ version = "0.24.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59"
dependencies = [
"heck 0.4.0",
"heck 0.4.1",
"proc-macro2",
"quote",
"rustversion",
@ -4734,7 +4774,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1a45a1c4c9015217e12347f2a411b57ce2c4fc543913b14b6fe40483328e709"
dependencies = [
"cfg-expr",
"heck 0.4.0",
"heck 0.4.1",
"pkg-config",
"toml",
"version-compare",
@ -4753,16 +4793,15 @@ dependencies = [
[[package]]
name = "tempfile"
version = "3.3.0"
version = "3.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5"
dependencies = [
"cfg-if",
"fastrand",
"libc",
"redox_syscall 0.2.16",
"remove_dir_all",
"winapi",
"fastrand 2.0.1",
"redox_syscall 0.4.1",
"rustix 0.38.25",
"windows-sys 0.48.0",
]
[[package]]
@ -4956,10 +4995,9 @@ dependencies = [
[[package]]
name = "topojson"
version = "0.5.1"
source = "git+https://github.com/dabreegster/topojson?branch=both_fixes#6efc6be1d4ef65909d6a4a68e53940d83f6015d7"
source = "git+https://github.com/georust/topojson#b9a63622b1a4c253ec9c362181b9a77838fb963e"
dependencies = [
"geojson",
"log",
"serde",
"serde_json",
]
@ -5908,3 +5946,23 @@ name = "xmlwriter"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9"
[[package]]
name = "zerocopy"
version = "0.7.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e97e415490559a91254a2979b4829267a57d2fcd741a98eee8b722fb57289aa0"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.7.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd7e48ccf166952882ca8bd778a43502c64f33bf94c12ebe2a7f08e5a0f6689f"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.39",
]

View File

@ -17,6 +17,7 @@ members = [
"map_model",
"piggyback",
"popdat",
"popgetter",
"raw_map",
"sim",
"synthpop",
@ -37,7 +38,7 @@ opt-level = 3
# Specify the versions for common dependencies just once here, instead of
# repeating in a bunch of crates
[workspace.dependencies]
anyhow = "1.0.69"
anyhow = "1.0.75"
bincode = "1.3.1"
colorous = "1.0.9"
contour = "0.7.0"
@ -46,7 +47,7 @@ flate2 = "1.0.26"
fs-err = "2.9.0"
futures = { version = "0.3.27"}
futures-channel = { version = "0.3.29"}
geo = "0.26.0"
geo = "0.27.0"
geojson = { version = "0.24.1", features = ["geo-types"] }
geom = { git = "https://github.com/a-b-street/geom" }
getrandom = "0.2.11"

View File

@ -14,7 +14,7 @@ geom = { workspace = true }
kml = { path = "../kml" }
log = { workspace = true }
osm2streets = { git = "https://github.com/a-b-street/osm2streets" }
popgetter = { git = "https://github.com/dabreegster/popgetter/" }
popgetter = { path = "../popgetter" }
raw_map = { path = "../raw_map" }
serde = { workspace = true }
streets_reader = { git = "https://github.com/a-b-street/osm2streets" }

View File

@ -17,7 +17,7 @@ log = { workspace = true }
lyon = "1.0.1"
md5 = "0.7.0"
petgraph = { version = "0.6.4", features=["serde-1"] }
popgetter = { git = "https://github.com/dabreegster/popgetter/" }
popgetter = { path = "../popgetter" }
rand = { workspace = true }
rand_xorshift = { workspace = true }
raw_map = { path = "../raw_map" }

13
popgetter/Cargo.toml Normal file
View File

@ -0,0 +1,13 @@
[package]
name = "popgetter"
version = "0.1.0"
edition = "2021"
[dependencies]
anyhow = { workspace = true }
fs-err = { workspace = true }
geo = { workspace = true }
geo-types = "0.7.12"
geojson = { workspace = true }
serde = { workspace = true }
topojson = { git = "https://github.com/georust/topojson" }

1
popgetter/README.md Normal file
View File

@ -0,0 +1 @@
Temporarily, old code from <https://github.com/Urban-Analytics-Technology-Platform/popgetter> is copied here to upgrade dependencies. When the upstream repo is ready again, depend on it.

109
popgetter/src/lib.rs Normal file
View File

@ -0,0 +1,109 @@
use std::time::Instant;
use anyhow::{bail, Result};
use geo::Intersects;
use geojson::Feature;
use serde::{Deserialize, Serialize};
use topojson::{to_geojson, TopoJson};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CensusZone {
// England: OA11CD
pub id: String,
// (England-only for now)
// 0 cars or vars per household. See https://www.ons.gov.uk/datasets/TS045/editions/2021/versions/3 for details.
pub cars_0: u16,
pub cars_1: u16,
pub cars_2: u16,
// 3 or more cars or vans per household
pub cars_3: u16,
}
impl CensusZone {
// Assumes "3 or more" just means 3
pub fn total_cars(&self) -> u16 {
self.cars_1 + 2 * self.cars_2 + 3 * self.cars_3
}
}
/// Clips existing TopoJSON files to the given boundary. All polygons are in WGS84.
pub fn clip_zones(
topojson_path: &str,
boundary: geo::Polygon<f64>,
) -> Result<Vec<(geo::Polygon<f64>, CensusZone)>> {
let gj = load_all_zones_as_geojson(topojson_path)?;
let start = Instant::now();
let mut output = Vec::new();
for gj_feature in gj {
let geom: geo::Geometry<f64> = gj_feature.clone().try_into()?;
if boundary.intersects(&geom) {
let polygon = match geom {
geo::Geometry::Polygon(p) => p,
// TODO What're these, and what should we do with them?
geo::Geometry::MultiPolygon(mut mp) => mp.0.remove(0),
_ => bail!("Unexpected geometry type for {:?}", gj_feature.properties),
};
let census_zone = CensusZone {
id: gj_feature
.property("ID")
.unwrap()
.as_str()
.unwrap()
.to_string(),
cars_0: gj_feature
.property("cars_0")
.unwrap()
.as_u64()
.unwrap()
.try_into()?,
cars_1: gj_feature
.property("cars_1")
.unwrap()
.as_u64()
.unwrap()
.try_into()?,
cars_2: gj_feature
.property("cars_2")
.unwrap()
.as_u64()
.unwrap()
.try_into()?,
cars_3: gj_feature
.property("cars_3")
.unwrap()
.as_u64()
.unwrap()
.try_into()?,
};
output.push((polygon, census_zone));
}
}
println!(
"Filtering took {:?}. {} results",
start.elapsed(),
output.len()
);
Ok(output)
}
fn load_all_zones_as_geojson(path: &str) -> Result<Vec<Feature>> {
let mut start = Instant::now();
let topojson_str = fs_err::read_to_string(path)?;
println!("Reading file took {:?}", start.elapsed());
start = Instant::now();
let topo = topojson_str.parse::<TopoJson>()?;
println!("Parsing topojson took {:?}", start.elapsed());
start = Instant::now();
let fc = match topo {
TopoJson::Topology(t) => to_geojson(&t, "zones")?,
_ => bail!("Unexpected topojson contents"),
};
println!("Converting to geojson took {:?}", start.elapsed());
Ok(fc.features)
}

View File

@ -10,6 +10,6 @@ abstutil = { path = "../abstutil" }
geom = { workspace = true }
serde = { workspace = true }
osm2streets = { git = "https://github.com/a-b-street/osm2streets" }
popgetter = { git = "https://github.com/dabreegster/popgetter/" }
popgetter = { path = "../popgetter" }
strum = "0.24.1"
strum_macros = "0.24.3"