【问题标题】:Reprojecting & CRS of Shapefile using sf Package in R在 R 中使用 sf 包对 Shapefile 进行重投影和 CRS
【发布时间】:2020-06-11 17:49:34
【问题描述】:

我是新的 R 用户。我在 R 中有一个 shapfile,我想用它来计算 K 最近邻。每个多边形的质心(Inside_X 和 Inside_Y)在 arcmap 中计算(示例:X:32570914 Y:5791442)。我使用sf 包为我的坐标获取CRS。理想情况下,我想使用我的 shapefile 的 proj,但它在 R 中似乎无效。下面是我的代码。我的问题是knearneighbor 考虑knearneigh: coordinates are not geographicalst_is_longlat 给出[FALSE] 即使在设置CRS 之后。请帮忙。

>data<- readOGR (dsn = ".", layer ="My_Data")
>summary(data)

    Object of class SpatialPolygonsDataFrame
    Coordinates:
           min      max
    x 32568756 32641426
    y  5723944  5853056
    Is projected: TRUE 
    proj4string :
    [+proj=tmerc +lat_0=0 +lon_0=9 +k=0.9996 +x_0=32500000 +y_0=0 +ellps=GRS80 +units=m +no_defs]
    Data attributes:


>data.sf <- st_as_sf(data)


## Set CRS
>data.crs <- st_transform(data.sf, crs = 4839)
>st_crs(data.crs)

data.coord <- cbind(data.crs$INSIDE_X, data.crs$INSIDE_Y)

## K Nearest neighbor
>library(spdep)
>data.knn <- knearneigh(data.coord, k = 10, longlat = TRUE)

Warning message:
In knearneigh(data.coord, k = 10, longlat = TRUE) :
  knearneigh: coordinates are not geographical: longlat argument wrong

【问题讨论】:

  • 这是一个警告,您有longlat=TRUE,但您的坐标NOT 以经纬度为单位,因为它们是EPSG :4839。这在 knearneigh 的帮助中都有解释。

标签: r coordinates coordinate-systems coordinate-transformation sf


【解决方案1】:

使用 EPSG 4326 代替 4839,4839 是项目https://epsg.io/4839

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-17
    • 1970-01-01
    • 2016-08-27
    • 1970-01-01
    • 2021-05-15
    • 2021-02-12
    • 2014-10-07
    • 2020-07-25
    相关资源
    最近更新 更多