1

I have a spatial grid of an image. Now I want to use this grid and make a finer resolution grid out of it.

For example an image structure in R is given below:

str(c)
Formal class 'SpatialGridDataFrame' [package "sp"] with 4 slots
  ..@ data       :'data.frame': 35100 obs. of  1 variable:
  .. ..$ class: num [1:35100(1d)] 0 0 0 0 0 0 0 0 0 0 ...
  ..@ grid       :Formal class 'GridTopology' [package "sp"] with 3 slots
  .. .. ..@ cellcentre.offset: Named num [1:2] 563450 6355500
  .. .. .. ..- attr(*, "names")= chr [1:2] "x" "y"
  .. .. ..@ cellsize         : num [1:2] 25 25
  .. .. ..@ cells.dim        : int [1:2] 36 39
  ..@ bbox       : num [1:2, 1:2] 563438 6355488 564338 6356463
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:2] "x" "y"
  .. .. ..$ : chr [1:2] "min" "max"
  ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
  .. .. ..@ projargs: chr "+proj=utm +zone=35 +south +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"

Here i want to create a finer resolution grid with increasing the cell.dim i.e by multiplying rows and columns by a scale factor S=5 and also changing cell size by dividing the same by scale factor 5.

So, to do this we need to change the cellcentre.offset, which am unable to do so. The bounding box would remain same.

The problem m facing is that the data is of 35100 observations but when i display it, i can only display 1404 observations (36*39) because of the present grid topology. I want to display all the observations for that I need a finer resolution grid topology with the same bounding box.

1

You can do:

library(raster)
d <- raster(c)
dd <- disaggregate(d, 5)
  • Ah, the beautiful simplicity, at least on the surface. – Jeffrey Evans Jul 1 '16 at 14:49
1

I got the solution.

For creating a new grid we first need the bounding box and the pixel size to which it is to be changed.

The below code would form a new grid of any resolution:

#defining spatial grid data frame
S=5 #scale to which it is to be converted
psize<-psdeg[1]/S    # psdeg is the pixel size of old grid
bb<-c@bbox #bounding box where "c" is the old grid

cs <- c(psize, psize) #new cell size
cc <- bb[, 1] + (cs/2) # new cell centre
cd <- ceiling(diff(t(bb))/cs) # new cell dimensions

deggrid <- GridTopology(cellcentre.offset=cc,cellsize=cs,cells.dim=cd) # grid formation

k<-array(0,c(Mdeg*Ndeg*S^2)) #dataframe for new grid

class<-array(k)
class<-as.data.frame(class) 
Ddeg <- SpatialGridDataFrame(deggrid, class , proj4string = "+proj=utm +zone=35 +south +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs") # spatial grid dataframe formation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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