polygon - Rasterize spatialpolygons in R giving raster with NA values -


i having issues converting spatialpolygondataframe raster. when ther conversion, raster has na values. shown below:

 dl3 [1] class       : spatialpolygonsdataframe  features    : 126  extent      : -15.04001, 46.1036, 3.759985, 31.71804  (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +datum=wgs84 +towgs84=0,0,0 +ellps=wgs84  variables   : 1 names       :  lfrp  min values  :    14  max values  : 335.2  

this how rasterize it:

##to convert raster funr<-function(r){ ext<-raster(extent(r)) crs(ext)<-crs(r) d<-rasterize(r,ext,field=1,update=t) d}  dl4<-lapply(dl3,funr) dl4 [1] class       : rasterlayer  dimensions  : 45, 40, 1800  (nrow, ncol, ncell) resolution  : 1.52859, 0.6212901  (x, y) extent      : -15.04001, 46.1036, 3.759985, 31.71804  (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +datum=wgs84 +towgs84=0,0,0 +ellps=wgs84  data source : in memory names       : layer  values      : na, na  (min, max) 

what can doing wrongly? need method ensure values in dataframe reflect in raster, please.

the principle works, illustrated below.

library(raster) spp <- shapefile(system.file("external/lux.shp", package="raster")) r <- raster(spp, ncol=40, nrow=45)     spp2 <- rasterize(spp, r, "id_1") 

as not work you, assume polygons small relative raster cell size such none of cells covered. can try smaller grid cells? if indeed polygons small, might make more sense use centroids (coordinates(spp)) , rasterize these (as points).


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -