Search code examples
rggplot2mapscoordinates

map coordinates in R: ggswissmaps


When using ggswissmaps, I get long / lat coordinate that do not match a format that I recognize.

library(ggswissmaps)
data("shp_df")
    
head(shp_df[["g1b15"]]$long)

[1] 679207 680062 679981 680365 680281 680479

head(shp_df[["g1b15"]]$lat)

[1] 245176 244294 244051 243411 241866 241584

What scale could this be? It is neither the long / lat I get from e.g. Google maps, degrees, nor UTM.


Solution

  • It looks like the co-ordinates are given in metres (Northing, Easting), using the Swiss CH1903 / LV03 projection.

    If you want to convert this to standard degrees latitude / longitude, you can do something like this:

    library(ggswissmaps)
    
    data("shp_df")
    
    sw_shp <- split(shp_df[["g1b15"]], shp_df[["g1b15"]]$id) |>
      lapply(function(x) list(as.matrix(subset(x, piece == 1)[1:2]))) |>
      sf::st_multipolygon() |>
      sf::st_sfc(crs = 21781) |>
      sf::st_transform(crs = 'WGS84')
    

    This now gives you a simple features column which is easy to handle. For example, it can be plotted like this:

    plot(sw_shp, axes = TRUE)
    

    enter image description here