File: sample.R

package info (click to toggle)
r-cran-sf 0.9-7%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,796 kB
  • sloc: cpp: 5,333; sh: 18; makefile: 2
file content (31 lines) | stat: -rw-r--r-- 1,079 bytes parent folder | download | duplicates (3)
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
suppressPackageStartupMessages(library(sf))
bb = st_bbox(c(xmin=0, ymin=1, xmax=3, ymax=2))
xx <- st_make_grid(st_as_sfc(bb), square = FALSE, what = "polygons")
plot(xx, border = 'green', main = "pointy topped")
x <- st_make_grid(st_as_sfc(bb), square = FALSE, what = "points")
plot(x, add = TRUE)
x <- st_make_grid(st_as_sfc(bb), square = FALSE, what = "corners")
plot(x, col = 'orange', add = TRUE)
plot(st_as_sfc(bb), add = TRUE, border = 'red')
st_overlaps(xx) %>% 
	lengths() %>% 
	sum()

st_as_sfc(bb) %>%
	st_difference(st_union(xx)) %>%
	st_area()

xx <- st_make_grid(st_as_sfc(bb), square = FALSE, what = "polygons", flat_topped = TRUE)
plot(xx, border = 'green', main = "flat topped")
x <- st_make_grid(st_as_sfc(bb), square = FALSE, what = "points", flat_topped = TRUE)
plot(x, add = TRUE)
x <- st_make_grid(st_as_sfc(bb), square = FALSE, what = "corners", flat_topped = TRUE)
plot(x, col = 'orange', add = TRUE)
plot(st_as_sfc(bb), add = TRUE, border = 'red')
st_overlaps(xx) %>% 
	lengths() %>% 
	sum()

st_as_sfc(bb) %>%
	st_difference(st_union(xx)) %>%
	st_area()