1use std::collections::BTreeMap;
6
7use osm2streets::{osm, IntersectionID, RoadID, StreetNetwork};
8use popgetter::CensusZone;
9use serde::{Deserialize, Serialize};
10
11use abstio::{CityName, MapName};
12use abstutil::{
13 deserialize_btreemap, deserialize_multimap, serialize_btreemap, serialize_multimap, MultiMap,
14 Tags,
15};
16use geom::{Distance, PolyLine, Polygon, Pt2D};
17
18pub use self::types::{Amenity, AmenityType, AreaType};
19
20mod types;
21
22#[derive(Serialize, Deserialize)]
23pub struct RawMap {
24 pub name: MapName,
25 pub streets: StreetNetwork,
26 #[serde(
27 serialize_with = "serialize_btreemap",
28 deserialize_with = "deserialize_btreemap"
29 )]
30 pub buildings: BTreeMap<osm::OsmID, RawBuilding>,
31 pub areas: Vec<RawArea>,
32 pub parking_lots: Vec<RawParkingLot>,
33 pub parking_aisles: Vec<(osm::WayID, Vec<Pt2D>)>,
34 pub transit_routes: Vec<RawTransitRoute>,
35 pub census_zones: Vec<(Polygon, CensusZone)>,
36 #[serde(
37 serialize_with = "serialize_btreemap",
38 deserialize_with = "deserialize_btreemap"
39 )]
40 pub transit_stops: BTreeMap<String, RawTransitStop>,
41 #[serde(
47 serialize_with = "serialize_multimap",
48 deserialize_with = "deserialize_multimap"
49 )]
50 pub bus_routes_on_roads: MultiMap<osm::WayID, String>,
51 #[serde(
52 serialize_with = "serialize_btreemap",
53 deserialize_with = "deserialize_btreemap"
54 )]
55 pub osm_tags: BTreeMap<osm::WayID, Tags>,
56
57 #[serde(
58 serialize_with = "serialize_btreemap",
59 deserialize_with = "deserialize_btreemap"
60 )]
61 pub extra_road_data: BTreeMap<RoadID, ExtraRoadData>,
62 #[serde(
63 serialize_with = "serialize_btreemap",
64 deserialize_with = "deserialize_btreemap"
65 )]
66 pub elevation_per_intersection: BTreeMap<IntersectionID, Distance>,
67 pub extra_pois: Vec<ExtraPOI>,
68}
69
70impl RawMap {
71 pub fn blank(name: MapName) -> RawMap {
72 RawMap {
73 name,
74 streets: StreetNetwork::blank(),
75 buildings: BTreeMap::new(),
76 areas: Vec::new(),
77 parking_lots: Vec::new(),
78 parking_aisles: Vec::new(),
79 transit_routes: Vec::new(),
80 census_zones: Vec::new(),
81 transit_stops: BTreeMap::new(),
82 bus_routes_on_roads: MultiMap::new(),
83 osm_tags: BTreeMap::new(),
84 extra_road_data: BTreeMap::new(),
85 elevation_per_intersection: BTreeMap::new(),
86 extra_pois: Vec::new(),
87 }
88 }
89
90 pub fn save(&self) {
91 abstio::write_binary(abstio::path_raw_map(&self.name), self)
92 }
93
94 pub fn get_city_name(&self) -> &CityName {
95 &self.name.city
96 }
97
98 pub fn road_to_osm_tags(&self, id: RoadID) -> Option<&Tags> {
100 let way = self.streets.roads[&id].osm_ids.get(0)?;
101 self.osm_tags.get(&way)
102 }
103}
104
105#[derive(Clone, Debug, Serialize, Deserialize)]
106pub struct RawBuilding {
107 pub polygon: Polygon,
108 pub osm_tags: Tags,
109 pub public_garage_name: Option<String>,
110 pub num_parking_spots: usize,
111 pub amenities: Vec<Amenity>,
112}
113
114#[derive(Clone, Debug, Serialize, Deserialize)]
115pub struct RawArea {
116 pub area_type: AreaType,
117 pub polygon: Polygon,
118 pub osm_tags: Tags,
119 pub osm_id: osm::OsmID,
120}
121
122#[derive(Clone, Debug, Serialize, Deserialize)]
123pub struct RawParkingLot {
124 pub osm_id: osm::OsmID,
125 pub polygon: Polygon,
126 pub osm_tags: Tags,
127}
128
129#[derive(Clone, Debug, Serialize, Deserialize)]
130pub struct RawTransitRoute {
131 pub long_name: String,
132 pub short_name: String,
133 pub gtfs_id: String,
134 pub shape: PolyLine,
136 pub stops: Vec<String>,
138 pub route_type: RawTransitType,
139 }
141
142#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
143pub enum RawTransitType {
144 Bus,
145 Train,
146}
147
148#[derive(Clone, Debug, Serialize, Deserialize)]
149pub struct RawTransitStop {
150 pub gtfs_id: String,
151 pub position: Pt2D,
153 pub name: String,
154}
155
156#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
158pub enum CrossingType {
159 Signalized,
161 Unsignalized,
163}
164
165#[derive(Clone, Debug, Serialize, Deserialize)]
167pub struct ExtraRoadData {
168 pub percent_incline: f64,
169 pub crosswalk_forward: bool,
171 pub crosswalk_backward: bool,
172 pub barrier_nodes: Vec<Pt2D>,
177 pub crossing_nodes: Vec<(Pt2D, CrossingType)>,
179}
180
181impl ExtraRoadData {
182 pub fn default() -> Self {
183 Self {
184 percent_incline: 0.0,
185 crosswalk_forward: true,
187 crosswalk_backward: true,
188 barrier_nodes: Vec::new(),
189 crossing_nodes: Vec::new(),
190 }
191 }
192}
193
194#[derive(Clone, Debug, Serialize, Deserialize)]
196pub struct ExtraPOI {
197 pub pt: Pt2D,
198 pub kind: ExtraPOIType,
199}
200
201#[derive(Clone, Debug, Serialize, Deserialize)]
202pub enum ExtraPOIType {
203 LondonUndergroundStation(String),
204 NationalRailStation(String),
205}