【问题标题】:data projection in R using package SP使用包 SP 在 R 中进行数据投影
【发布时间】:2016-08-27 12:10:06
【问题描述】:

我在尝试将我的 GPS 数据投影到 R 时有点卡住了。

我正在阅读 R 包“T-LoCoH”的小插图中的教程,并使用这些说明尝试将我的数据从 WGS84 投影到 UTM37(埃塞俄比亚区域)。

我的数据集名为“d”,坐标位于名为“经度”和“纬度”的列中。

require(sp)

head(d)
  Latitude Longitude
1  6.36933  39.84300
2  6.37050  39.84417
3  6.41733  39.83800
4  6.41750  39.83800
5  6.41717  39.83750
6  6.41767  39.83733

d2 <- SpatialPoints(d, proj4string=CRS("+proj=longlat, ellps=WGS84"))
Error in CRS("+proj=longlat \nellps=WGS84") : unknown projection id

你能告诉我我做错了什么吗?

另外,如果我的数据集中有更多列,如何指定我只想将数据投影到包含纬度和经度的 2 列中?

非常感谢您的帮助。

谢谢, 林迪

【问题讨论】:

  • 你需要使用 spTransform()
  • @MLavoie 是的,一旦您使用正确的 CRS 获得数据!

标签: r utm wgs84


【解决方案1】:

代替:

> d2 <- SpatialPoints(d, proj4string=CRS("+proj=longlat, ellps=WGS84"))
Error in CRS("+proj=longlat, ellps=WGS84") : unknown projection id

你需要:

> d2 <- SpatialPoints(d, proj4string=CRS("+proj=longlat +ellps=WGS84"))

但最好使用 epsg 代码作为 GPS 坐标:

> d2 <- SpatialPoints(d, proj4string=CRS("+init=epsg:4326"))

这是这个的简写:

Coordinate Reference System (CRS) arguments: +init=epsg:4326
+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 

如果你只想传递两列,你可以这样做:

> d2 <- SpatialPoints(d[,c("Longitude","Latitude")], proj4string=CRS("+init=epsg:4326"))

这让我认为您可能应该以其他顺序使用 X 和 Y 坐标。您可以使用任何其他方法来选择数据框列,因此如果您的经纬度在第 7 列和第 23 列中,那么d[,c(23,7)] 会这样做。

【讨论】:

    【解决方案2】:

    您可以使用 PBSmapping 库为您执行此操作。

    require(PBSmapping)
    
    # re-create your data
    d = as.data.frame(list(Latitude = c(6.36933,6.37050,6.41733,
                                    6.41750,6.41717,6.41767),
                       Longitude = c(39.84300,39.84417,39.83800,
                                     39.83800,39.83750,39.83733)))
    
    # convUL function requires columns to be called "X" and "Y"
    dataLL=as.data.frame(list(X=d$Longitude,Y=d$Latitude))
    
    # add a projection attribute (see details in ?convUL)
    attr(dataLL,"projection")="LL"
    
    # create a new data frame called dataUTM
    dataUTM=convUL(dataLL,km=F)
    
    # output from running previous command
    convUL: For the UTM conversion, automatically detected zone 37.
    convUL: Converting coordinates within the northern hemisphere.
    
    # extract UTM zone
    attr(dataUTM,"zone")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-11
      • 2021-08-29
      • 2019-04-10
      • 1970-01-01
      • 1970-01-01
      • 2012-04-24
      • 2017-07-03
      • 2013-06-07
      相关资源
      最近更新 更多