I want to model the movement of fish. Therefore I get a bathymetric map from gebco and masked the land masses.
library(terra)
tif_file <- "~/path_to/GEBCO_map.tif"
map <- rast(tif_file)
map <- ifel(map >= 0, NA, abs(map))
until here I have everything under control. Now I want to change the resolution of the map to a coarser scale and I need to change the coordinates reference.
print(res(map))
[1] 0.004166667 0.004166667
# I want to change that to 100x100
coord. ref. : lon/lat WGS 84 (EPSG:4326)
# I want to change that to coord. ref. : WGS 84 / UTM zone 29N (EPSG:32629)
# for that I have a reference map (mapE)
map_reprojected <- project(map, crs(mapE))
# Trying to get the desired resolution (e.g., 100 x 100 meters)
new_resolution <- c(100, 100)
current_resolution <- res(map)
# Calculate the target number of rows and columns based on the desired resolution
target_ncols <- ncol(map) * (current_resolution[1] / new_resolution[1])
target_nrows <- nrow(map) * (current_resolution[2] / new_resolution[2])
# Create a dummy raster with the new resolution but same number of rows and columns
dummy_raster <- rast(ext(map), nrows = round(target_nrows), ncols = round(target_ncols), resolution = new_resolution)
# Resample the original map to the new resolution while keeping the number of rows and columns
map_resampled <- resample(map_reprojected, res = new_resolution, method = "bilinear")
My problem is, that once I adjust the resolution, my dimensions of the map go to 1,1,1 and I have NAs everywhere. Is there any way to change just the resolution of the map?
Changing the coord.reference works but is the map still correct then ? When I plot it, it looks worbed.