raw_map/
types.rs

1use serde::{Deserialize, Serialize};
2use strum::IntoEnumIterator;
3use strum_macros::{Display, EnumIter, EnumString};
4
5use abstutil::Tags;
6use osm2streets::NamePerLanguage;
7
8/// A business located inside a building.
9#[derive(Serialize, Deserialize, Debug, Clone)]
10pub struct Amenity {
11    pub names: NamePerLanguage,
12    /// This is the specific amenity listed in OSM, not the more general `AmenityType` category.
13    pub amenity_type: String,
14    /// Depending on options while importing, these might be empty, to save file space.
15    pub osm_tags: Tags,
16}
17
18/// Businesses are categorized into one of these types.
19#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, EnumString, Display, EnumIter, Debug)]
20pub enum AmenityType {
21    Bank,
22    Bar,
23    Beauty,
24    Bike,
25    Cafe,
26    CarRepair,
27    CarShare,
28    Childcare,
29    ConvenienceStore,
30    Culture,
31    Exercise,
32    FastFood,
33    Food,
34    GreenSpace,
35    Hotel,
36    Laundry,
37    Library,
38    Medical,
39    Pet,
40    Playground,
41    Pool,
42    PostOffice,
43    Religious,
44    School,
45    Shopping,
46    Supermarket,
47    Tourism,
48    University,
49}
50
51impl AmenityType {
52    fn types(self) -> Vec<&'static str> {
53        match self {
54            AmenityType::Bank => vec!["bank"],
55            AmenityType::Bar => vec!["bar", "pub", "nightclub", "biergarten"],
56            AmenityType::Beauty => vec!["hairdresser", "beauty", "chemist", "cosmetics"],
57            AmenityType::Bike => vec!["bicycle"],
58            AmenityType::Cafe => vec!["cafe", "pastry", "coffee", "tea", "bakery"],
59            AmenityType::CarRepair => vec!["car_repair"],
60            AmenityType::CarShare => vec!["car_sharing"],
61            AmenityType::Childcare => vec!["childcare", "kindergarten"],
62            AmenityType::ConvenienceStore => vec!["convenience"],
63            AmenityType::Culture => vec!["arts_centre", "art", "cinema", "theatre"],
64            AmenityType::Exercise => vec!["fitness_centre", "sports_centre", "track", "pitch"],
65            AmenityType::FastFood => vec!["fast_food", "food_court"],
66            AmenityType::Food => vec![
67                "restaurant",
68                "farm",
69                "ice_cream",
70                "seafood",
71                "cheese",
72                "chocolate",
73                "deli",
74                "butcher",
75                "confectionery",
76                "beverages",
77                "alcohol",
78            ],
79            AmenityType::GreenSpace => vec!["park", "garden", "nature_reserve"],
80            AmenityType::Hotel => vec!["hotel", "hostel", "guest_house", "motel"],
81            AmenityType::Laundry => vec!["dry_cleaning", "laundry", "tailor"],
82            AmenityType::Library => vec!["library"],
83            AmenityType::Medical => vec![
84                "clinic", "dentist", "hospital", "pharmacy", "doctors", "optician",
85            ],
86            AmenityType::Pet => vec!["veterinary", "pet", "animal_boarding", "pet_grooming"],
87            AmenityType::Playground => vec!["playground"],
88            AmenityType::Pool => vec!["swimming_pool"],
89            AmenityType::PostOffice => vec!["post_office"],
90            AmenityType::Religious => vec!["place_of_worship", "religion"],
91            AmenityType::School => vec!["school"],
92            AmenityType::Shopping => vec![
93                "wholesale",
94                "bag",
95                "marketplace",
96                "second_hand",
97                "charity",
98                "clothes",
99                "lottery",
100                "shoes",
101                "mall",
102                "department_store",
103                "car",
104                "tailor",
105                "nutrition_supplements",
106                "watches",
107                "craft",
108                "fabric",
109                "kiosk",
110                "antiques",
111                "shoemaker",
112                "hardware",
113                "houseware",
114                "mobile_phone",
115                "photo",
116                "toys",
117                "bed",
118                "florist",
119                "electronics",
120                "fishing",
121                "garden_centre",
122                "frame",
123                "watchmaker",
124                "boutique",
125                "mobile_phone",
126                "party",
127                "car_parts",
128                "video",
129                "video_games",
130                "musical_instrument",
131                "music",
132                "baby_goods",
133                "doityourself",
134                "jewelry",
135                "variety_store",
136                "gift",
137                "carpet",
138                "perfumery",
139                "curtain",
140                "appliance",
141                "furniture",
142                "lighting",
143                "sewing",
144                "books",
145                "sports",
146                "travel_agency",
147                "interior_decoration",
148                "stationery",
149                "computer",
150                "tyres",
151                "newsagent",
152                "general",
153            ],
154            AmenityType::Supermarket => vec!["supermarket", "greengrocer"],
155            AmenityType::Tourism => vec![
156                "gallery",
157                "museum",
158                "zoo",
159                "attraction",
160                "theme_park",
161                "aquarium",
162            ],
163            AmenityType::University => vec!["college", "university"],
164        }
165    }
166
167    /// All types of amenities, in alphabetical order.
168    pub fn all() -> Vec<AmenityType> {
169        AmenityType::iter().collect()
170    }
171
172    /// Categorize an OSM amenity tag.
173    pub fn categorize(a: &str) -> Option<AmenityType> {
174        for at in AmenityType::all() {
175            if at.types().contains(&a) {
176                return Some(at);
177            }
178        }
179        None
180    }
181}
182
183#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
184pub enum AreaType {
185    Park,
186    Water,
187    Island,
188    /// Not from OSM. A user-specified area to focus on.
189    StudyArea,
190}