R/helpers.R

Defines functions round_world_coords normalise_lon

################################################################################
# Normalizing longitude values
normalise_lon <- function(lon, lon0) {
  while (lon < (lon0 - 180.0)) {
    lon <- lon + 360.0
  }
  while (lon > (lon0 + 180.0)) {
    lon <- lon - 360.0
  }
  return(lon)
}

################################################################################
# Function to round values for world maps
round_world_coords <- function(value, scale, round_cm) {
  val <- NULL

  if (round_cm || scale < 1.15) {
    val <- round(value)
  } else if (scale < 1.32) {
    val <- round(value * 2) / 2
  } else {
    val <- round(value * 10) / 10
  }

  return(val)
}

Try the crstools package in your browser

Any scripts or data that you put into this service are public.

crstools documentation built on March 19, 2026, 5:08 p.m.