I'm trying to extract values from many rasters to specific points and have those values be in columns that are labeled as the raster name. I can do it all here except get the values. All projections match. Is this due to the fact that is an ovr type raster?

m <- "E:/./"
allFiles <- list.files(m, full.names = T,pattern = "_ex0315.ovr",
                       no.. = TRUE, recursive=TRUE)
filenamez <- str_split_fixed(allFiles, "/", 6)[,5]
allFiles <- stack(allFiles)

names(allFiles) <- filenamez
projection(allFiles) <- CRS("+proj=utm +zone=14 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0") 


corproj<-CRS("+proj=utm +zone=14 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0")

points <- SpatialPointsDataFrame(Choruspts[,2:3], Choruspts,
                                 proj4string = corproj)   

points.mrc <- spTransform(points, CRS(projection(allFiles)))

output<-as.data.frame(matrix(NA, nrow(Choruspts), length(filenamez)))

for(i in 1:length(filenamez)) {
    output[, i] <- extract(allFiles[[i]], points, method="bilinear")
names(output) <- filenamez

fulloutput <- cbind(Choruspts, output)

The output has the 3 columns of the point files and column headers of the 399 rasters but the values are all NAs.

[1] 200 399

For example:

  Location Easting Northing A1_2013-04-06_650 A1_2013-04-06_710 A1_2013-04-06_730 A1_2013-04-06_750 A1_2013-04-20_640
1 A1 E 100  427572  4676098                NA                NA                NA                NA                NA
2 A1 E 200  427672  4676098                NA                NA                NA                NA                NA
3 A1 E 400  427872  4676097                NA                NA                NA                NA                NA
4  A1 E 50  427522  4676099                NA                NA                NA                NA                NA
5 A1 E 800  428073  4676090                NA                NA                NA                NA                NA
6 A1 N 100  427465  4676203                NA                NA                NA                NA                NA

I have determined that the stack is lacking values, which should be the last entry on the bottom:

class       : RasterStack 
dimensions  : 1436, 801, 1150236, 399  (nrow, ncol, ncell, nlayers)
resolution  : 1, 1  (x, y)
extent      : 0, 801, 0, 1436  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=14 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0 
names       : A1_2013.04.06_650, A1_2013.04.06_710, A1_2013.04.06_730, A1_2013.04.06_750, A1_2013.04.20_640, A1_2013.04.20_700, A1_2013.04.20_740, A1_2013.04.20_800, A1_2013.04.20_820, A1_2013.04.20_840, A1_2013.04.20_900, A1_2013.04.20_920, A1_2013.04.27_617, A1_2013.04.27_644, A1_2013.04.27_708, ... 

The points you are using do not seem to overlap with the extent of your RasterStack

extent      : 0, 801, 0, 1436  (xmin, xmax, ymin, ymax)

The extent look suspect, it would be area of about 1 by 1 km (which is of course possible) with one edge on the equator.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.