-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
172 lines (138 loc) · 5.11 KB
/
README.Rmd
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
message = FALSE,
warning = FALSE,
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# overtureR <a href="https://arthurgailes.github.io/overtureR/"><img src="man/figures/logo.png" align="right" height="139" alt="overtureR website" /></a>
<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-stable-green.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![CRAN status](https://www.r-pkg.org/badges/version/overtureR)](https://CRAN.R-project.org/package=overtureR)
[![R-CMD-check](https://github.com/arthurgailes/overtureR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/arthurgailes/overtureR/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/arthurgailes/overtureR/branch/master/graph/badge.svg)](https://app.codecov.io/gh/arthurgailes/overtureR?branch=master)
<!-- badges: end -->
## Installation
```{r eval=FALSE}
install.packages("overtureR")
# devtools::install_github("arthurgailes/overtureR")
```
## Key Features
* Query global [Overture Maps](https://overturemaps.org/) data directly in R
* Conduct analysis on massive dataset without loading into memory using [dbplyr's](https://dbplyr.tidyverse.org/) lazy evaluation
* Seamless `dplyr` and `sf` integration
* Merge with your local `sf` data within `duckdb` or with `sf`
* Local downloading for offline use and performance
## Usage
Replicating `duckdb` examples from the [Overture docs](https://docs.overturemaps.org/getting-data/duckdb/)
```{r ggtheme, include=FALSE}
library(ggplot2)
map_theme <- theme_minimal() +
theme(
plot.title = element_text(face = "bold", size = 16, hjust = 0.5),
plot.subtitle = element_text(size = 12, hjust = 0.5, margin = margin(b = 20)),
plot.caption = element_text(size = 8, margin = margin(t = 10)),
legend.position = "none",
legend.title = element_text(face = "bold"),
legend.text = element_blank(),
panel.grid = element_blank(),
axis.text = element_blank(),
axis.title = element_blank(),
plot.background = element_rect(fill = "grey90", color = NA),
panel.background = element_rect(fill = "grey90", color = NA),
legend.background = element_rect(fill = "grey90", color = NA),
panel.border = element_blank()
)
theme_set(map_theme)
```
```{r counties, warning=FALSE}
library(overtureR)
library(dplyr)
library(ggplot2)
counties <- open_curtain("division_area") |>
# in R, filtering on variables must come before removing them via select
filter(subtype == "county" & country == "US" & region == "US-PA") |>
transmute(
id,
division_id,
primary = names$primary,
geometry
) |>
collect()
# Plot the results
ggplot(counties) +
geom_sf(aes(fill = as.numeric(sf::st_area(geometry))), color = "white", size = 0.2) +
viridis::scale_fill_viridis(option = "plasma", guide = FALSE) +
labs(
title = "Pennsylvania Counties by Area",
caption = "Data: Overture Maps"
)
```
```{r mountains}
library(overtureR)
library(dplyr)
# lazily load the full `mountains` dataset
mountains <- open_curtain(type = "*", theme = "places") |>
transmute(
id,
primary_name = names$primary,
x = bbox$xmin,
y = bbox$ymin,
main_category = categories$primary,
primary_source = sources[[1]]$dataset,
confidence,
geometry # currently no duckdb spatial implementation
) |>
filter(main_category == "mountain" & confidence > .90)
head(mountains)
```
## Downloading data locally
The record_overture function allows you to download Overture Maps data to a local directory, maintaining the same partition structure as in S3. This is useful for offline analysis or when you need to work with the data repeatedly. Here's an example:
```{r record}
library(overtureR)
library(ggplot2)
library(dplyr)
library(rayshader)
# Define a bounding box for New York City
broadway <- c(xmin = -73.9901, ymin = 40.755488, xmax = -73.98, ymax = 40.76206)
# Download building data for NYC to a local directory
local_buildings <- open_curtain("building", broadway) |>
record_overture(output_dir = tempdir(), overwrite = TRUE)
# The downloaded data is returned as a `dbplyr` object, same as the original (but faster!)
broadway_buildings <- local_buildings |>
filter(!is.na(height)) |>
mutate(height = round(height)) |>
collect()
p <- ggplot(broadway_buildings) +
geom_sf(aes(fill = height)) +
scale_fill_distiller(palette = "Oranges", direction = 1) +
# guides(fill = FALSE) +
labs(title = "Buildings on Broadway", caption = "Data: Overture Maps", fill = "")
# Convert to 3D and render
plot_gg(
p,
multicore = TRUE,
width = 6, height = 5, scale = 250,
windowsize = c(1032, 860),
zoom = 0.55,
phi = 40, theta = 0,
solid = FALSE,
offset_edges = TRUE,
sunangle = 75
)
render_snapshot(clear=TRUE)
```
## Roadmap
- Read pmtiles
- Add partition, chunking to record_overture
- Add beta/alpha datasets
- Add mapping vignette
- Add performance vignette
- Download overture files via open_curtain