I want to create a presence-absence raster out of a shapefile (vector) with the rasterize command of the R-package in R. Until now I only get wrong results.
The raster should just distinguish between the two options ('shapefile on this cell present', 'shapefile on this cell abscent').
I tried it out with several options of the rasterize-command:
forest_polygons_raster_mask <- rasterize(forest_polygons, ras, mask = TRUE)
forest_polygons_raster_update <- rasterize(forest_polygons, ras, update =
TRUE)
forest_polygons_raster_cov <- rasterize(forest_polygons, ras, getCover =
TRUE)
the command with the getCover option does not stop, also after several hours. With both of the other commands I get a wrong result and my raster has presence-cells in areas where the shapefile is abscent.
The original shapefile with two holes:
That is the raster I get after the rasterize command with the update-option. One hole is missing, and the other is split into two smaller holes. No abscence was recognized wrong, just presence was recognized wrong:
Shapefile layer over raster layer, the holes in the shapefile are not left out as abscence in the raster:
Did anyone have a similar problem? What might the problem be? My shapefile is quite ordinary with different fields of the categories: ID, Shape (Polygon), Classification (text), Shape_Area, Shape_Length. The cellsize of the input raster for the rasterize process is quite small (so I do not expect that the errors are due to two big cells).