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

Hodgess, Erin HodgessE at uhd.edu
Fri Jan 27 12:15:45 CET 2017


Hi again!


Give this bad boy a shot:






CRSfunction<-function(couche)

 {


   prj_couche<-couche at proj4string

   prj_couche_c <- couche at proj4string@projargs

   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")

   prj_c <- "+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_c != prj_c){

     couche at proj4string <- prj

           }

 }




Erin M. Hodgess
Associate Professor
Department of Mathematics and Statistics
University of Houston - Downtown
mailto: hodgesse at uhd.edu
________________________________
From: Tristan Bourgeois <tristan.bourgeois at gmail.com>
Sent: Friday, January 27, 2017 4:39 AM
To: Hodgess, Erin
Cc: r-sig-geo at r-project.org
Subject: Re: [R-sig-Geo] R function checking/transforming CRS layer R function

Hi Erin !

Yes,   I tried to apply my function to "UH"  which is a shapefile.




2017-01-27 11:28 GMT+01:00 Hodgess, Erin <HodgessE at uhd.edu<mailto:HodgessE at uhd.edu>>:
Hi Tristan!

I'm looking at your code right now.  What is your input, please; the UH?

Thanks,
Erin


Erin M. Hodgess
Associate Professor
Department of Mathematics and Statistics
University of Houston - Downtown
mailto: hodgesse at uhd.edu<mailto:hodgesse at uhd.edu>

________________________________________
From: R-sig-Geo <r-sig-geo-bounces at r-project.org<mailto:r-sig-geo-bounces at r-project.org>> on behalf of Tristan Bourgeois <tristan.bourgeois at gmail.com<mailto:tristan.bourgeois at gmail.com>>
Sent: Friday, January 27, 2017 3:41 AM
To: r-sig-geo at r-project.org<mailto:r-sig-geo at r-project.org>
Subject: [R-sig-Geo] R function checking/transforming CRS layer R function

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<http://is.na>(projargs) : is.na<http://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]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org<mailto:R-sig-Geo at r-project.org>
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



--
Tristan Bourgeois

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list