I imported my shapefile dat to R with readOGR, coordinates are given in easting and northing, I'd like to change it to latlon and tried:
dat_latlon <- spTransform(dat, CRS("+proj=longlat +datum=WGS84"))
However, I get this error message:
Error in spTransform(xSP, CRSobj, ...) :
No transformation possible from NA reference system
And str(dat) shows that:
..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
.. .. ..@ projargs: chr NA
So I guess I have to assign the projection first? Somewhere here (or stackoverflow) I found this:
dat@proj4string <- "+proj=tmerc +lat_0=0 +lon_0=9 +k=1 +x_0=3500000 +y_0=0 +datum=potsdam +units=m +no_defs"
but I only get an error:
Error in checkAtAssignment("SpatialPointsDataFrame", "proj4string", "character") :
Zuweisung eines Objektes der Klasse “character” ist für @‘proj4string’ in einem Objekt aus Klasse “SpatialPointsDataFrame” nicht zulässig; is(value, "CRS") ist nicht TRUE
(sorry for German - apparently it's not valid to assign an object of class character in an object of class SpatialPointsDataFrame).
Now I am stuck, can you help me?
project(dat) <- CRS("+proj=tmerc +lat_0=0 +lon_0=9 +k=1 +x_0=3500000 +y_0=0 +datum=potsdam +units=m +no_defs")– Nov 24 '14 at 09:50Error in project(dat) <- CRS("+proj=tmerc +lat_0=0 +lon_0=9 +k=1 +x_0=3500000 +y_0=0 +datum=potsdam +units=m +no_defs") : could not find function "project<-"– user41019 Nov 24 '14 at 10:49projection(dat), sorry – Nov 24 '14 at 11:04Error in projection(dat) <- CRS("+proj=tmerc +lat_0=0 +lon_0=9 +k=1 +x_0=3500000 +y_0=0 +datum=potsdam +units=m +no_defs") : could not find function "projection<-"– user41019 Nov 24 '14 at 12:56