2

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?

user41019
  • 21
  • 1
  • 1
  • 2
  • 1
    Try 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:50
  • hm, this results in: Error 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:49
  • projection(dat), sorry –  Nov 24 '14 at 11:04
  • same :/ Error 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
  • 1
    it is proj4string not projection (the latter is in raster) – mdsumner Nov 24 '14 at 13:07

1 Answers1

1

Try using:

proj4string(dat) <- CRS("+proj=longlat +datum=WGS84")
Matt
  • 1,672
  • 16
  • 24
fares2212
  • 11
  • 1