[R-sig-Geo] R function checking/transforming CRS layer R function

Tristan Bourgeois tristan.bourgeois at gmail.com
Fri Jan 27 10:41:53 CET 2017


Dear all,

I'm trying to build up an r function able to check if the projection system
of a layer is in Lambert93 (WSG code : 2154) .
If the condition is false I want to transform the CRS into Lambert 93.

This is what I wrote :

> CRSfunction<-function(couche)
+ {
+   prj_couche<-CRS(couche)
+   prj<-CRS("+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3
+x_0=700000 +y_0=6600000 +ellps=GRS80 +units=m +no_defs")
+   if (prj_couche!=prj)
+     {CRS(couche)="+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3
+x_0=700000 +y_0=6600000 +ellps=GRS80 +units=m +no_defs" }
+ }
> CRSfunction(UH)
Error in CRS(couche) : no method for coercing this S4 class to a vector
In addition: Warning message:
In is.na(projargs) : is.na() applied to non-(list or vector) of type 'S4'
Called from: CRS(couche)
Browse[1]> Q


Does anybody can help to deal with the mistake I 've made ??

Plus, I'm not sure the function will work with both raster and shapefiles.

Cheers.


Tristan Bourgeois.
R New User

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list