[R-sig-Geo] how create grid raster with 0.5 size of resolution

Alessandro alessandro.montaghi at unifi.it
Thu Dec 4 00:35:00 CET 2008


Hi R- Reserchers

 

To improve my analysis i need a raster with 0.5 x 0.5 of resolution.

 

I use this code but I tried several solution to find the right command to
obtain 0.5x0.5 resolution

 

Thanks 

Ale 

 

 

> dem.area <-
(ground at bbox[1,2]-ground at bbox[1,1])*(ground at bbox[2,2]-ground at bbox[2,1]) #A#
makes the dem area

> dem.pixelsize <- round(sqrt(dem.area/length(ground$Z)),0) #A# makes the
cell size

> dem.pixelsize

[1] 1

> dem.grid <-
GridTopology(cellcentre.offset=c(ground at bbox[1,1],ground at bbox[2,1]),
cellsize=c(dem.pixelsize,dem.pixelsize),
cells.dim=c(round((ground at bbox[1,2]-ground at bbox[1,1])/dem.pixelsize,0),round
((ground at bbox[2,2]-ground at bbox[2,1])/dem.pixelsize,0)))

> dem.grid

                        X1      X2

cellcentre.offset 267586.6 4147061

cellsize               1.0       1

cells.dim           1405.0     829

> dem <- as(SpatialGrid(dem.grid, proj4string = CRS(as.character(NA))),
"SpatialGridDataFrame")

> ID <- as.factor(1:(dem.grid at cells.dim[1]*dem.grid at cells.dim[2]))

> dem at data <- as.data.frame(ID)

> proj4string(dem) <- CRS("+init=epsg:26911")

> str(dem["ID"])

Formal class 'SpatialGridDataFrame' [package "sp"] with 6 slots

  ..@ data       :'data.frame': 1164745 obs. of  1 variable:

  .. ..$ ID: Factor w/ 1164745 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9
10 ...

  ..@ grid       :Formal class 'GridTopology' [package "sp"] with 3 slots

  .. .. ..@ cellcentre.offset: num [1:2]  267587 4147061

  .. .. ..@ cellsize         : num [1:2] 1 1

  .. .. ..@ cells.dim        : int [1:2] 1405 829

  ..@ grid.index : int(0) 

  ..@ coords     : num [1:2, 1:2]  267587  268991 4147061 4147889

  .. ..- attr(*, "dimnames")=List of 2

  .. .. ..$ : NULL

  .. .. ..$ : chr [1:2] "coords.x1" "coords.x2"

  ..@ bbox       : num [1:2, 1:2]  267586 4147060  268991 4147889

  .. ..- attr(*, "dimnames")=List of 2

  .. .. ..$ : chr [1:2] "coords.x1" "coords.x2"

  .. .. ..$ : chr [1:2] "min" "max"

  ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots

  .. .. ..@ projargs: chr " +init=epsg:26911 +proj=utm +zone=11 +ellps=GRS80
+datum=NAD83 +units=m +no_defs +towgs84=0,0,0"

> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20081203/30fe3cbd/attachment.html>


More information about the R-sig-Geo mailing list