I cropped a shapefile to a smaller extent (my AOI - area of interest) - to work with a reduced working directory. During my workflow I rasterize the shapefile.
Here is my problem: I saved both of my shapefiles (smaller and bigger) to compare the rasterized results (which should be the same as the underlying raster has the same extent (AOI) as the smaller shapefile (obviously as well my AOI)). But unfortunately they are not. CRS and number o cells are identical - but for example number of NAs not.
I did the same procedure and workflow with synthetic data and it worked perfectly - so the problem has to be my data maybe. Here is the dropboxlink where you can download the shapefile and the raster. https://www.dropbox.com/sh/btgt2rc7uzawtx5/AADJ2YrKOnPh8gM-PPF7rmIQa?dl=0
I leave you my code here:
#load shp files
setwd("C:/Users/.../R")
TESTshp<-readOGR(dsn="test_crop_dropbox", layer="boden_ebod_reproj")
extent(TESTshp)
setwd("C:/Users/.../R/test_crop_dropbox")
TESTraster<-raster("testraster.tif")
extent(TESTraster)
TESTshp_small <- crop(TESTshp, extent(TESTraster))
TESTrasterize<- rasterize(TESTshp, TESTraster, field="BodTyp_gen")
TESTrasterize_small<- rasterize(TESTshp_small, TESTraster, field="BodTyp_gen")
identical(TESTrasterize, TESTrasterize_small)
Do you have any suggestion what could be wrong? Thanks a lot!