Last active
March 5, 2021 02:08
-
-
Save MilesMcBain/942e38dc545fbf683885f29d8d2896cd to your computer and use it in GitHub Desktop.
ra30 res 9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
system.time({ | |
library(conflicted) | |
library(qfes) | |
library(tidyverse) | |
library(rmapshaper) | |
library(sf) | |
library(h3jsr) | |
library(furrr) | |
library(future) | |
library(rdeck) | |
library(viridisLite) | |
conflict_prefer("filter", "dplyr") | |
remoteness_areas <- | |
get_remoteness_areas(list(ste_name16 = "Queensland")) %>% | |
filter(!sf::st_is_empty(geometry)) %>% | |
st_cast("POLYGON") %>% | |
filter(ra_code16 == 30) | |
n_cores <- 7 | |
future::plan(multisession, workers = n_cores) | |
poly_splits <- split(remoteness_areas, seq(n_cores)) | |
## A very slow way of getting a starting set of parents for QLD. | |
intersectors <- future_map(poly_splits, function(polygons) { | |
big_hexes <- | |
h3_fill_aus(polygons, resolution = 3) | |
big_hexes | |
}) | |
## All descendants at res 8 from the res 3 coverage set | |
children <- | |
unlist(intersectors) %>% | |
get_children(res = 9) %>% | |
unlist() %>% | |
unique() %>% | |
split(seq(n_cores)) | |
remoteness_areas_3112 <- | |
remoteness_areas %>% | |
st_transform(3112) | |
## Res 8 candidate hex ids are in seven batches. | |
## Materialise the polys in separate threads and do joins | |
intersection_result <- | |
future_map(children, function(h3_ids) { | |
child_sf <- | |
st_sf(h3_id = h3_ids, polgyon = h3_to_polygon(h3_ids)) %>% | |
st_transform(3112) | |
st_intersection(child_sf, remoteness_areas_3112) | |
}) | |
result_long <- | |
bind_rows(intersection_result) | |
}) | |
str(intersection_result) | |
map_hexes <- | |
result_long %>% | |
st_drop_geometry() %>% | |
as_tibble() %>% | |
drop_na() | |
rdeck( | |
initial_bounds = st_bbox(remoteness_areas) | |
) %>% | |
add_h3_hexagon_layer( | |
data = result_long, | |
get_hexagon = h3_id, | |
get_fill_color = scale_color_category( | |
col = ra_name16, | |
palette = viridis(1) | |
) | |
) | |
db_hexes <- | |
qfesdata::qfes_query( | |
database = "GIS", | |
query = | |
" | |
SELECT | |
H3Index, RA_CODE16 | |
FROM | |
H3 | |
JOIN H3_REMOTENESSAREA ON H3_REMOTENESSAREA.H3Id = H3.Id | |
WHERE | |
H3.Resolution = 9 | |
AND H3_REMOTENESSAREA.RA_CODE16 = 30 | |
" | |
) | |
setdiff(db_hexes$H3Index, result_long$h3_id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment