Skip to content
Prev 19158 / 29559 Next

Import custom projection in R

On Tue, 27 Aug 2013, Pan wrote:

            
No, reading (and re-reading) the help pages and their references may help. 
You have not explained why you need to read your "custom" projection. You 
could simply enter it as a PROJ.4 string. You appear to think that you 
should read a shapefile (including its optional *.prj file component) to 
retreive the string. If you don't need to do this, and can write it as a 
string in R, do that - CRS() of your string with rgdal loaded will check 
for obvious errors. If you have a representation that OGR recognises, such 
as a shapefile, you can say for example:

library(rgdal)
dsn <- system.file("vectors", package = "rgdal")[1]
# to access the vector examples provided
OGRSpatialRef(dsn, "cities")

Here, the dsn= argument is the directory containing the shapefile 
components, and cities is a layer; here, you can check that there are 
files ending in "prj", and for files starting with "cities":

list.files(path=dsn, pattern="prj$")
list.files(path=dsn, pattern="^cities")

Do check that the files are where you think they are, the most frequent 
cause of the error message you see being that they are somewhere else. 
Once you are done, use writeOGR(), not writePointShape() which is 
deprecated and which discards your coordinate reference system anyway, so 
defeating the point of your exercise.

Hope this clarifies,

Roger