I have rasterized a SpatialPointsDataFrame
object, but the created RasterLayer
returns NA.
> #create spatial attributes
> xmin <- 624748.7
> xmax <- 669548.7
> ymin <- 640557.8
> ymax <- 712757.8
> goef.col <- 448.00
> geof.row <- 722.00
> spa.res <- 100.00
>
> #Points
> points <- frame.val
> points
X Y Z DATE
1 100.1855 6.448029 3.9 2.5
2 100.3491 6.348555 3.9 18.0
3 100.3125 6.318388 3.9 4.0
4 100.3852 6.285333 3.9 3.0
5 100.3587 6.242500 3.9 6.0
6 100.3221 6.238888 3.9 3.0
7 100.2445 6.217528 3.9 2.0
8 100.3990 6.149028 3.9 1.0
9 100.4592 6.175778 3.9 1.0
10 100.4010 6.085000 3.9 1.0
11 100.4447 5.973361 3.9 1.0
12 100.4113 6.022528 3.9 0.0
13 100.3281 6.046112 3.9 1.0
14 100.3299 6.097472 3.9 1.0
15 100.3648 5.850138 3.9 0.0
>
> coordinates(points) <- c("X", "Y")
> points
class : SpatialPointsDataFrame
features : 15
extent : 100.1855, 100.4592, 5.850138, 6.448029 (xmin, xmax, ymin, ymax)
crs : NA
variables : 2
names : Z, DATE
min values : 3.9, 0
max values : 3.9, 18
>
> # An empty SpatialGrid
> basin.grid <- SpatialGrid(GridTopology(c(X = xmin, Y = ymin),
+ c(spa.res, spa.res),
+ c(goef.col, geof.row)))
> basin.grid <- SpatialPoints(basin.grid)
> gridded(basin.grid) <- TRUE
>
> # The grid is converted into RasterLayer
> raster.georef <- raster(basin.grid)
> ext.raster <- points[2]
>
> point.raster <- rasterize(ext.raster, raster.georef, 'DATE')
> point.raster
class : RasterLayer
dimensions : 722, 448, 323456 (nrow, ncol, ncell)
resolution : 100, 100 (x, y)
extent : 624698.7, 669498.7, 640507.8, 712707.8 (xmin, xmax, ymin, ymax)
crs : NA
source : memory
names : layer
values : NA, NA (min, max)
Any way I can solve this to get real values in the created RasterLayer
?