Issue in setting y argument for sample_lsm function
igloopigloo opened this issue · 1 comments
Hi,
I am trying to calculate some landscape metrics from a landcover raster for a few points using landscapmetrics package in R.
Below is my code. The strange thing is the same code that works on one laptop, does not work on another. Or. maybe I am doing something wrong.
`#read raster file
landcover<-raster("reclass_avg.tif")
#read point shapefile
kest_ebd1<-shapefile("kest_test.shp")
#project point shapefile to that of raster
kest_ebd1a<-spTransform(kest_ebd1,crs(landcover))
buffer_sizes=c(250,500,1000) # buffers for different sizes
buffer_grid_mon = buffer_sizes %>% #buffer data
set_names() %>%
map_dfr(~sample_lsm(list(landcover),
what=c("lsm_c_pland","lsm_l_shdi","lsm_c_ed"), #metrics
y = kest_ebd1a, #locations
shape = "circle",
size = .), #from each element of the data
.id = "buffer") `
When I run the above code, it gives me the error "Error in map()
:
ℹ In index: 1.
ℹ With name: 250.
Caused by error:
! Please provide a matrix with coords, points or polygons object.
I have checked my point file. It is of SpatialPointsDataFrame object.
I don't what am I doing wrong here.
Can someone please help me out.
Thanks,
IP
Hi,
My bad!I figure it out! There was some conflict in packages version.
Thanks,
IP