diff --git a/mapping_draft-hpc_optimised_wilderness.Rmd b/mapping_draft-hpc_optimised_wilderness.Rmd index 9286f2f..4cd32c3 100644 --- a/mapping_draft-hpc_optimised_wilderness.Rmd +++ b/mapping_draft-hpc_optimised_wilderness.Rmd @@ -493,6 +493,7 @@ scenicareas_buf500 <- st_buffer(scenicareas_simplified, dist = 500) # plot(lnd[ sel, ], col = "turquoise", add = TRUE) # add selected zones to map # from https://gotellilab.github.io/Bio381/StudentPresentations/SpatialDataTutorial.html +# TODO: integrate pre-calc here into calculations further down which are still recalculating these figures ecs_sf_sssi <- st_within(ecs_sf, sssi_simplified) ecs_sf_sssi50m <- st_within(ecs_sf, sssi_buf50) ecs_sf_sssi500m <- st_within(ecs_sf, sssi_buf500) @@ -514,6 +515,8 @@ ecs_sf_scenicareas500m <- st_within(ecs_sf, scenicareas_buf500) ecs_sf_scenicareasbeyond500m <- !(st_within(ecs_sf, scenicareas_buf500)) # TODO: implement more efficient code using do.call() function or sapply() as here https://stackoverflow.com/questions/3642535/creating-an-r-dataframe-row-by-row +# TODO: implement parallel computing to distribute execution of loopable calculations below +# See: https://nceas.github.io/oss-lessons/parallel-computing-in-r/parallel-computing-in-r.html # Generate dataframe based on SSSI buffers @@ -581,23 +584,30 @@ permaculture_wildland_row <- c(sum(apply(st_within(permaculture_sf, wildland_sim wildland_counts <- rbind(wildland_counts, permaculture_wildland_row) grocery_wildland_row <- c(sum(apply(st_within(poi_grocery_sf, wildland_simplified, sparse=FALSE), 1, any)), sum(apply(st_within(poi_grocery_sf, wildland_buf50, sparse=FALSE), 1, any)), sum(apply(st_within(poi_grocery_sf, wildland_buf500, sparse=FALSE), 1, any))) +wildland_counts <- rbind(wildland_counts, grocery_wildland_row) pubs_wildland_row <- c(sum(apply(st_within(poi_pubs_sf, wildland_simplified, sparse=FALSE), 1, any)), sum(apply(st_within(poi_pubs_sf, wildland_buf50, sparse=FALSE), 1, any)), sum(apply(st_within(poi_pubs_sf, wildland_buf500, sparse=FALSE), 1, any))) +wildland_counts <- rbind(wildland_counts, pubs_wildland_row) colnames(wildland_counts) <- c("Within Wildland Areas", "...50m", "...500m") # Generate dataframe from rows based on percentages of totals -ecs_wildland_row_pct <- ecs_wildland_row/length(ecs_sf) +ecs_wildland_row_pct <- ecs_wildland_row/length(ecs) pow_wildland_row_pct <- pow_wildland_row/length(pow_pointX) dtas_wildland_row_pct <- dtas_wildland_row/length(dtas) transition_wildland_row_pct <- transition_wildland_row/length(transition) permaculture_wildland_row_pct <- permaculture_wildland_row/length(permaculture) +grocery_wildland_row_pct <- grocery_wildland_row/length(poi_grocery) +pubs_wildland_row_pct <- pubs_wildland_row/length(poi_pubs) wildland_counts_pct <- rbind(ecs_wildland_row_pct, pow_wildland_row_pct) wildland_counts_pct <- rbind(wildland_counts_pct, dtas_wildland_row_pct) wildland_counts_pct <- rbind(wildland_counts_pct, transition_wildland_row_pct) wildland_counts_pct <- rbind(wildland_counts_pct, permaculture_wildland_row_pct) +wildland_counts_pct <- rbind(wildland_counts_pct, grocery_wildland_row_pct) +wildland_counts_pct <- rbind(wildland_counts_pct, pubs_wildland_row_pct) + colnames(wildland_counts_pct) <- c("% Within wildlands", "% within 50m", "% within 500m") # Merge into larger dataframe @@ -620,22 +630,30 @@ permaculture_forestinv_row <- c(sum(apply(st_within(permaculture_sf, forestinv_s forestinv_counts <- rbind(forestinv_counts, permaculture_forestinv_row) grocery_forestinv_row <- c(sum(apply(st_within(poi_grocery_sf, forestinv_simplified, sparse=FALSE), 1, any)), sum(apply(st_within(poi_grocery_sf, forestinv_buf50, sparse=FALSE), 1, any)), sum(apply(st_within(poi_grocery_sf, forestinv_buf500, sparse=FALSE), 1, any))) +forestinv_counts <- rbind(forestinv_counts, grocery_forestinv_row) pubs_forestinv_row <- c(sum(apply(st_within(poi_pubs_sf, forestinv_simplified, sparse=FALSE), 1, any)), sum(apply(st_within(poi_pubs_sf, forestinv_buf50, sparse=FALSE), 1, any)), sum(apply(st_within(poi_pubs_sf, forestinv_buf500, sparse=FALSE), 1, any))) +forestinv_counts <- rbind(forestinv_counts, pubs_forestinv_row) colnames(forestinv_counts) <- c("Within Woodlands", "...50m", "...500m") # Generate dataframe from rows based on percentages of totals -ecs_forestinv_row_pct <- ecs_forestinv_row/length(ecs_sf) +# TODO: fix error generated by ecs_forestinv_row_pct using ecs_sf. Migrate all these to sf, but check for errors. +ecs_forestinv_row_pct <- ecs_forestinv_row/length(ecs) pow_forestinv_row_pct <- pow_forestinv_row/length(pow_pointX) dtas_forestinv_row_pct <- dtas_forestinv_row/length(dtas) transition_forestinv_row_pct <- transition_forestinv_row/length(transition) permaculture_forestinv_row_pct <- permaculture_forestinv_row/length(permaculture) +grocery_forestinv_row_pct <- grocery_forestinv_row/length(poi_grocery) +pubs_forestinv_row_pct <- pubs_forestinv_row/length(poi_pubs) forestinv_counts_pct <- rbind(ecs_forestinv_row_pct, pow_forestinv_row_pct) forestinv_counts_pct <- rbind(forestinv_counts_pct, dtas_forestinv_row_pct) forestinv_counts_pct <- rbind(forestinv_counts_pct, transition_forestinv_row_pct) forestinv_counts_pct <- rbind(forestinv_counts_pct, permaculture_forestinv_row_pct) +forestinv_counts_pct <- rbind(forestinv_counts_pct, grocery_forestinv_row_pct) +forestinv_counts_pct <- rbind(forestinv_counts_pct, pubs_forestinv_row_pct) + colnames(forestinv_counts_pct) <- c("% Within Woodlands", "% within 50m", "% within 500m") # Merge into larger dataframe @@ -658,23 +676,29 @@ permaculture_scenicareas_row <- c(sum(apply(st_within(permaculture_sf, scenicare scenicareas_counts <- rbind(scenicareas_counts, permaculture_scenicareas_row) grocery_scenicareas_row <- c(sum(apply(st_within(poi_grocery_sf, scenicareas_simplified, sparse=FALSE), 1, any)), sum(apply(st_within(poi_grocery_sf, scenicareas_buf50, sparse=FALSE), 1, any)), sum(apply(st_within(poi_grocery_sf, scenicareas_buf500, sparse=FALSE), 1, any))) +scenicareas_counts <- rbind(scenicareas_counts, grocery_scenicareas_row) pubs_scenicareas_row <- c(sum(apply(st_within(poi_pubs_sf, scenicareas_simplified, sparse=FALSE), 1, any)), sum(apply(st_within(poi_pubs_sf, scenicareas_buf50, sparse=FALSE), 1, any)), sum(apply(st_within(poi_pubs_sf, scenicareas_buf500, sparse=FALSE), 1, any))) +scenicareas_counts <- rbind(scenicareas_counts, pubs_scenicareas_row) colnames(scenicareas_counts) <- c("Within Scenic Areas", "...50m", "...500m") # Generate dataframe from rows based on percentages of totals -ecs_scenicareas_row_pct <- ecs_scenicareas_row/length(ecs_sf) +ecs_scenicareas_row_pct <- ecs_scenicareas_row/length(ecs) pow_scenicareas_row_pct <- pow_scenicareas_row/length(pow_pointX) dtas_scenicareas_row_pct <- dtas_scenicareas_row/length(dtas) transition_scenicareas_row_pct <- transition_scenicareas_row/length(transition) permaculture_scenicareas_row_pct <- permaculture_scenicareas_row/length(permaculture) +grocery_scenicareas_row_pct <- grocery_scenicareas_row/length(poi_grocery) +pubs_scenicareas_row_pct <- pubs_scenicareas_row/length(poi_pubs) scenicareas_counts_pct <- rbind(ecs_scenicareas_row_pct, pow_scenicareas_row_pct) scenicareas_counts_pct <- rbind(scenicareas_counts_pct, dtas_scenicareas_row_pct) scenicareas_counts_pct <- rbind(scenicareas_counts_pct, transition_scenicareas_row_pct) scenicareas_counts_pct <- rbind(scenicareas_counts_pct, permaculture_scenicareas_row_pct) +scenicareas_counts_pct <- rbind(scenicareas_counts_pct, grocery_scenicareas_row_pct) +scenicareas_counts_pct <- rbind(scenicareas_counts_pct, pubs_scenicareas_row_pct) colnames(scenicareas_counts_pct) <- c("% Within scenicareass", "% within 50m", "% within 500m") # Merge into larger dataframe diff --git a/wilderness_layers.qgz b/wilderness_layers.qgz index bee41ef..a9aee00 100644 Binary files a/wilderness_layers.qgz and b/wilderness_layers.qgz differ