Error when re-projecting spatial points using spTransform in rgdal R

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

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"

      

Does anyone know why I am getting this error or have any suggestions as to how I can change these coordinates from AGD66 to WGS84? Thank you for your help.

Cheers,
Adam

+3


source to share


1 answer


I have removed part of the wrong answer.

The project () function cannot do data transformations, so you might have a problem and I think you have the wrong one.

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

I think you need this:



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 

      

This means the pts66 do not change from their original values, but they have the metadata correct for the next step that will convert them to your target (this is Lambert Conformal Conic btw). You may need a little more research to figure out what is 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 

      

Your original project () was incorrectly trying to convert from longlat to WGS84 to longlat on AGD66, but this function cannot do that, so it just added confusion to the mix. The date is not a projection, it is a critical part of defining a projection, and in this sense "longlat on AGD66" is a projection, just like "Conformal Conic Lambert on WGS84".

+6


source







All Articles