【问题标题】:mutate lat/long coordinates to UTM in a pipe R在管道 R 中将纬度/经度坐标变异为 UTM
【发布时间】:2020-12-02 14:42:41
【问题描述】:

我有一个海岸线空间值的 df,但它们是纬度/经度,我需要它们位于 NAD83 / UTM 区域 10N。我可以通过在 dplyr 管道中进行变异来做到这一点吗?

testdf <- data.frame(long = c(-124.0048, -123.9844, -123.9691, -123.9604, -123.9810, -123.9612),
                   lat = c(45.04352, 45.10493, 45.20530, 45.29999, 45.34960, 45.40917))


testdf %>% mutate(utm = rgdal::project(c(lon,lat), proj = ???),
# but then I guess I would need to separate the utm column into x and y still.

或者可能是map()

编辑:对不起,我现在意识到这是一个不好的代表。实际数据集有投影+proj=longlat +datum=WGS84 +no_defs。现在正在将其编辑到testdf

【问题讨论】:

    标签: r dplyr coordinates spatial utm


    【解决方案1】:

    您可以使用sf 包:

    library(sf)
    #> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
    testdf <- data.frame(long = c(-124.0048, -123.9844, -123.9691, -123.9604, -123.9810, -123.9612),
                         lat = c(45.04352, 45.10493, 45.20530, 45.29999, 45.34960, 45.40917))
    
    testsf = st_as_sf(testdf, coords = c("long", "lat"))
    testsf <- st_set_crs(testsf, "+proj=longlat +datum=WGS84") 
    testsf 
    #> Simple feature collection with 6 features and 0 fields
    #> geometry type:  POINT
    #> dimension:      XY
    #> bbox:           xmin: -124.0048 ymin: 45.04352 xmax: -123.9604 ymax: 45.40917
    #> CRS:            +proj=longlat +datum=WGS84
    #>                     geometry
    #> 1 POINT (-124.0048 45.04352)
    #> 2 POINT (-123.9844 45.10493)
    #> 3  POINT (-123.9691 45.2053)
    #> 4 POINT (-123.9604 45.29999)
    #> 5   POINT (-123.981 45.3496)
    #> 6 POINT (-123.9612 45.40917)
    
    utmsf <- st_transform(testsf,"+proj=utm +zone=10 +ellps=GRS80 +datum=NAD83" )
    utmsf
    #> Simple feature collection with 6 features and 0 fields
    #> geometry type:  POINT
    #> dimension:      XY
    #> bbox:           xmin: 420866.4 ymin: 4988276 xmax: 424783.9 ymax: 5028855
    #> CRS:            +proj=utm +zone=10 +ellps=GRS80 +datum=NAD83
    #>                   geometry
    #> 1 POINT (420866.4 4988276)
    #> 2   POINT (422556 4995078)
    #> 3 POINT (423893.4 5006214)
    #> 4 POINT (424701.9 5016725)
    #> 5 POINT (423153.9 5022256)
    #> 6 POINT (424783.9 5028855)
    

    reprex package (v0.3.0) 于 2020-08-12 创建

    关联的管道是:

    library(dplyr)
    testdf %>% st_as_sf(coords = c("long", "lat")) %>%
               st_set_crs("+proj=longlat +datum=WGS84") %>%
               st_transform("+proj=utm +zone=10 +ellps=GRS80 +datum=NAD83" )
    

    【讨论】:

      猜你喜欢
      • 2021-07-18
      • 2015-07-13
      • 2013-02-14
      • 2011-02-11
      • 1970-01-01
      • 2016-07-30
      • 2021-07-31
      • 2016-06-19
      • 2018-04-01
      相关资源
      最近更新 更多