tests/testthat/test_crs_ew_extent.R

# styler: off

test_that("test ew extent", {
  # CONFORMAL
  # conic projection
  suggested_crs_ew_conic <- suggest_crs(c(25, 76, 48, 56), distortion = "conformal")
  ref_proj4_ew_conic <- "+proj=lcc +lon_0=50.5 +lat_1=49.3333333 +lat_2=54.6666667 +lat_0=52 +datum=WGS84 +units=m +no_defs"
  ref_wkt_ew_conic <- 'PROJCS["ProjWiz_Custom_Lambert_Conformal_Conic",
                             GEOGCS["GCS_WGS_1984",
                                    DATUM["D_WGS_1984",
                                          SPHEROID["WGS_1984",6378137.0,298.257223563]],
                                    PRIMEM["Greenwich",0.0],
                                    UNIT["Degree",0.0174532925199433]],
                             PROJECTION["Lambert_Conformal_Conic"],
                             PARAMETER["False_Easting",0.0],
                             PARAMETER["False_Northing",0.0],
                             PARAMETER["Central_Meridian",50.5],
                             PARAMETER["Standard_Parallel_1",49.3333333],
                             PARAMETER["Standard_Parallel_2",54.6666667],
                             PARAMETER["Latitude_Of_Origin",52],
                             UNIT["Meter",1.0]]'
  expect_equal(suggested_crs_ew_conic$proj4, ref_proj4_ew_conic)
  expect_true(sf::st_crs(suggested_crs_ew_conic$wkt) == sf::st_crs(ref_wkt_ew_conic))

  # Mercator projection
  expect_message(suggested_crs_ew_mercator <- suggest_crs(c(-13, 37, 8, 16), distortion = "conformal"),
                 "To reduce overall area distortion on the map")
  ref_proj4_ew_mercator <- "+proj=merc +lon_0=12 +lat_ts=12 +datum=WGS84 +units=m +no_defs"
  ref_wkt_ew_mercator <- 'PROJCS["ProjWiz_Custom_Mercator",
                                GEOGCS["GCS_WGS_1984",
                                       DATUM["D_WGS_1984",
                                             SPHEROID["WGS_1984",6378137.0,298.257223563]],
                                       PRIMEM["Greenwich",0.0],
                                       UNIT["Degree",0.0174532925199433]],
                                PROJECTION["Mercator"],
                                PARAMETER["False_Easting",0.0],
                                PARAMETER["False_Northing",0.0],
                                PARAMETER["Central_Meridian",12],
                                PARAMETER["Standard_Parallel_1",12],
                                UNIT["Meter",1.0]]'
  expect_equal(suggested_crs_ew_mercator$proj4, ref_proj4_ew_mercator)
  expect_true(sf::st_crs(suggested_crs_ew_mercator$wkt) == sf::st_crs(ref_wkt_ew_mercator))

  # Lambert conformal
  expect_message(suggested_crs_ew_lcc <- suggest_crs(c(-69, -48, -26, -19), distortion = "conformal"),
                 "For maps at this scale")
  ref_proj4_ew_lcc <- "+proj=lcc +lon_0=-58.5 +lat_1=-24.8333333 +lat_2=-20.1666667 +lat_0=-22.5 +datum=WGS84 +units=m +no_defs"
  ref_wkt_ew_lcc <- 'PROJCS["ProjWiz_Custom_Lambert_Conformal_Conic",
                           GEOGCS["GCS_WGS_1984",
                                  DATUM["D_WGS_1984",
                                        SPHEROID["WGS_1984",6378137.0,298.257223563]],
                                  PRIMEM["Greenwich",0.0],
                                  UNIT["Degree",0.0174532925199433]],
                           PROJECTION["Lambert_Conformal_Conic"],
                           PARAMETER["False_Easting",0.0],
                           PARAMETER["False_Northing",0.0],
                           PARAMETER["Central_Meridian",-58.5],
                           PARAMETER["Standard_Parallel_1",-24.8333333],
                           PARAMETER["Standard_Parallel_2",-20.1666667],
                           PARAMETER["Latitude_Of_Origin",-22.5],
                           UNIT["Meter",1.0]]'
  expect_equal(suggested_crs_ew_lcc$proj4, ref_proj4_ew_lcc)
  expect_true(sf::st_crs(suggested_crs_ew_lcc$wkt) == sf::st_crs(ref_wkt_ew_lcc))

  # Polar stereographic (north)
  message <- capture_messages(suggested_crs_ew_ps <- suggest_crs(c(6, 35, 75, 81), distortion = "conformal"))
  ref_proj4_ew_ps <- "+proj=stere +lon_0=20.5 +lat_0=90 +datum=WGS84 +units=m +no_defs"
  ref_wkt_ew_ps <- 'PROJCS["ProjWiz_Custom_Stereographic",
                          GEOGCS["GCS_WGS_1984",
                                 DATUM["D_WGS_1984",
                                       SPHEROID["WGS_1984",6378137.0,298.257223563]],
                                 PRIMEM["Greenwich",0.0],
                                 UNIT["Degree",0.0174532925199433]],
                          PROJECTION["Stereographic"],
                          PARAMETER["False_Easting",0.0],
                          PARAMETER["False_Northing",0.0],
                          PARAMETER["Central_Meridian",20.5],
                          PARAMETER["Scale_Factor",1.0],
                          PARAMETER["Latitude_Of_Origin",90],
                          UNIT["Meter",1.0]]'
  expect_equal(suggested_crs_ew_ps$proj4, ref_proj4_ew_ps)
  expect_true(sf::st_crs(suggested_crs_ew_ps$wkt) == sf::st_crs(ref_wkt_ew_ps))
  ### check messages
  expect_true(any(grepl("To reduce overall area distortion on the map", message)))
  expect_true(any(grepl("For maps at this scale", message)))

  # Polar stereographic (south)
  message <- capture_messages(suggested_crs_ew_ps <- suggest_crs(c(6, 35, -81, -75), distortion = "conformal"))
  ref_proj4_ew_ps <- "+proj=stere +lon_0=20.5 +lat_0=-90 +datum=WGS84 +units=m +no_defs"
  ref_wkt_ew_ps <- 'PROJCS["ProjWiz_Custom_Stereographic",
                          GEOGCS["GCS_WGS_1984",
                                 DATUM["D_WGS_1984",
                                       SPHEROID["WGS_1984",6378137.0,298.257223563]],
                                 PRIMEM["Greenwich",0.0],
                                 UNIT["Degree",0.0174532925199433]],
                          PROJECTION["Stereographic"],
                          PARAMETER["False_Easting",0.0],
                          PARAMETER["False_Northing",0.0],
                          PARAMETER["Central_Meridian",20.5],
                          PARAMETER["Scale_Factor",1.0],
                          PARAMETER["Latitude_Of_Origin",-90],
                          UNIT["Meter",1.0]]'
  expect_equal(suggested_crs_ew_ps$proj4, ref_proj4_ew_ps)
  expect_true(sf::st_crs(suggested_crs_ew_ps$wkt) == sf::st_crs(ref_wkt_ew_ps))
  ### check messages
  expect_true(any(grepl("To reduce overall area distortion on the map", message)))
  expect_true(any(grepl("For maps at this scale", message)))

  # Polar stereographic (south, negative conic)
  expect_message(suggested_crs_ew_ps <- suggest_crs(c(-126, 90, -77, -57), distortion = "conformal"),
                 "To reduce overall area distortion on the map")
  ref_proj4_ew_ps <- "+proj=stere +lon_0=-18 +lat_0=-90 +datum=WGS84 +units=m +no_defs"
  ref_wkt_ew_ps <- 'PROJCS["ProjWiz_Custom_Stereographic",
                            GEOGCS["GCS_WGS_1984",
                                   DATUM["D_WGS_1984",
                                         SPHEROID["WGS_1984",6378137.0,298.257223563]],
                                   PRIMEM["Greenwich",0.0],
                                   UNIT["Degree",0.0174532925199433]],
                            PROJECTION["Stereographic"],
                            PARAMETER["False_Easting",0.0],
                            PARAMETER["False_Northing",0.0],
                            PARAMETER["Central_Meridian",-18],
                            PARAMETER["Scale_Factor",1.0],
                            PARAMETER["Latitude_Of_Origin",-90],
                            UNIT["Meter",1.0]]'
  expect_equal(suggested_crs_ew_ps$proj4, ref_proj4_ew_ps)
  expect_true(sf::st_crs(suggested_crs_ew_ps$wkt) == sf::st_crs(ref_wkt_ew_ps))

  # Polar stereographic (north, negative conic)
  expect_message(suggested_crs_ew_ps <- suggest_crs(c(-126, 90, 57, 77), distortion = "conformal"),
                 "To reduce overall area distortion on the map")
  ref_proj4_ew_ps <- "+proj=stere +lon_0=-18 +lat_0=90 +datum=WGS84 +units=m +no_defs"
  ref_wkt_ew_ps <- 'PROJCS["ProjWiz_Custom_Stereographic",
                            GEOGCS["GCS_WGS_1984",
                                   DATUM["D_WGS_1984",
                                         SPHEROID["WGS_1984",6378137.0,298.257223563]],
                                   PRIMEM["Greenwich",0.0],
                                   UNIT["Degree",0.0174532925199433]],
                            PROJECTION["Stereographic"],
                            PARAMETER["False_Easting",0.0],
                            PARAMETER["False_Northing",0.0],
                            PARAMETER["Central_Meridian",-18],
                            PARAMETER["Scale_Factor",1.0],
                            PARAMETER["Latitude_Of_Origin",90],
                            UNIT["Meter",1.0]]'
  expect_equal(suggested_crs_ew_ps$proj4, ref_proj4_ew_ps)
  expect_true(sf::st_crs(suggested_crs_ew_ps$wkt) == sf::st_crs(ref_wkt_ew_ps))



  # EQUAL AREA
  # Albers equal area
  suggested_crs_ew_eql <- suggest_crs(c(25, 76, 48, 56), distortion = "equal_area")
  ref_proj4_ew_eql <- "+proj=aea +lon_0=50.5 +lat_1=49.3333333 +lat_2=54.6666667 +lat_0=52 +datum=WGS84 +units=m +no_defs"
  ref_wkt_ew_eql <- 'PROJCS["ProjWiz_Custom_Albers",
                             GEOGCS["GCS_WGS_1984",
                                    DATUM["D_WGS_1984",
                                          SPHEROID["WGS_1984",6378137.0,298.257223563]],
                                    PRIMEM["Greenwich",0.0],
                                    UNIT["Degree",0.0174532925199433]],
                             PROJECTION["Albers"],
                             PARAMETER["False_Easting",0.0],
                             PARAMETER["False_Northing",0.0],
                             PARAMETER["Central_Meridian",50.5],
                             PARAMETER["Standard_Parallel_1",49.3333333],
                             PARAMETER["Standard_Parallel_2",54.6666667],
                             PARAMETER["Latitude_Of_Origin",52],
                             UNIT["Meter",1.0]]'
  expect_equal(suggested_crs_ew_eql$proj4, ref_proj4_ew_eql)
  expect_true(sf::st_crs(suggested_crs_ew_eql$wkt) == sf::st_crs(ref_wkt_ew_eql))

  # Polar Lambert equal area (north)
  expect_message(suggested_crs_ew_pole <- suggest_crs(c(6, 35, 75, 81), distortion = "equal_area"),
                 "For maps at this scale")
  ref_proj4_ew_pole <- "+proj=laea +lon_0=20.5 +lat_0=90 +datum=WGS84 +units=m +no_defs"
  ref_wkt_ew_pole <- 'PROJCS["ProjWiz_Custom_Lambert_Azimuthal",
                            GEOGCS["GCS_WGS_1984",
                                   DATUM["D_WGS_1984",
                                         SPHEROID["WGS_1984",6378137.0,298.257223563]],
                                   PRIMEM["Greenwich",0.0],
                                   UNIT["Degree",0.0174532925199433]],
                            PROJECTION["Lambert_Azimuthal_Equal_Area"],
                            PARAMETER["False_Easting",0.0],
                            PARAMETER["False_Northing",0.0],
                            PARAMETER["Central_Meridian",20.5],
                            PARAMETER["Latitude_Of_Origin",90],
                            UNIT["Meter",1.0]]'
  expect_equal(suggested_crs_ew_pole$proj4, ref_proj4_ew_pole)
  expect_true(sf::st_crs(suggested_crs_ew_pole$wkt) == sf::st_crs(ref_wkt_ew_pole))

  # Polar Lambert equal area (south)
  expect_message(suggested_crs_ew_pole <- suggest_crs(c(6, 35, -81, -75), distortion = "equal_area"),
                 "For maps at this scale")
  ref_proj4_ew_pole <- "+proj=laea +lon_0=20.5 +lat_0=-90 +datum=WGS84 +units=m +no_defs"
  ref_wkt_ew_pole <- 'PROJCS["ProjWiz_Custom_Lambert_Azimuthal",
                            GEOGCS["GCS_WGS_1984",
                                   DATUM["D_WGS_1984",
                                         SPHEROID["WGS_1984",6378137.0,298.257223563]],
                                   PRIMEM["Greenwich",0.0],
                                   UNIT["Degree",0.0174532925199433]],
                            PROJECTION["Lambert_Azimuthal_Equal_Area"],
                            PARAMETER["False_Easting",0.0],
                            PARAMETER["False_Northing",0.0],
                            PARAMETER["Central_Meridian",20.5],
                            PARAMETER["Latitude_Of_Origin",-90],
                            UNIT["Meter",1.0]]'
  expect_equal(suggested_crs_ew_pole$proj4, ref_proj4_ew_pole)
  expect_true(sf::st_crs(suggested_crs_ew_pole$wkt) == sf::st_crs(ref_wkt_ew_pole))

  # Cylindrical
  expect_message(suggested_crs_cyl <- suggest_crs(c(25, 45, 3, 8), distortion = "equal_area"),
                 "For maps at this scale")
  ref_proj4_cyl <- "+proj=cea +lon_0=35 +lat_ts=5.5 +datum=WGS84 +units=m +no_defs"
  ref_wkt_cyl <- 'PROJCS["ProjWiz_Custom_Cylindrical_Equal_Area",
                        GEOGCS["GCS_WGS_1984",
                               DATUM["D_WGS_1984",
                                     SPHEROID["WGS_1984",6378137.0,298.257223563]],
                               PRIMEM["Greenwich",0.0],
                               UNIT["Degree",0.0174532925199433]],
                        PROJECTION["Cylindrical_Equal_Area"],
                        PARAMETER["False_Easting",0.0],
                        PARAMETER["False_Northing",0.0],
                        PARAMETER["Central_Meridian",35],
                        PARAMETER["Standard_Parallel_1",5.5],
                        UNIT["Meter",1.0]]'
  expect_equal(suggested_crs_cyl$proj4, ref_proj4_cyl)
  expect_true(sf::st_crs(suggested_crs_cyl$wkt) == sf::st_crs(ref_wkt_cyl))

  # Oblique Lambert azimuthal equal-area
  suggested_crs_ew_obl <- suggest_crs(c(-157, 20, -56, -45), distortion = "equal_area")
  ref_proj4_ew_obl <- "+proj=laea +lon_0=-68.5 +lat_0=-50.5 +datum=WGS84 +units=m +no_defs"
  ref_wkt_ew_obl <- 'PROJCS["ProjWiz_Custom_Lambert_Azimuthal",
 GEOGCS["GCS_WGS_1984",
  DATUM["D_WGS_1984",
   SPHEROID["WGS_1984",6378137.0,298.257223563]],
  PRIMEM["Greenwich",0.0],
  UNIT["Degree",0.0174532925199433]],
 PROJECTION["Lambert_Azimuthal_Equal_Area"],
 PARAMETER["False_Easting",0.0],
 PARAMETER["False_Northing",0.0],
 PARAMETER["Central_Meridian",-68.5],
 PARAMETER["Latitude_Of_Origin",-50.5],
 UNIT["Meter",1.0]]'
  expect_equal(suggested_crs_ew_obl$proj4, ref_proj4_ew_obl)
  expect_true(sf::st_crs(suggested_crs_ew_obl$wkt) == sf::st_crs(ref_wkt_ew_obl))

  # Albers equal-area conic
  suggested_crs_ew_alb <- suggest_crs(c(-112, 105, -34, -14), distortion = "equal_area")
  ref_proj4_ew_alb <- "+proj=aea +lon_0=-3.5 +lat_1=-30.6666667 +lat_2=-17.3333333 +lat_0=-24 +datum=WGS84 +units=m +no_defs"
  ref_wkt_ew_alb <- 'PROJCS["ProjWiz_Custom_Albers",
                           GEOGCS["GCS_WGS_1984",
                                  DATUM["D_WGS_1984",
                                        SPHEROID["WGS_1984",6378137.0,298.257223563]],
                                  PRIMEM["Greenwich",0.0],
                                  UNIT["Degree",0.0174532925199433]],
                           PROJECTION["Albers"],
                           PARAMETER["False_Easting",0.0],
                           PARAMETER["False_Northing",0.0],
                           PARAMETER["Central_Meridian",-3.5],
                           PARAMETER["Standard_Parallel_1",-30.6666667],
                           PARAMETER["Standard_Parallel_2",-17.3333333],
                           PARAMETER["Latitude_Of_Origin",-24],
                           UNIT["Meter",1.0]]'
  expect_equal(suggested_crs_ew_alb$proj4, ref_proj4_ew_alb)
  expect_true(sf::st_crs(suggested_crs_ew_alb$wkt) == sf::st_crs(ref_wkt_ew_alb))

  # Polar Lambert azimuthal (south, negative conic)
  suggested_crs_ew_pole <- suggest_crs(c(-126, 90, -77, -57), distortion = "equal_area")
  ref_proj4_ew_pole <- "+proj=laea +lon_0=-18 +lat_0=-90 +datum=WGS84 +units=m +no_defs"
  ref_wkt_ew_pole <- 'PROJCS["ProjWiz_Custom_Lambert_Azimuthal",
                            GEOGCS["GCS_WGS_1984",
                                   DATUM["D_WGS_1984",
                                         SPHEROID["WGS_1984",6378137.0,298.257223563]],
                                   PRIMEM["Greenwich",0.0],
                                   UNIT["Degree",0.0174532925199433]],
                            PROJECTION["Lambert_Azimuthal_Equal_Area"],
                            PARAMETER["False_Easting",0.0],
                            PARAMETER["False_Northing",0.0],
                            PARAMETER["Central_Meridian",-18],
                            PARAMETER["Latitude_Of_Origin",-90],
                            UNIT["Meter",1.0]]'
  expect_equal(suggested_crs_ew_pole$proj4, ref_proj4_ew_pole)
  expect_true(sf::st_crs(suggested_crs_ew_pole$wkt) == sf::st_crs(ref_wkt_ew_pole))

  # Polar Lambert azimuthal (north, negative conic)
  suggested_crs_ew_pole <- suggest_crs(c(-126, 90, 57, 77), distortion = "equal_area")
  ref_proj4_ew_pole <- "+proj=laea +lon_0=-18 +lat_0=90 +datum=WGS84 +units=m +no_defs"
  ref_wkt_ew_pole <- 'PROJCS["ProjWiz_Custom_Lambert_Azimuthal",
                            GEOGCS["GCS_WGS_1984",
                                   DATUM["D_WGS_1984",
                                         SPHEROID["WGS_1984",6378137.0,298.257223563]],
                                   PRIMEM["Greenwich",0.0],
                                   UNIT["Degree",0.0174532925199433]],
                            PROJECTION["Lambert_Azimuthal_Equal_Area"],
                            PARAMETER["False_Easting",0.0],
                            PARAMETER["False_Northing",0.0],
                            PARAMETER["Central_Meridian",-18],
                            PARAMETER["Latitude_Of_Origin",90],
                            UNIT["Meter",1.0]]'
  expect_equal(suggested_crs_ew_pole$proj4, ref_proj4_ew_pole)
  expect_true(sf::st_crs(suggested_crs_ew_pole$wkt) == sf::st_crs(ref_wkt_ew_pole))

})

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.