Reputation: 57
Following is the code I am using to extract image value using dataframe. But I am getting an error in last line of the code. Please let me know how to solve the issue?
library(raster)
library(gdalUtils)
library(raster)
library(ncdf4)
library(sp)
library(sf)
library(rgdal)
library(raster)
library(tidyverse)
library(tidyr)
setwd("C:/Users/phd-shanti/Downloads/trmm_daily18")
trmm_files <- list.files(,pattern=".nc4$",full.names = FALSE) # to read all files with the name nc4
trmm_stack <- stack(trmm_files, varname = "HQprecipitation") # to stack multiple image together
crs(trmm_stack) <- CRS('+init=EPSG:4326') # also it was rotated and geometry was set
trmm_stack_flip <- t(flip(trmm_stack, direction='y'))
setwd("D:/fire_work_cov/data/india_fire_points1mar_30may/20_02_cmbi_shp")
a <- list.files(pattern= '*.shp')
f<- read_sf("chotanagpur.shp")
bb = as.data.frame(f)
g<- bb[,c("LATITUDE",'LONGITUDE')]
rasValue=extract(trmm_stack_flip , g)
I m getting error in last line?
Error in UseMethod("extract_") : no applicable method for 'extract_' applied to an object of class "c('RasterBrick', 'Raster', 'RasterStackBrick', 'BasicRaster')"
Upvotes: 0
Views: 113
Reputation: 367
In your code, the extract
function is called from the tidyr
package. But here you want it to call it from the raster
package. You can force it to call from it.
rasValue = raster::extract(trmm_stack_flip , g)
Let me know if this helps.
Upvotes: 1