Raster & R – Extracting Values According to Latitude and Longitude

latitude longituderraster

having 12 files with 12 hdrs for one year: these files are raster (projected WGS84,lat long):

          samples = 1440
           lines   = 720
           bands   = 1
           header offset = 0
           file type = ENVI Standard
           data type = 4
           interleave = bsq
            byte order = 0
      map info = {  Geographic Lat/Lon, 1, 1, -180, 90, 0.25, 0.25,WGS-84}
        coordinate system string = GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",
                 SPHEROID["WGS_1984",6378137,298.257223563]]
       ,PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
                 }

These lines will open the files as a list:

      a<-list.files("D:\\ECV\\2010", "*.envi", full.names = TRUE)
           for(i in 1:length(a)){
            d <- raster(a[i]}

I would like to extract the values correspond to 44.8386° N, 0.5783° W from all files as txt file

Best Answer

Curlew's answer can be improved upon like this (do not use a loop, and use a RasterStack)

library(raster)
files <- list.files("D:\\ECV\\2010", "*.envi", full.names = TRUE)
s <- stack(files)
point <- cbind(44.8386, 0.5783)
result <- extract(s, point)