I'm working with R and I have a raster (population
) with population density data on each cell and a multilinestring (border_365_366
) that represents an international border. I'd like to extract the coordinates of the raster cells that overlap with the international border.
Does anyone know how to extract this? I think one of the major issues here is that I'm working with a multilestring instead of a data.frame with coordinates.
> class(border_365_366)
[1] "sf" "data.frame"
> class(population)
[1] "RasterLayer"
attr(,"package")
[1] "raster"
> border_365_366
Simple feature collection with 1 feature and 0 fields
geometry type: MULTILINESTRING
dimension: XY
bbox: xmin: 27.32998 ymin: 57.52933 xmax: 28.21014 ymax: 59.46253
geographic CRS: WGS 84
geometry
1 MULTILINESTRING ((27.66656 ...
> population
class : RasterLayer
dimensions : 21600, 34926, 754401600 (nrow, ncol, ncell)
resolution : 0.01030751, 0.01046373 (x, y)
extent : -180, 180, -120.053, 105.9636 (xmin, xmax, ymin, ymax)
crs : +proj=longlat +datum=WGS84 +no_defs
names : pop_new
values : 0, 107475 (min, max)
I was able to solve this issue by converting the line to linestring
border_365_366<- st_cast(border_365_366,'LINESTRING')