#ProjectCentered
Automatically center a projection on the plotted map
Following this previous post and this discussion on Mastodon, I wrote a function that wraps a combination of functions from the ‘terra’ package to project a SpatRaster or SpatVector layer while automatically centering the projection on that layer, to minimize visual distortion: projectCentered <- function(x, # SpatRaster or SpatVector proj = "laea" # +proj parameter for PROJ.4 string ) { # version 1.0, by A. Marcia Barbosa stopifnot(inherits(x, "SpatRaster") || inherits(x, "SpatVector")) if (terra::crs(x) == "" || is.na(terra::crs(x))) { stop("'x' does not have a CRS to project") } if (inherits(x, "SpatRaster")) { a <- terra::as.polygons(x * 0) } if (inherits(x, "SpatVector") && length(x) > 1) { a <- terra::aggregate(x) } else { a <- x } if (!isTRUE(terra::is.lonlat(a))) { a <- terra::project(a, "EPSG:4326") } centr <- terra::crds(terra::centroids(a)) proj <- tolower(proj) proj <- sub("+proj=", "", proj, fixed = TRUE) # in case user input prefix CRS <- paste( paste0("+proj=", proj), paste0("+lat_0=", centr[2]), paste0("+lon_0=", centr[1]) ) tryCatch(terra::project(x, CRS), error = function(e) stop("'proj' is invalid")) } Here is a use case (compared with the default behaviour), using e.g. Lambert Azimuthal Equal-Area projection: library(terra) library(geodata) countries <- geodata::world(path = tempdir()) map <- subset(countries, countries$NAME_0 %in% c("New Zealand", "Australia")) par(mfrow = c(1, 3)) plot(map, main = "Unprojected") plot(project(map, "+proj=laea"), main = "Projected, default-centered") plot(projectCentered(map, "laea"), main = "Projected, map-centered") This is meant to be used for visualization purposes. For computing e.g. areas or distances, it is better to use unprojected layers, with longitude-latitude coordinates in degrees (making sure that spherical geometry or geodesic algorithms are being used), so that the Earth’s curvature is taken into account — see e.g. here. Note that I just plotted the bare minimum to illustrate what the ‘projectCentered’ function does. Maps can be made to look much nicer — even with just terra + base R plots, with no added package dependencies! ### Share this: * Share on X (Opens in new window) X * Share on Facebook (Opens in new window) Facebook * Like Loading... ### _Related_
modtools.wordpress.com
October 27, 2026 at 12:16 PM
What if #K12 #Education was designed for powerful, engaging learning every day? Check out #NextGenLearningChallenges latest article on schools achieving this, from #ProjectCentered classrooms in ND to #StudentDriven work in CA & ME: bit.ly/4ayHrMI #PBL #LearnerCentered
Your Favorite Learning Experience Charts the Way to a Learning…
What if schools were designed to spark powerful, purposeful, super-engaging, life-enhancing learning all the time, every day?
bit.ly
February 18, 2026 at 8:00 PM
#Education concepts continue to evolve and strengthen http://bit.ly/2sB3ooZ let's add #ProjectCentered #MeasurementBased #Science methods
Is peer feedback the most effective way to teach?
A recent study by the Wall Street Journal shows that coll...
bit.ly
April 7, 2025 at 7:20 AM
#Education concepts continue to evolve and strengthen http://bit.ly/2sB3ooZ let's add #ProjectCentered #MeasurementBased #Science methods
Is peer feedback the most effective way to teach?
A recent study by the Wall Street Journal shows that coll...
bit.ly
April 6, 2025 at 6:52 PM
#Education concepts continue to evolve and strengthen http://bit.ly/2sB3ooZ let's add #ProjectCentered #MeasurementBased #Science methods
Is peer feedback the most effective way to teach?
A recent study by the Wall Street Journal shows that coll...
bit.ly
April 5, 2025 at 11:25 PM
#Education concepts continue to evolve and strengthen http://bit.ly/2sB3ooZ let's add #ProjectCentered #MeasurementBased #Science methods
Is peer feedback the most effective way to teach?
A recent study by the Wall Street Journal shows that coll...
bit.ly
April 5, 2025 at 7:57 AM
#Education concepts continue to evolve and strengthen http://bit.ly/2sB3ooZ let's add #ProjectCentered #MeasurementBased #Science methods
Is peer feedback the most effective way to teach?
A recent study by the Wall Street Journal shows that coll...
bit.ly
April 4, 2025 at 8:04 PM
#Education concepts continue to evolve and strengthen http://bit.ly/2sB3ooZ let's add #ProjectCentered #MeasurementBased #Science methods
Is peer feedback the most effective way to teach?
A recent study by the Wall Street Journal shows that coll...
bit.ly
April 4, 2025 at 6:54 AM
#Education concepts continue to evolve and strengthen http://bit.ly/2sB3ooZ let's add #ProjectCentered #MeasurementBased #Science methods
Is peer feedback the most effective way to teach?
A recent study by the Wall Street Journal shows that coll...
bit.ly
March 31, 2025 at 4:15 PM
#Education concepts continue to evolve and strengthen http://bit.ly/2sB3ooZ let's add #ProjectCentered #MeasurementBased #Science methods
Is peer feedback the most effective way to teach?
A recent study by the Wall Street Journal shows that coll...
bit.ly
March 31, 2025 at 12:35 AM
#Education concepts continue to evolve and strengthen http://bit.ly/2sB3ooZ let's add #ProjectCentered #MeasurementBased #Science methods
Is peer feedback the most effective way to teach?
A recent study by the Wall Street Journal shows that coll...
bit.ly
March 30, 2025 at 10:36 AM
#Education concepts continue to evolve and strengthen http://bit.ly/2sB3ooZ let's add #ProjectCentered #MeasurementBased #Science methods
Is peer feedback the most effective way to teach?
A recent study by the Wall Street Journal shows that coll...
bit.ly
March 29, 2025 at 5:39 PM
#Education concepts continue to evolve and strengthen http://bit.ly/2sB3ooZ let's add #ProjectCentered #MeasurementBased #Science methods
Is peer feedback the most effective way to teach?
A recent study by the Wall Street Journal shows that coll...
bit.ly
March 29, 2025 at 3:20 AM
#Education concepts continue to evolve and strengthen http://bit.ly/2sB3ooZ let's add #ProjectCentered #MeasurementBased #Science methods
Is peer feedback the most effective way to teach?
A recent study by the Wall Street Journal shows that coll...
bit.ly
March 28, 2025 at 1:06 PM
#Education concepts continue to evolve and strengthen http://bit.ly/2sB3ooZ let's add #ProjectCentered #MeasurementBased #Science methods
Is peer feedback the most effective way to teach?
A recent study by the Wall Street Journal shows that coll...
bit.ly
March 27, 2025 at 8:02 PM
#Education concepts continue to evolve and strengthen http://bit.ly/2sB3ooZ let's add #ProjectCentered #MeasurementBased #Science methods
Is peer feedback the most effective way to teach?
A recent study by the Wall Street Journal shows that coll...
bit.ly
March 27, 2025 at 4:52 AM
#Education concepts continue to evolve and strengthen http://bit.ly/2sB3ooZ let's add #ProjectCentered #MeasurementBased #Science methods
Is peer feedback the most effective way to teach?
A recent study by the Wall Street Journal shows that coll...
bit.ly
March 26, 2025 at 1:45 PM
#Education concepts continue to evolve and strengthen http://bit.ly/2sB3ooZ let's add #ProjectCentered #MeasurementBased #Science methods
Is peer feedback the most effective way to teach?
A recent study by the Wall Street Journal shows that coll...
bit.ly
March 25, 2025 at 9:14 PM
#Education concepts continue to evolve and strengthen http://bit.ly/2sB3ooZ let's add #ProjectCentered #MeasurementBased #Science methods
Is peer feedback the most effective way to teach?
A recent study by the Wall Street Journal shows that coll...
bit.ly
March 25, 2025 at 3:58 AM
#Education concepts continue to evolve and strengthen http://bit.ly/2sB3ooZ let's add #ProjectCentered #MeasurementBased #Science methods
Is peer feedback the most effective way to teach?
A recent study by the Wall Street Journal shows that coll...
bit.ly
March 24, 2025 at 7:56 AM
#Education concepts continue to evolve and strengthen http://bit.ly/2sB3ooZ let's add #ProjectCentered #MeasurementBased #Science methods
Is peer feedback the most effective way to teach?
A recent study by the Wall Street Journal shows that coll...
bit.ly
March 23, 2025 at 4:30 AM
#Education concepts continue to evolve and strengthen http://bit.ly/2sB3ooZ let's add #ProjectCentered #MeasurementBased #Science methods
Is peer feedback the most effective way to teach?
A recent study by the Wall Street Journal shows that coll...
bit.ly
March 22, 2025 at 1:18 PM
#Education concepts continue to evolve and strengthen http://bit.ly/2sB3ooZ let's add #ProjectCentered #MeasurementBased #Science methods
Is peer feedback the most effective way to teach?
A recent study by the Wall Street Journal shows that coll...
bit.ly
March 21, 2025 at 6:17 PM
#Education concepts continue to evolve and strengthen http://bit.ly/2sB3ooZ let's add #ProjectCentered #MeasurementBased #Science methods
Is peer feedback the most effective way to teach?
A recent study by the Wall Street Journal shows that coll...
bit.ly
March 20, 2025 at 6:28 AM