Import Seattle collision data and convert to the common format. #87

This commit is contained in:
Dustin Carlino 2020-11-06 13:16:50 -08:00
parent b0bdbf6c1f
commit 104c987edd
4 changed files with 86 additions and 0 deletions

View File

@ -130,3 +130,4 @@ modify the mode for some people (change 50% of all driving trips between 7 and
- <https://github.com/BayAreaMetro/travel-model-one>
- <https://github.com/RSGInc/DaySim>
- <https://github.com/arup-group/pam>
- <https://spatial-microsim-book.robinlovelace.net/smsimr.html>

View File

@ -78,3 +78,63 @@ pub fn import_stats19(input: ExtraShapes, source_url: &str) -> CollisionDataset
}
data
}
/// Import data from Seattle GeoData
/// (https://data-seattlecitygis.opendata.arcgis.com/datasets/5b5c745e0f1f48e7a53acec63a0022ab_0).
/// Any parsing errors will skip the row and log a warning.
pub fn import_seattle(input: ExtraShapes, source_url: &str) -> CollisionDataset {
let mut data = CollisionDataset {
source_url: source_url.to_string(),
collisions: Vec::new(),
};
for shape in input.shapes {
if shape.points.len() != 1 {
warn!("One row had >1 point: {:?}", shape);
continue;
}
let time = match parse_incdttm(&shape.attributes["INCDTTM"]) {
Some(time) => time,
None => {
warn!("Couldn't parse time {}", shape.attributes["INCDTTM"]);
continue;
}
};
let severity = match shape
.attributes
.get("SEVERITYCODE")
.cloned()
.unwrap_or_else(String::new)
.as_ref()
{
"1" | "0" => Severity::Slight,
"2b" | "2" => Severity::Serious,
"3" => Severity::Fatal,
x => {
warn!("Unknown severity {}", x);
continue;
}
};
data.collisions.push(Collision {
location: shape.points[0],
time,
severity,
});
}
data
}
// INCDTTM is something like "11/12/2019 7:30:00 AM"
fn parse_incdttm(x: &str) -> Option<Duration> {
let parts = x.split(" ").collect::<Vec<_>>();
if parts.len() != 3 {
return None;
}
let time = Duration::parse(parts[1]).ok()?;
if parts[2] == "AM" {
Some(time)
} else if parts[2] == "PM" {
Some(time + Duration::hours(12))
} else {
None
}
}

View File

@ -128,6 +128,14 @@
"checksum": "350bd9e59bf2af4e885a7c0741e6ee6b",
"size_bytes": 102846513
},
"data/input/seattle/collisions.bin": {
"checksum": "5c403fc190bc43e028a34d6d54a5d6bf",
"size_bytes": 4457539
},
"data/input/seattle/collisions.kml": {
"checksum": "16e26b4a07d2918780e09c95202ba9ac",
"size_bytes": 433758033
},
"data/input/seattle/footways.bin": {
"checksum": "09c6aca2ad37d007c6bd40b91886ed95",
"size_bytes": 5536891

View File

@ -54,6 +54,23 @@ fn input(config: &ImporterConfiguration, timer: &mut abstutil::Timer) {
"input/seattle/google_transit/",
"http://metro.kingcounty.gov/gtfs/google_transit.zip",
);
// From
// https://data-seattlecitygis.opendata.arcgis.com/datasets/5b5c745e0f1f48e7a53acec63a0022ab_0
download(
config,
"input/seattle/collisions.kml",
"https://opendata.arcgis.com/datasets/5b5c745e0f1f48e7a53acec63a0022ab_0.kml",
);
// This is a little expensive, so delete data/input/seattle/collisions.bin to regenerate this.
if !abstutil::file_exists("data/input/seattle/collisions.bin") {
let shapes = kml::load("data/input/seattle/collisions.kml", &bounds, true, timer).unwrap();
let collisions = collisions::import_seattle(
shapes,
"https://data-seattlecitygis.opendata.arcgis.com/datasets/5b5c745e0f1f48e7a53acec63a0022ab_0");
abstutil::write_binary("data/input/seattle/collisions.bin".to_string(), &collisions);
}
}
pub fn osm_to_raw(name: &str, timer: &mut abstutil::Timer, config: &ImporterConfiguration) {