[R-sig-Geo] Define projection using Raster package

Robert Hijmans r.hijmans at gmail.com
Fri May 8 08:21:11 CEST 2009


Thanks Roger, you are right, I had missed that part (don't ask me how).

projectRaster() is indeed the function in raster to use (but it is a bit slow).

Something like
r<-raster(paste(asc.in.dir, "\\", asc.in.files[1], sep=""))
projection(r) <- "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"

Create a projected raster 'template'
newproj <- "+proj=tmerc +lat_0=0 +lon_0=0 +k=9996 +x_0=500000 +y_0=10000000"
projras <- projectBbox(r, newproj)
# Adjust the cell size, e.g. and perhaps the extent
res(projras) <- 100000
# xmin(projras) <- ....


now do the loop

r<-raster(paste(asc.in.dir, "\\", asc.in.files[i], sep=""))
rr <- projectRaster(r, projras)

Robert

On Fri, May 8, 2009 at 2:02 PM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
> On Fri, 8 May 2009, Robert Hijmans wrote:
>
>> Tim,
>>
>> "proj" is not a valid argument in raster(x, ... ) when x (the first
>> argument) is of class character (i.e. interpreted as a filename); but
>> I can add that argument. For now, what should work is:
>>
>> r<-raster(paste(asc.in.dir, "\\", asc.in.files[i], sep=""))
>> projection(r) <- "+proj=tmerc +lat_0=0 +lon_0=0 +k=9996 +x_0=500000
>> +y_0=10000000"
>
> This answers the question of how to set the coordinate reference system.
> However, I think that Tim is also asking about how to warp from geographical
> coordinates to the specified projected coordinates. Should he use
> projectRaster() to do this?
>
> Roger
>
>>
>> Robert
>>
>> On Fri, May 8, 2009 at 10:26 AM, Tim Sippel <tsippel at gmail.com> wrote:
>>>
>>> I need to take an ESRI grid (.asc) which is in geographic coordinates
>>> (lat/lon) and project it to UTM coordinates.  The following command is
>>> giving me an error saying I'm giving it an undefined argument.  I can
>>> read
>>> the raster without the projs arguement, but I'm stuck when adding that
>>> on.
>>>
>>>> r<-raster(paste(asc.in.dir, "\\", asc.in.files[i], sep=""),
>>>
>>> projs="+proj=tmerc +lat_0=0 +lon_0=0 +k=9996 +x_0=500000 +y_0=10000000")
>>> Error in .local(x, ...) :
>>>  unused argument(s) (projs = "+proj=tmerc +lat_0=0 +lon_0=0 +k=9996
>>> +x_0=500000 +y_0=10000000")
>>>
>>> Thanks,
>>>
>>> Tim
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at stat.math.ethz.ch
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
> --
> Roger Bivand
> Economic Geography Section, Department of Economics, Norwegian School of
> Economics and Business Administration, Helleveien 30, N-5045 Bergen,
> Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
> e-mail: Roger.Bivand at nhh.no
>



More information about the R-sig-Geo mailing list