Spaces:
Sleeping
Sleeping
use subset
Browse files
app.R
CHANGED
@@ -119,7 +119,28 @@ duckdb_secrets(Sys.getenv("MINIO_KEY"),
|
|
119 |
Sys.getenv("MINIO_SECRET"),
|
120 |
"minio.carlboettiger.info")
|
121 |
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
# Define the server
|
125 |
server <- function(input, output, session) {
|
@@ -143,8 +164,12 @@ observeEvent(input$get_features, {
|
|
143 |
print(bounds)
|
144 |
})
|
145 |
|
146 |
-
|
147 |
attach(as.list(bounds))
|
|
|
|
|
|
|
|
|
|
|
148 |
gbif |>
|
149 |
dplyr::filter(between(decimallatitude, ymin, ymax),
|
150 |
between(decimallongitude, xmin, xmax)) |>
|
|
|
119 |
Sys.getenv("MINIO_SECRET"),
|
120 |
"minio.carlboettiger.info")
|
121 |
|
122 |
+
|
123 |
+
get_h3index <- function(shape, zoom = 0L, precision = 6L) {
|
124 |
+
|
125 |
+
tmp <- tempfile(fileext = ".fgb")
|
126 |
+
shape |> st_transform(4326) |> write_sf(tmp, append = FALSE)
|
127 |
+
zoom <- as.integer(zoom)
|
128 |
+
|
129 |
+
# consider auto-retry at higher precision if subset is empty.
|
130 |
+
precision <- as.integer(precision)
|
131 |
+
subset <- open_dataset(tmp) |>
|
132 |
+
mutate(poly = array_extract(unnest(st_dump(geom)),"geom"),
|
133 |
+
hexid = h3_polygon_wkt_to_cells(poly,{precision}),
|
134 |
+
hexid = unnest(hexid)
|
135 |
+
) |>
|
136 |
+
mutate(h0 = h3_h3_to_string( h3_cell_to_parent(hexid, {zoom})),
|
137 |
+
hexid = h3_h3_to_string (hexid) ) |>
|
138 |
+
select(h0) |>
|
139 |
+
distinct() |>
|
140 |
+
pull(h0)
|
141 |
+
|
142 |
+
toupper(subset)
|
143 |
+
}
|
144 |
|
145 |
# Define the server
|
146 |
server <- function(input, output, session) {
|
|
|
164 |
print(bounds)
|
165 |
})
|
166 |
|
|
|
167 |
attach(as.list(bounds))
|
168 |
+
|
169 |
+
subset <- get_h3index(drawn_features)
|
170 |
+
urls <- paste0("https://minio.carlboettiger.info/public-gbif/hex/h0=", subset, "/part0.parquet")
|
171 |
+
gbif <- open_dataset(urls, tblname = "gbif")
|
172 |
+
|
173 |
gbif |>
|
174 |
dplyr::filter(between(decimallatitude, ymin, ymax),
|
175 |
between(decimallongitude, xmin, xmax)) |>
|