Skip to content

Instantly share code, notes, and snippets.

@mdsumner
Created October 23, 2020 22:43
Show Gist options
  • Save mdsumner/38f2fa0a2e310a010cbdff1dc2ae0d6d to your computer and use it in GitHub Desktop.
Save mdsumner/38f2fa0a2e310a010cbdff1dc2ae0d6d to your computer and use it in GitHub Desktop.
## e.g. 
## sf::st_as_text(sf::st_as_sfc(sf::st_bbox(c(xmin = 0, xmax = 1, ymin = 0, ymax = 1))))
wkt_template <- "POLYGON (({xmin} {ymin}, {xmax} {ymin}, {xmax} {ymax}, {xmin} {ymax}, {xmin} {ymin}))"

xmin <- -80; xmax <- -78
ymin <- 34.5; ymax <- 36

## the filter, anything within this box will be included entirely
wkt <- glue::glue(wkt_template)

read_sf(system.file("gpkg/nc.gpkg", package = "sf", mustWork = TRUE), wkt_filter = wkt)
## normally 100 features from nc.gpkg
## 
##Simple feature collection with 27 features and 14 fields (with 1 geometry empty)
##...
@mdsumner
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment