代码之家  ›  专栏  ›  技术社区  ›  JonasEngstrom

如何使用R将地图坐标从SWEREF99 TM转换为WGS84?

  •  0
  • JonasEngstrom  · 技术社区  · 1 年前

    我正在尝试使用 sf 用于R的软件包,用于从坐标参考系统转换坐标North 6855790,East 557541 SWEREF99 TM WGS84 以及预期输出北61.830576°,东16.092562°(以十进制表示,或北61°49 50,07,东16°5 33,22,以度、分和秒表示,尽管我更喜欢十进制) this website 然而,我正在向北64.54803°,向东3.262454°。

    SWEREF99 TM和WGS84的EPSG代码应为 3006 4326 据我所知。

    对于上下文:我计划使用 dplyr ,一旦它工作,所以使用上面提到的转换网站是不现实的。替代解决方案,不使用 sf 一揽子计划也会奏效。

    我做错了什么?

    我尝试过:

    # This part’s here for reproducibility.
    # Ignore it if you already have sf installed
    chooseCRANmirror(ind=1)
    install.packages('sf')
    
    # The actual code.
    library(sf)
    data.frame(x = 6855790, y = 557541) |>
      st_as_sf(coords = c('x', 'y')) |>
      st_set_crs(3006) |>
      st_transform(4326)
    

    这给了我以下输出:

    ## Simple feature collection with 1 feature and 0 fields
    ## Geometry type: POINT
    ## Dimension:     XY
    ## Bounding box:  xmin: 64.54803 ymin: 3.262454 xmax: 64.54803 ymax: 3.262454
    ## Geodetic CRS:  WGS 84
    ##                    geometry
    ## 1 POINT (64.54803 3.262454)
    

    我在发布之前搜索了论坛。例如 this post 类似,但使用包 rdal 哪一个 is no longer on CRAN as of October 16, 2023

    1 回复  |  直到 1 年前
        1
  •  2
  •   Friede    1 年前

    开关值

    library(sf)
    #> Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
    data.frame(x = 557541, y = 6855790) |>
      st_as_sf(coords = c('x', 'y')) |>
      st_set_crs(3006) |>
      st_transform(4326)
    #> Simple feature collection with 1 feature and 0 fields
    #> Geometry type: POINT
    #> Dimension:     XY
    #> Bounding box:  xmin: 16.09256 ymin: 61.83058 xmax: 16.09256 ymax: 61.83058
    #> Geodetic CRS:  WGS 84
    #>                    geometry
    #> 1 POINT (16.09256 61.83058)
    

    这就是 c("longitude", "latitude") 。 看起来很有希望

    library(rnaturalearth)
    library(ggplot2)
    library(sf)
    
    data.frame(x = 557541, y = 6855790) |>
      st_as_sf(coords = c('x', 'y')) |>
      st_set_crs(3006) |>
      st_transform(4326) -> pt
    
    swe <- ne_countries(country = "sweden", scale = "large", returnclass = "sf")
    
    ggplot(data = swe) +
      geom_sf() +
      geom_sf(data = pt)
    

    enter image description here

    创建于2023-10-20 reprex v2.0.2