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",

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

3 Answers 3


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

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

Assuming that you know how to create a point shape out of your longitude, latitude value:

point_location <- readOGR("Foldername","filename")
a<-list.files("D:\\ECV\\2010", "*.envi", full.names = TRUE)
result <- data.frame(ID=seq(1,length(a)),Value=rep(NA,length(a))
for(i in 1:length(a)){
   d <- raster(a[i])
   result$Value[i] <- extract(d,point_location)     

EDIT: The quick and dirty way to do it manually in QGIS

  • Load in your NVDI raster layers and Create a new point layer with WGS84 (https://i.sstatic.net/QECqp.jpg)
  • Set the new point layer on EDIT-Mode and go to the address field on the bottom of your QGis window
  • Here add your longitude,latitude values (http://imgur.com/UpeunXm),press return and zoom to your address. This is very dirty and not exact. If you want exact values you should search how to convert those values to a shapefile in QGIS (i would try to use the add text-delimited file and create a .csv file with your locations first.)
  • Now add a point to your new layer on this location and save.
  • Open the Plugin Downloader and download the Point Sampling Tool. The Rest is self-explaining.
  • what you mean by "Assuming that know how to create a point shape out of your longitude, latitude value:" what folder name and file name refer to? in point_location
    – Jonsson
    Commented Jan 27, 2013 at 13:12
  • well, you need to create a point shapefile with your longitude, latitude values. readOGR needs the directory and the filename (without extension). Like this readOGR("D:/Data/GIS","location") to load in location.shp
    – Curlew
    Commented Jan 27, 2013 at 13:32
  • so first I create a point shape out of my longitude, latitude value(which I do not know how to do it)then i use the code above,third I use writetable to write the results.I wonder if you tried it,it worked?
    – Jonsson
    Commented Jan 27, 2013 at 13:40
  • correct, i just tried it out and it works without any problems (i.imgur.com/kf7Ei3M.png). I made a test point somewhere near your location (using QGIS). Please test it yourself :-)
    – Curlew
    Commented Jan 27, 2013 at 14:01
  • could you please tell me how did you do it(I can not create the shape file,please add the steps of creating the shapefile).Or please explain how we can do it using QGIS as a second answer?I have been struggling for long time
    – Jonsson
    Commented Jan 27, 2013 at 14:07

Just a short remark to the extract function from raster package when you work with lat and lon values - use SpatialPoints: x<- 44.8386 y<- 0.5783 value<-extract(raster, SpatialPoints(cbind(x,y)))

Without it, you may just receive NA values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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