Dear R-sig-geo users,

    I have a question about extracting information from a raster file
after I read it in using rgdal package, and I would be infinitely
grateful if someone could help me.
    The summary of raster file looks like this:

#summary of raster file
> summary(xxx)
Object of class SpatialGridDataFrame
Coordinates:
   min max
x -180 180
y  -90  90
Is projected: FALSE
proj4string :
[+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0]
Number of points: 2
Grid attributes:
  cellcentre.offset cellsize cells.dim
x           -179.10      1.8       200
y            -89.55      0.9       200
Data attributes:
     Min.   1st Qu.    Median      Mean   3rd Qu.      Max.      NA's
    0.000     0.000     0.000    47.010     3.264 13540.000 26563.000

I would like to write a code that extracts the value of associated
cell given a specific location in latitude and longitude. I've noticed
that [EMAIL PROTECTED] contains the values as 40000 x 1 matrix. I've wrote the
following code assuming that the values are stored as in C programing
(column wise seperation):


#initiate values
[EMAIL PROTECTED]@cellsize[1]
[EMAIL PROTECTED]@cellsize[2]

[EMAIL PROTECTED]@cellcentre.offset[1]
[EMAIL PROTECTED]@cellcentre.offset[2]

[EMAIL PROTECTED]@cells.dim[1]
[EMAIL PROTECTED]@cells.dim[2]

#given coordinate
x=26
y=45

#find the index
index=floor((x-x_start)/x_inc)*y_dim + floor( (y-y_start)/y_inc )
[EMAIL PROTECTED],1]

The result does not seem to match what I should get. Could anybody
explain to me how the data is stored in SpatialGridDataFrame? Your
help would be much much appreciated.

Thank you and have a good night
Harry

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to