【问题标题】:set CRS for latitude longitude point data为经纬度点数据设置 CRS
【发布时间】:2021-09-10 10:09:56
【问题描述】:

我有一些经纬度的点。我想设置 CRS 来计算距离。我试图设置 CRS,但它在 (function (classes, fdef, mtable) 中显示错误“错误: 无法找到签名“CRS”的函数“proj4string”的继承方法

long <- c(133.2982, 132.6715,133.2375,133.3048,133.2594,133.2165)
lat <- c(35.5716,35.3551,35.5504,35.5707,35.5680,35.5708)
lonlat <-data.frame(cbind(long,lat))

pj <- sp::CRS("+proj=longlat +datum=WGS84")

fetch_locs = sp::SpatialPoints(lonlat[,1:2], 
                           sp::CRS(proj4string(pj)))

【问题讨论】:

    标签: r sf sp proj


    【解决方案1】:

    先说几句:

    • 目前不鼓励使用 proj4string,首选 EPSG 代码。
    • 不再支持 proj4string 中的“+datum=”声明, 请改用“+省略号”。
    • 您可能会选择切换到更新的sf 包。

    所以:

    以下是使用旧的 sp 包创建 SpatialPoints 对象的方法:

    library(sp)
    long <- c(133.2982, 132.6715,133.2375,133.3048,133.2594,133.2165)
    lat <- c(35.5716,35.3551,35.5504,35.5707,35.5680,35.5708)
    lonlat <-data.frame(cbind(long,lat))
    
    lonlat_sp = SpatialPoints(coords=lonlat, proj4string=CRS("+proj=longlat +ellips=WGS84"))
    

    下面是使用 sf 包的方法

    library(sf)
    Linking to GEOS 3.9.0, GDAL 3.2.2, PROJ 7.2.1
    lonlat_sf = st_as_sf(lonlat, coords=c("long", "lat"), crs="EPSG:4326")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-05
      • 1970-01-01
      • 2015-09-20
      • 2020-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多