在 rgdal R 中使用 spTransform 重新投影空间点时出错 [英] Error when re-projecting spatial points using spTransform in rgdal R

查看:62
本文介绍了在 rgdal R 中使用 spTransform 重新投影空间点时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,
我在 CRS 澳大利亚大地基准 66/84(为简洁起见为 AGD66)中有大量经纬度坐标.我想将这些坐标从 AGD66 更改为 WGS84,因为它们之间有大约 200 米的差异,并且我在 WGS84 中有其他坐标和图层.我试图通过以下方式做到这一点:

G'day,
I have a large number of lon/lat coordinates that are in the CRS Australian Geodetic Datum 66/84 (AGD66 for brevity). I want to change these coordinates from AGD66 to WGS84 because there is about a 200m difference between them and I have other coordinates and layers in WGS84. I have tried to do this by:

lon        lat
147.1428   -43.49083

library(rgdal)
pts<-read.table(file.choose(),header=TRUE,sep=',')  
# I first project the pts in their original CRS
pts66<-project(cbind(pts$lon,pts$lat), "+init=epsg:4202")
# Then to transform it to WGS84
pts84 = spTransform(pts66,CRS("+init=epsg:3033"))

Error in function (classes, fdef, mtable)  : 
unable to find an inherited method for function "spTransform", for signature "matrix", "CRS"

有谁知道我为什么会收到此错误,或者对如何将这些坐标从 AGD66 更改为 WGS84 有任何建议?提前感谢您的帮助.

Does anyone know why I get this error or have any suggestions for how I can change these coordinates from AGD66 to WGS84? Thanks for your help in advance.

干杯,
亚当

推荐答案

我删除了部分错误答案.

函数 project() 无法进行数据转换,因此您可能在那里遇到问题,我认为您所拥有的内容是错误的.

The function project() cannot do datum conversions so you may have a problem there and I think what you have is wrong.

问题是你只能在WGS84上project() from/to longlat,所以你第一次使用project是不正确的.如果我猜对了,您的坐标在 AGD66 中,因此您必须首先分配该投影,然后才能进行转换.您不能使用 project() 进行基准转换,但 spTransform() 可以.

The problem is that you can only project() from/to longlat on WGS84, so your first use of project is incorrect. If I guess this right, you have coordinates that are in AGD66 so you must first assign that projection and then you can transform. You cannot do datum transformations with project(), but spTransform() can.

我认为你需要这个:

pts = read.table(text = "lon        lat
147.1428   -43.49083", header = TRUE)

## assign original coordinate system
pts66 = SpatialPoints(cbind(pts$lon,pts$lat), CRS("+init=epsg:4202"))

## Then to transform it to WGS84
pts84 = spTransform(pts66, CRS("+init=epsg:3033"))


pts66
SpatialPoints:
     coords.x1 coords.x2
[1,]  147.1428 -43.49083
Coordinate Reference System (CRS) arguments: +init=epsg:4202 +proj=longlat +ellps=aust_SA
+no_defs 

pts84
SpatialPoints:
     coords.x1 coords.x2
[1,]  11126605   2971806
Coordinate Reference System (CRS) arguments: +init=epsg:3033 +proj=lcc +lat_1=-68.5     +lat_2=-74.5
+lat_0=-50 +lon_0=70 +x_0=6000000 +y_0=6000000 +ellps=WGS84 +datum=WGS84 +units=m +no_defs
+towgs84=0,0,0 

这意味着 pts66 不会改变它们的原始值,但它们具有正确的元数据,可用于下一步将它们转换为您的目标(顺便说一句,Lambert Conformal Conic).您可能需要进行更多调查才能弄清楚需要什么.

This means that pts66 are not changed from their original values, but they have the metadata correct for the next step which transforms them to your target (which is Lambert Conformal Conic btw). You might need a bit more investigation to figure out what's required.

CRS("+init=epsg:4202")
CRS arguments:
+init=epsg:4202 +proj=longlat +ellps=aust_SA +no_defs 

CRS("+init=epsg:3033")

CRS arguments:
+init=epsg:3033 +proj=lcc +lat_1=-68.5 +lat_2=-74.5 +lat_0=-50
+lon_0=70 +x_0=6000000 +y_0=6000000 +ellps=WGS84 +datum=WGS84 +units=m
+no_defs +towgs84=0,0,0 

您的原始 project() 错误地尝试从 WGS84 上的 longlat 转换为 AGD66 上的 longlat,但该函数无法做到这一点,因此它只是在混合中增加了混乱.基准面不是投影,它是投影定义的关键部分,从这个意义上说,AGD66 上的 longlat"是一种投影,就像WGS84 上的 Lambert Conformal Conic"一样.

Your original project() was incorrectly attempting to transform from longlat on WGS84 to longlat on AGD66, but that function cannot do that so it's just added confusion in the mix. A datum is not a projection, it is a critical part of a projection's definition and in this sense "longlat on AGD66" is a projection just as "Lambert Conformal Conic on WGS84" is.

这篇关于在 rgdal R 中使用 spTransform 重新投影空间点时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆