Skip to content

Open raster _ extract pixel value

10 messages · Roger Bivand, Komine, Roman Luštrik +2 more

#
Hi, 
I begin to work with R software to treat raster data. 
Now, I have a NDVI image with a tiff extension. I want to open this image
and to extract NDVI value for some pixel which I have their coordinates. 
1-	Please what is the code to open a tiff image with R ?
2-	How to extract the value of some pixel which I have their coordinate ? 
NB: I hope you understand my questions with my bad English. 
Thank you 


--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Open-raster-extract-pixel-value-tp6166730p6166730.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
#
On Sun, 13 Mar 2011, Roman Lu?trik wrote:

            
An oblique remark - a translation of the Spatial task view page into 
Belorussian by Amanda Lynn is at:

http://webhostingrating.com/libs/analysis-of-spatial-data-be

If other translations became available (volunteers welcome), perhaps the 
ctv Task View mechanism could be internationalised?

Roger

  
    
#
Thank for your answers,
 But I don't arrive to open my raster.After to download raster package, I
tried this code to open my raster but, there is an error:
My code=
r<-read.raster("C:\\Users\\Komine\\Desktop\\MODIS\\MYD09GQ.A2010280.h16v07.005.2010282160347.sur_refl_b01_1.tif",package="raster")

Please, where is the error?
Thanks again.  

--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Open-raster-extract-pixel-value-tp6166730p6167068.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
#
Dear all,
I tried your suggestion doing this:

library(raster)
myobject <-
raster("C:\\Users\\komine\\Desktop\\MODIS\\MYD09GQ.A2010280.h16v07.005.2010282160347.sur_refl_b01_1.tif")
e <- extent(-90, -32, -60, 15)
r <-
crop("C:\\Users\\komine\\Desktop\\MODIS\\MYD09GQ.A2010280.h16v07.005.2010282160347.sur_refl_b01_1.tif",e)
plot(myobject)

the result is here:
Fixing "AREA_OR_POINT=Point" georeference
Erreur dans function (classes, fdef, mtable)  :
  unable to find an inherited method for function "crop", for signature
"character"
However the raster appear in spite of the previous error message.
1- I suppose that I did an error although R read my raster?
2- Could you explain me the meaning of: extent(-90, -32, -60, 15)

Thanks for your help


--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Open-raster-extract-pixel-value-tp6166730p6167299.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
#
Komine, you can do:

library(raster) 
myobject
<-raster("C:\\Users\\komine\\Desktop\\MODIS\\MYD09GQ.A2010280.h16v07.005.2010282160347.sur_refl_b01_1.tif") 
plot(myobject)
click(myobject)   # and click somewhere on the map to get the value at that
location 
myobject[1]  # value of first cell
myobject[10,10]  # value of cell at row 10, column 10
extract(myobject, cbind(0,0))  # value at coordinates (0,0) (perhaps not on
your map)
?extract # for more info. 

Robert



--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Open-raster-extract-pixel-value-tp6166730p6167448.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
#
Thanks to all for your answers, I progress!
Robert, after to try your code, all is ok. Now I try to open a NDVI image
with HRD extension. Also almost all is ok with the next code: 
library(raster) 
myobject <-raster("C:\\Users\\komine\\Desktop\\MODIS2\\NDVI_280") 
plot(myobject) 
click(myobject)   # and click somewhere on the map to get the value at that
location 
myobject[1]  # value of first cell 
myobject[10,10]  # value of cell at row 10, column 10 
extract(myobject, cbind(496439.36,1662612.38)) # value at coordinates
-	However, the image NDVI don?t appear well because I have a color on the
raster map like a mask,
-	Also, I compare to verify a pixel value NDVI extract from R and the ENVI
software (like Erdas) but I have two differences values for the same pixel
(for the past coordinates, pixel value from R= -0.5376111  whereas for ENVI= 
-0.586962)
Could you help on this problem? 
Thanks again 


--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Open-raster-extract-pixel-value-tp6166730p6171051.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
#
Dear, 
Thanks, pixel value is ok, in fact I must put 4 numbers after the gamma. But
the image NDVI don't appear good with a color on all the map although the
pixel values are correct.

Thank you

--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Open-raster-extract-pixel-value-tp6166730p6172015.html
Sent from the R-sig-geo mailing list archive at Nabble.com.