It is not clear to me if you want to crop or if you want to mask some areas, both things are possible in IsoriX.
For cropping, this is most easily done at the prepraster() stage: just the argument "manual_crop" and provide your 4 coordinates as a vector (see ?prepraster); but you can also crop at the final stage (see example below).
For masking, when you call plot() on an object created by isofind, there is an argument called mask2 and you can add any SpatVector object to define the mask.
library(IsoriX)
# Example from ?isofind ---------------------------------------------------
GNIPDataDEagg <- prepsources(data = GNIPDataDE)
GermanFit <- isofit(
data = GNIPDataDEagg,
mean_model_fix = list(elev = TRUE, lat_abs = TRUE)
)
## We build the isoscape
GermanScape <- isoscape(
raster = ElevRasterDE,
isofit = GermanFit
)
## We fit the calibration model
CalibAlien <- calibfit(
data = CalibDataAlien,
isofit = GermanFit
)
## We perform the assignment on land only
AssignmentDry <- isofind(
data = AssignDataAlien,
isoscape = GermanScape,
calibfit = CalibAlien
)
## Simple plot
plot(AssignmentDry, who = "group")
# Cropping assignment maps ---------------------------------------------------
## Define region to keep
coord_after_croping <- terra::ext(5.50207, 15.50583, 47.00592, 53) #long1 long2 lat1 lat2
## Cropping
croppedAssignmentDry <- AssignmentDry
croppedAssignmentDry$group$pv <- terra::crop(AssignmentDry$group$pv, coord_after_croping)
croppedAssignmentDry$sample$pv <- terra::crop(AssignmentDry$sample$pv, coord_after_croping)
## Plotting cropped map
plot(croppedAssignmentDry, who = "group")
plot(croppedAssignmentDry, who = "Alien_1")
# Masking assignment maps ---------------------------------------------------
## Simple creation of a spatial vector on the file
my_mask <- terra::vect("POLYGON ((8 49, 7 50, 8 51, 10 50.5, 11 51, 12 50, 12 49, 10 49.5, 8 49))")
## Import shape file (here from:
https://download.geofabrik.de/europe/germany/brandenburg.html)
polygon_object <- terra::vect("~/Downloads/brandenburg-latest-free.shp/gis_osm_landuse_a_free_1.shp")
my_mask2 <- terra::aggregate(polygon_object) ## the shape file as > 270000 geometries, so we merge them all (slow)
## Plot cropped map with custom masks