[R-sig-Geo] how to calculate with grids?

Bastian Pöschl rotate at gmx.li
Tue Mar 16 20:49:31 CET 2010


Dear useRs,
        
        I try to subtract one ascii grid from another.
        
        By now i havn't managed to get a proper output.
        Sorry I am not able to provide the files for testing because
        they are very big.
        
        The grids are read by 
        
        dem1<-readAsciiGrid("grid1.asc", as.image = FALSE, plot.image =
        FALSE, colname = "height_old", proj4string = crs)
        dem2<-readAsciiGrid("dem2.asc", as.image = FALSE, plot.image =
        FALSE, colname = "height_new", proj4string = crs)
        
        The cell dimension is not equal (i tried to convert them into
        SpatialPointDataFrames to subtract the data, but struggled
        because of the different extensions.
        The cellsize is equal
        
        1> summary(dem1)
        Object of class SpatialGridDataFrame
        Coordinates:
                      min     max
        coords.x1 3493070 3495230
        coords.x2 5404550 5405920
        Is projected: TRUE 
        proj4string :
        [+proj=tmerc +lat_0=0 +lon_0=9 +k=1 +x_0=3500000 +y_0=0
        +ellps=bessel +datum=potsdam +units=m +no_defs]
        Number of points: 2
        Grid attributes:
          cellcentre.offset cellsize cells.dim
        1         3493070.5        1      2160
        2         5404550.5        1      1370
        Data attributes:
              Min.    1st Qu.     Median       Mean    3rd Qu.
        Max.       NA's 
          420.0000   433.4856   443.1912   442.5298   450.7338
        465.0000 80438.0000 
        
        1> summary(dem2)
        Object of class SpatialGridDataFrame
        Coordinates:
                        min       max
        coords.x1 3492999.5 3495000.5
        coords.x2 5403999.5 5406000.5
        Is projected: TRUE 
        proj4string :
        [+proj=tmerc +lat_0=0 +lon_0=9 +k=1 +x_0=3500000 +y_0=0
        +ellps=bessel +datum=potsdam +units=m +no_defs]
        Number of points: 2
        Grid attributes:
          cellcentre.offset cellsize cells.dim
        1           3493000        1      2001
        2           5404000        1      2001
        Data attributes:
            Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
        396.3400 425.7900 439.0900 437.6107 449.2700 470.1700 
        
        
        
        I found some hints in the help archive.
        http://finzi.psych.upenn.edu/Rhelp10/2009-February/187216.html
        tells about combining grids in an array, what i tried, but
        failed.
        
        I hope somebody can help me and give some advice how grids can
        be merged and/or calculations can be don within the grid format.
        
        This would be great.
        
        Thank you,
        
        Bastian



More information about the R-sig-Geo mailing list