【问题标题】:Distance between UTM coordinatesUTM坐标之间的距离
【发布时间】:2021-10-11 08:55:21
【问题描述】:

我在 QGIS 地图上有点,并且想确定 R 中每个点之间的距离。每个唯一 ID 都是一棵树。坐标是 UTM 坐标(x = 东,y = 北)

我的数据集如下所示:

Unique_ID EW_X. EW_Y
45 573500 775011
49 572224 774700
70 573573 775200
71 573573 775200

我会使用什么公式,这样我就可以获得描述每棵树之间距离的输出,如下所示(其中 x 是每棵树之间的距离):

Unique_ID 45 49 70 71
45 x x x
49 x x x
70 x x x
71 x x x

或者如果它更简单,重复行(例如,45 对 49、45 对 70、45 对 71;等等,每次重复都是一个新行)

【问题讨论】:

    标签: r utm


    【解决方案1】:

    使用tidyversesf,要获得以米为单位的距离矩阵,请尝试:

    library(tidyverse)
    library(sf)
    
    df <- tibble(
       Unique_ID = c(45L, 49L, 70L, 71L),
            EW_X = c(573500L, 572224L, 573573L, 573573L),
            EW_Y = c(775011L, 774700L, 775200L, 775200L))
    
    sf_trees <- st_as_sf(x = df, coords = c("EW_X", "EW_Y"),
                         crs = 3857) # Note that I am using WGS 84 Pseudo Mercator. If you know the UTM zone you could be more specific with the csr/epsg code
    tb_distance <- st_distance(sf_trees, sf_trees, ) %>%  # The following 3 lines are optional.
      as_tibble() %>% 
      set_names(nm = df$Unique_ID) %>% 
      bind_cols(tibble(Unique_ID = as.character(df$Unique_ID)), . )
    
    tb_distance
    # A tibble: 4 x 5
      Unique_ID  `45`  `49`  `70`  `71`
      <chr>       [m]   [m]   [m]   [m]
    1 45           0  1313.  203.  203.
    2 49        1313.    0  1439. 1439.
    3 70         203. 1439.    0     0 
    4 71         203. 1439.    0     0 
    

    【讨论】:

      猜你喜欢
      • 2018-04-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-23
      • 1970-01-01
      • 2016-01-23
      • 2021-09-08
      • 2016-10-31
      • 2012-08-06
      相关资源
      最近更新 更多