I have a polygon:
p1 <- rbind(c(-180,-20), c(-140,55), c(10, 0), c(-140,-60), c(-180,-20))
hole <- rbind(c(-150,-20), c(-100,-10), c(-110,20), c(-150,-20))
p1 <- list(p1, hole)
I create a simple feature
polygon object:
library(sf)
poly_sfc <- st_sfc(st_polygon(p1))
and now add a simple dataframe to it:
data <- data.frame(name = "Los Angeles", language = "English", weather ="sunny")
df <- st_sf(data, geometry = poly_sfc)
I can see that it's added the data to the overall sfc
.
Simple feature collection with 1 feature and 3 fields
geometry type: POLYGON
dimension: XY
bbox: xmin: -180 ymin: -60 xmax: 10 ymax: 55
epsg (SRID): NA
proj4string: NA
name language weather geometry
1 Los Angeles English sunny POLYGON ((-180 -20, -140 55...
Now I'd like to rasterise this, which I can using:
library(star)
r <- st_rasterize(df, options = "ALL_TOUCHED=TRUE")
However, when I look at the raster r
the data from df
has been dropped.
stars object with 2 dimensions and 1 attribute
attribute(s):
ID
Min. :1
1st Qu.:1
Median :1
Mean :1
3rd Qu.:1
Max. :1
NA's :34597
dimension(s):
from to offset delta refsys point values
x 1 328 -180 0.580682 NA NA NULL [x]
y 1 199 55 -0.580682 NA NA NULL [y]
How can I make sure that the data from df
is passed into the raster? Is there a way to do it via st_rasterize
??