mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 23:43:25 +03:00
use cbor for maps
This commit is contained in:
parent
43536743a8
commit
82bac55275
@ -5,4 +5,5 @@ authors = ["Dustin Carlino <dabreegster@gmail.com>"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
|
serde_cbor = "0.8.2"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
extern crate serde;
|
extern crate serde;
|
||||||
|
extern crate serde_cbor;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{Error, Read, Write};
|
use std::io::{Error, ErrorKind, Read, Write};
|
||||||
|
|
||||||
pub fn write_json<T: Serialize>(path: &str, obj: &T) -> Result<(), Error> {
|
pub fn write_json<T: Serialize>(path: &str, obj: &T) -> Result<(), Error> {
|
||||||
let mut file = File::create(path)?;
|
let mut file = File::create(path)?;
|
||||||
@ -19,3 +20,14 @@ pub fn read_json<T: DeserializeOwned>(path: &str) -> Result<T, Error> {
|
|||||||
let obj: T = serde_json::from_str(&contents).unwrap();
|
let obj: T = serde_json::from_str(&contents).unwrap();
|
||||||
Ok(obj)
|
Ok(obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn write_binary<T: Serialize>(path: &str, obj: &T) -> Result<(), Error> {
|
||||||
|
let mut file = File::create(path)?;
|
||||||
|
serde_cbor::to_writer(&mut file, obj).map_err(|err| Error::new(ErrorKind::Other, err))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_binary<T: DeserializeOwned>(path: &str) -> Result<T, Error> {
|
||||||
|
let file = File::open(path)?;
|
||||||
|
let obj: T = serde_cbor::from_reader(file).map_err(|err| Error::new(ErrorKind::Other, err))?;
|
||||||
|
Ok(obj)
|
||||||
|
}
|
||||||
|
@ -50,7 +50,7 @@ fn main() {
|
|||||||
let (map, bounds) = osm::osm_to_raw_roads(&flags.osm);
|
let (map, bounds) = osm::osm_to_raw_roads(&flags.osm);
|
||||||
let mut map = osm::split_up_roads(&map, &elevation);
|
let mut map = osm::split_up_roads(&map, &elevation);
|
||||||
let parcels_map: raw_data::Map =
|
let parcels_map: raw_data::Map =
|
||||||
abstutil::read_json(&flags.parcels).expect("loading parcels failed");
|
abstutil::read_binary(&flags.parcels).expect("loading parcels failed");
|
||||||
println!(
|
println!(
|
||||||
"Finding matching parcels from {} candidates",
|
"Finding matching parcels from {} candidates",
|
||||||
parcels_map.parcels.len()
|
parcels_map.parcels.len()
|
||||||
@ -94,5 +94,5 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
println!("writing to {}", flags.output);
|
println!("writing to {}", flags.output);
|
||||||
abstutil::write_json(&flags.output, &map).expect("serializing map failed");
|
abstutil::write_binary(&flags.output, &map).expect("serializing map failed");
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,6 @@ wait slow down even more -- before any of this change, lanes on adjacent roads s
|
|||||||
- debug impossibly long derived roads, like the horizontal E McGraw. try to detect by comparing length of original points with length of derived center pts.
|
- debug impossibly long derived roads, like the horizontal E McGraw. try to detect by comparing length of original points with length of derived center pts.
|
||||||
- big maps start centered over emptiness
|
- big maps start centered over emptiness
|
||||||
- some bldg paths are quite long.
|
- some bldg paths are quite long.
|
||||||
- more compact output
|
|
||||||
- draw sidewalk and parking markings
|
- draw sidewalk and parking markings
|
||||||
- make final Map serializable too
|
- make final Map serializable too
|
||||||
- useful to precompute sidewalk paths
|
- useful to precompute sidewalk paths
|
||||||
|
@ -31,5 +31,5 @@ fn main() {
|
|||||||
|
|
||||||
let out_path = &args[2];
|
let out_path = &args[2];
|
||||||
println!("writing to {}", out_path);
|
println!("writing to {}", out_path);
|
||||||
abstutil::write_json(out_path, &map).expect("serializing map failed");
|
abstutil::write_binary(out_path, &map).expect("serializing map failed");
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ pub struct Map {
|
|||||||
|
|
||||||
impl Map {
|
impl Map {
|
||||||
pub fn new(path: &str) -> Result<Map, Error> {
|
pub fn new(path: &str) -> Result<Map, Error> {
|
||||||
let data: raw_data::Map = abstutil::read_json(path)?;
|
let data: raw_data::Map = abstutil::read_binary(path)?;
|
||||||
|
|
||||||
let bounds = data.get_gps_bounds();
|
let bounds = data.get_gps_bounds();
|
||||||
let mut m = Map {
|
let mut m = Map {
|
||||||
|
Loading…
Reference in New Issue
Block a user