6
6
#
7
7
# **** -----
8
8
9
- # GOAL: Demonstrate how to get lat/long and map for ANY
9
+ # GOAL: Demonstrate how to get & map lat/long for ANY business type
10
10
11
11
# 1.0 CHATGPT + OSMDATA LESSON -----
12
12
@@ -18,20 +18,24 @@ Pittsburgh. Then use mapview to visualize the pharmacies on a map.
18
18
19
19
# * FINAL RESPONSE ----
20
20
21
- # load necessary packages
21
+ # Load required libraries
22
22
library(osmdata )
23
23
library(mapview )
24
24
25
- # define the bounding box for Pittsburgh
26
- bbox <- getbb(" Pittsburgh" )
25
+ # Get the bounding box for Pittsburgh
26
+ pittsburgh_bbox <- getbb(" Pittsburgh, Pennsylvania, USA" )
27
+
28
+ # Create an Overpass query for pharmacies in Pittsburgh
29
+ query <- opq(bbox = pittsburgh_bbox ) %> %
30
+ add_osm_feature(key = " amenity" , value = " pharmacy" )
31
+
32
+ # Extract the data as an sf object
33
+ pharmacies_sf <- osmdata_sf(query )
34
+
35
+ # Visualize the pharmacies on a map
36
+ mapview(pharmacies_sf $ osm_points , zcol = " name" )
27
37
28
- # search for pharmacies within the bounding box
29
- pharmacies <- opq(bbox ) %> %
30
- add_osm_feature(key = " amenity" , value = " pharmacy" ) %> %
31
- osmdata_sp()
32
38
33
- # visualize the pharmacies on a map
34
- mapview(pharmacies $ osm_points )
35
39
36
40
37
41
# 2.0 PREVIEW LEARNING LAB 83 ----
0 commit comments