mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +03:00
starting a new crate to import extra population data
This commit is contained in:
parent
0103c56b69
commit
3663c19cdc
@ -15,6 +15,7 @@ members = [
|
||||
"kml",
|
||||
"map_model",
|
||||
"playground_gui",
|
||||
"popdat",
|
||||
"precompute",
|
||||
"sim",
|
||||
"synthetic",
|
||||
|
@ -140,6 +140,8 @@ Constructing the map:
|
||||
intermediate map format into the final format
|
||||
- `precompute`: small tool to run the second stage of map conversion and write
|
||||
final output
|
||||
- `popdat`: importing extra census-based data specific to Seattle, optional
|
||||
right now
|
||||
|
||||
Traffic simulation:
|
||||
|
||||
|
18
import.sh
18
import.sh
@ -78,6 +78,24 @@ if [ ! -f data/shapes/blockface ]; then
|
||||
cd ..
|
||||
fi
|
||||
|
||||
if [ ! -f data/input/household_vehicles.kml ]; then
|
||||
# From https://gis-kingcounty.opendata.arcgis.com/datasets/acs-household-size-by-vehicles-available-acs-b08201-householdvehicles
|
||||
get_if_needed https://opendata.arcgis.com/datasets/7842d815523c4f1b9564e0301e2eafa4_2372.kml data/input/household_vehicles.kml;
|
||||
get_if_needed https://www.arcgis.com/sharing/rest/content/items/7842d815523c4f1b9564e0301e2eafa4/info/metadata/metadata.xml data/input/household_vehicles.xml;
|
||||
fi
|
||||
|
||||
if [ ! -f data/input/commute_time.kml ]; then
|
||||
# From https://gis-kingcounty.opendata.arcgis.com/datasets/acs-travel-time-to-work-acs-b08303-traveltime
|
||||
get_if_needed https://opendata.arcgis.com/datasets/9b5fd85861a04c5ab8b7407c7b58da7c_2375.kml data/input/commute_time.kml;
|
||||
get_if_needed https://www.arcgis.com/sharing/rest/content/items/9b5fd85861a04c5ab8b7407c7b58da7c/info/metadata/metadata.xml data/input/commute_time.xml;
|
||||
fi
|
||||
|
||||
if [ ! -f data/input/commute_mode.kml ]; then
|
||||
# From https://gis-kingcounty.opendata.arcgis.com/datasets/acs-means-of-transportation-to-work-acs-b08301-transportation
|
||||
get_if_needed https://opendata.arcgis.com/datasets/1da9717ca5ff4505826aba40a7ac0a58_2374.kml data/input/commute_mode.kml;
|
||||
get_if_needed https://www.arcgis.com/sharing/rest/content/items/1da9717ca5ff4505826aba40a7ac0a58/info/metadata/metadata.xml data/input/commute_mode.xml;
|
||||
fi
|
||||
|
||||
cd convert_osm
|
||||
for poly in `ls ../data/polygons/`; do
|
||||
name=`basename -s .poly $poly`;
|
||||
|
12
popdat/Cargo.toml
Normal file
12
popdat/Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "popdat"
|
||||
version = "0.1.0"
|
||||
authors = ["Dustin Carlino <dabreegster@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
abstutil = { path = "../abstutil" }
|
||||
geom = { path = "../geom" }
|
||||
kml = { path = "../kml" }
|
||||
serde = "1.0.89"
|
||||
serde_derive = "1.0.89"
|
63
popdat/src/lib.rs
Normal file
63
popdat/src/lib.rs
Normal file
@ -0,0 +1,63 @@
|
||||
use abstutil::Timer;
|
||||
use geom::{GPSBounds, LonLat};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct PopDat {
|
||||
// Keyed by census tract
|
||||
pub household_vehicles: BTreeMap<String, TractData>,
|
||||
pub commute_time: BTreeMap<String, TractData>,
|
||||
pub commute_mode: BTreeMap<String, TractData>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct TractData {
|
||||
pub pts: Vec<LonLat>,
|
||||
// TODO measurement and error grouped together, at least, ±
|
||||
pub raw: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
impl PopDat {
|
||||
pub fn import_all(timer: &mut Timer) -> PopDat {
|
||||
// Generally large slice of Seattle
|
||||
let mut bounds = GPSBounds::new();
|
||||
bounds.update(LonLat::new(-122.4416, 47.5793));
|
||||
bounds.update(LonLat::new(-122.2421, 47.7155));
|
||||
|
||||
PopDat {
|
||||
household_vehicles: TractData::import(
|
||||
"../data/input/household_vehicles.kml",
|
||||
&bounds,
|
||||
timer,
|
||||
),
|
||||
commute_time: TractData::import("../data/input/commute_time.kml", &bounds, timer),
|
||||
commute_mode: TractData::import("../data/input/commute_mode.kml", &bounds, timer),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TractData {
|
||||
fn import(path: &str, bounds: &GPSBounds, timer: &mut Timer) -> BTreeMap<String, TractData> {
|
||||
let mut map = BTreeMap::new();
|
||||
|
||||
for mut shape in kml::load(path, bounds, timer)
|
||||
.expect(&format!("couldn't load {}", path))
|
||||
.shapes
|
||||
{
|
||||
let name = shape.attributes.remove("TRACT_LBL").unwrap();
|
||||
// Remove useless stuff
|
||||
shape.attributes.remove("Internal feature number.");
|
||||
shape.attributes.remove("GEO_ID_TRT");
|
||||
map.insert(
|
||||
name,
|
||||
TractData {
|
||||
pts: shape.points,
|
||||
raw: shape.attributes,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
map
|
||||
}
|
||||
}
|
4
popdat/src/main.rs
Normal file
4
popdat/src/main.rs
Normal file
@ -0,0 +1,4 @@
|
||||
fn main() {
|
||||
let popdat = popdat::PopDat::import_all(&mut abstutil::Timer::new("importing popdat"));
|
||||
abstutil::write_binary("../data/shapes/popdat", &popdat).unwrap();
|
||||
}
|
Loading…
Reference in New Issue
Block a user