I have two polygons, where the smaller is completed contained within the larger. These polygons cover a large portion of North America. Here I create them using a bounding box in 4326.
#create two polygons
b1 <- sf::st_bbox(c(xmin = -170, ymin = 23, xmax = -50, ymax = 80), crs = 4326) %>%
sf::st_as_sfc()
b2 <- sf::st_bbox(c(xmin = -160, ymin = 26, xmax = -80, ymax = 60), crs = 4326) %>%
sf::st_as_sfc()
#plot polygons (4236)
plot(b1, col = 'red')
plot(b2, col = 'yellow', add = TRUE)
We can also visualize in Google Earth.
When I reproject these polygons (sinusoidal projection), however, the smaller is no longer completely contained within the larger.
Why is this?
I assume this has to do with the properties of the projection, but don't fully understand. I would have thought that a polygon contained within a larger polygon would need to stay contained within that polygon regardless of any transformations that are applied.
Apparently not though?
Note I also checked this in QGIS to make sure this isn't some sort of coding/software issue.
#repoject to MODIS sinusoidal projection
PROJ <- '+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +R=6371007.181 +units=m +no_defs'
b1_tr <- sf::st_transform(b1, crs = PROJ)
b2_tr <- sf::st_transform(b2, crs = PROJ)
#plot reprojected polygons
plot(b1_tr, col = 'red')
plot(b2_tr, col = 'yellow', add = TRUE)
Note how the yellow polygon is no longer completely inside the red polygon.
No such weirdness applies to rasters though (that have the same extent as the polygons) that are reprojected. The yellow raster is completely contained within the red raster. See below for rasters in 4326 and Sinusoidal.
#create rasters with same extent as polygons
r1 <- terra::rast(matrix(1, nrow = 100, ncol = 100))
terra::crs(r1) <- "epsg:4326"
terra::ext(r1) <- c(-170, -50, 23, 80)
r2 <- terra::rast(matrix(2, nrow = 100, ncol = 100))
terra::crs(r2) <- "epsg:4326"
terra::ext(r2) <- c(-160, -80, 26, 60)
#plot rasters (4326)
plot(r1, col = 'red')
plot(r2, col = 'yellow', add = TRUE, axes = FALSE)
#repoject to MODIS sinusoidal projection
r1_tr <- terra::project(r1, PROJ)
r2_tr <- terra::project(r2, PROJ)
#plot reprojected polygons
plot(r1_tr, col = 'red')
plot(r2_tr, col = 'yellow', add = TRUE, axes = FALSE)
My take away from this is not to reproject vector files that cover a large spatial area, which makes me somewhat uneasy!