Dump the entire map to geojson

This commit is contained in:
Dustin Carlino 2020-11-10 13:02:00 -08:00
parent ef34b36d9f
commit f30e1e2fff
2 changed files with 45 additions and 0 deletions

View File

@ -94,6 +94,8 @@ are missing, etc. A summary of the commands available so far:
one feature for the intersection and a feature for all connecting roads. The one feature for the intersection and a feature for all connecting roads. The
polygon coordinates are measured in meters, with the origin centered at the polygon coordinates are measured in meters, with the origin centered at the
intersection's center. intersection's center.
- **GET /map/get-all-geometry**: Returns a huge GeoJSON object with one
feature per road and intersection in the map. The coordinate space is WGS84.
## Working with the map model ## Working with the map model

View File

@ -330,6 +330,7 @@ fn handle_command(
let i = IntersectionID(params["id"].parse::<usize>()?); let i = IntersectionID(params["id"].parse::<usize>()?);
Ok(abstutil::to_json(&export_geometry(map, i))) Ok(abstutil::to_json(&export_geometry(map, i)))
} }
"/map/get-all-geometry" => Ok(abstutil::to_json(&export_all_geometry(map))),
_ => Err("Unknown command".into()), _ => Err("Unknown command".into()),
} }
} }
@ -481,3 +482,45 @@ fn export_geometry(map: &Map, i: IntersectionID) -> geojson::GeoJson {
foreign_members: None, foreign_members: None,
}) })
} }
fn export_all_geometry(map: &Map) -> geojson::GeoJson {
use geojson::{Feature, FeatureCollection, GeoJson};
let mut features = Vec::new();
let gps_bounds = Some(map.get_gps_bounds());
for i in map.all_intersections() {
let mut props = serde_json::Map::new();
props.insert("type".to_string(), "intersection".into());
props.insert("id".to_string(), i.orig_id.to_string().into());
features.push(Feature {
bbox: None,
geometry: Some(i.polygon.clone().into_ring().to_geojson(gps_bounds)),
id: None,
properties: Some(props),
foreign_members: None,
});
}
for r in map.all_roads() {
let mut props = serde_json::Map::new();
props.insert("type".to_string(), "road".into());
props.insert("id".to_string(), r.orig_id.osm_way_id.to_string().into());
features.push(Feature {
bbox: None,
geometry: Some(
r.center_pts
.to_thick_ring(2.0 * r.get_half_width(map))
.to_geojson(gps_bounds),
),
id: None,
properties: Some(props),
foreign_members: None,
});
}
GeoJson::from(FeatureCollection {
bbox: None,
features,
foreign_members: None,
})
}