[R-sig-Geo] finding CRS from latitude/longitude

alemante zd mintibezabih at gmail.com
Sun Oct 7 00:08:24 CEST 2012


Dear Robert, Tom and Caleb,

Thanks for your suggestions. I have now fixed my CRs. But I now face
further problems further down in my code as my ultimate objective is
to get a raster layer.

Here is the full code based on Robert's reproducable example:



x <- 1:10

y <- 1:10




F1<-data.frame(x, y)

library(sp)


#SP <- SpatialPoints(F1,proj4string=CRS("+proj=longlat"))

SP <- SpatialPoints(F1,proj4string=CRS("+proj=latlong +datum=potsdam")),
         CRS("+proj=merc"))





library(rgdal)

#spt <- spTransform(SP, CRS("  fill in  the proj4 string you want  ") )
spt<-spTransform(SpatialPoints(data.frame(x=1:10, y=1:10),
         proj4string=CRS("+proj=latlong +datum=potsdam")),
         CRS("+proj=merc"))


gridded(spt) = TRUE

library(raster)
r = raster(spt)
projection(r) = CRS("+proj=latlong +datum=potsdam")
plot(r)


I now get error messages like coordinate intervals not constant and no
vallues associated with the raster layer.

Thanks
minti

On Sat, Oct 6, 2012 at 6:19 PM, Robert J. Hijmans <r.hijmans at gmail.com> wrote:
>
> Alemante,
>
>> but I keep on getting the message that CRS is wrong.
>> Coordinate Reference System (CRS) arguments: NA
>
> Please show more complete code. Which object are you talking about? Some of
> the object you create have a CRS (SP) others do not.(pts, F1), which is
> pretty obvious from reading the sequence of events in your code. You set the
> CRS for SP, but then you use F1 again which does not have a CRS and
> therefore neither do the objects derived from it. You could do after,
> gridded(F1) = TRUE,  proj4string(F1) <- CRS("+proj=longlat")
>
>
>> Could you please advice me on how I can get it right?
>
> I need to guess, but I think you want to transform points, in that case, do
> this:
>
> # example data
> x <- 1:10
> y <- 1:10
>
> F1<-data.frame(x, y)
> library(sp)
> SP <- SpatialPoints(F1,proj4string=CRS("+proj=longlat"))
>
> library(rgdal)
> spt <- spTransform(SP, CRS("  fill in  the proj4 string you want  ") )
>
>
> Best, Robert
>
>
> On Sat, Oct 6, 2012 at 5:48 AM, alemante zd <mintibezabih at gmail.com> wrote:
>>
>> Dear all,
>>
>> I would like to sp transform my latitude/longitude vector to by first
>> telling it what CRS it is. This is what I did.
>>
>> F1<-data.frame(x, y)
>> coordinates(F1)=~x+y
>> SP<-SpatialPoints(F1,proj4string=CRS("+proj=longlat"))
>> pts = SpatialPixels(SpatialPoints(F1))
>> gridded(F1) = TRUE
>>
>> but I keep on getting the message that CRS is wrong.
>> Coordinate Reference System (CRS) arguments: NA
>>
>> Could you please advice me on how I can get it right?
>>
>> cheers
>> minti
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>



More information about the R-sig-Geo mailing list