-
Notifications
You must be signed in to change notification settings - Fork 712
/
Copy path061_chatgpt_osmdata.R
51 lines (34 loc) · 1.28 KB
/
061_chatgpt_osmdata.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# BUSINESS SCIENCE R TIPS ----
# R-TIP 061 | ChatGPT + Open Street Maps Nominatum API ----
#
# 👉 For Weekly R-Tips, Sign Up Here:
# https://learn.business-science.io/r-tips-newsletter
#
# **** -----
# GOAL: Demonstrate how to get & map lat/long for ANY business type
# 1.0 CHATGPT + OSMDATA LESSON -----
# * CHATGPT PROMPT ----
"
Using the osmdata R library, write R code to find the locations of all pharmacies in
Pittsburgh. Then use mapview to visualize the pharmacies on a map.
"
# * FINAL RESPONSE ----
# Load required libraries
library(osmdata)
library(mapview)
# Get the bounding box for Pittsburgh
pittsburgh_bbox <- getbb("Pittsburgh, Pennsylvania, USA")
# Create an Overpass query for pharmacies in Pittsburgh
query <- opq(bbox = pittsburgh_bbox) %>%
add_osm_feature(key = "amenity", value = "pharmacy")
# Extract the data as an sf object
pharmacies_sf <- osmdata_sf(query)
# Visualize the pharmacies on a map
mapview(pharmacies_sf$osm_points, zcol = "name")
# 2.0 PREVIEW LEARNING LAB 83 ----
# - Extends this lesson
# - Demo Geospatial App I built
# 3.0 LEARNING MORE ----
# - Do you want to become the data science expert for your organization?
# - HERE'S HOW: 10 SECRETS TO BECOMING A 6-FIGURE DATA SCIENTIST
# https://learn.business-science.io/free-rtrack-masterclass