[R-sig-Geo] Problem Setting Projection of Rasters upon Import
Hodgess, Erin
HodgessE at uhd.edu
Fri Jul 12 02:50:43 CEST 2013
Hi Michael:
Did you try this;
test<-raster("us_ppt_1981_2010.02.asc", crs="+ellps=GRS80")
with the plus sign, please?
That might do it.
Thanks,
Erin
________________________________________
From: r-sig-geo-bounces at r-project.org [r-sig-geo-bounces at r-project.org] on behalf of Michael Treglia [mtreglia at gmail.com]
Sent: Thursday, July 11, 2013 7:16 PM
To: r-sig-geo at r-project.org
Subject: [R-sig-Geo] Problem Setting Projection of Rasters upon Import
Hi All,
I am using he "raster" package, and in particular the "raster" function. I
am dealing with a number of layers, and it would be easiest to set the CRS
upon import. Looking through the documentation, it seems that it is doable,
and I have been using the following code to get started, though it is not
setting the CRS.
Here are my code, and the results of the import:
> test<-raster("us_ppt_1981_2010.02.asc", crs="ellps=GRS80")
> test
class : RasterLayer
dimensions : 3105, 7025, 21812625 (nrow, ncol, ncell)
resolution : 0.008333333, 0.008333333 (x, y)
extent : -125.0208, -66.47917, 24.0625, 49.9375 (xmin, xmax, ymin,
ymax)
*coord. ref. : NA *
data source : D:\GIS\PRISM\1981-2010\PPT\us_ppt_1981_2010.02.asc
names : us_ppt_1981_2010.02
values : -2147483648, 2147483647 (min, max)
If I use the "projection" command afterwards, it sets the projection
appropriately though.
> projection(test)<-CRS("+proj=longlat +ellps=GRS80")
> test
class : RasterLayer
dimensions : 3105, 7025, 21812625 (nrow, ncol, ncell)
resolution : 0.008333333, 0.008333333 (x, y)
extent : -125.0208, -66.47917, 24.0625, 49.9375 (xmin, xmax, ymin,
ymax)
*coord. ref. : +proj=longlat +ellps=GRS80 *
data source : D:\GIS\PRISM\1981-2010\PPT\us_ppt_1981_2010.02.asc
names : us_ppt_1981_2010.02
values : -2147483648, 2147483647 (min, max)
Any suggestions of why the first option is not working? I have a script in
which I import all files in a folder, and the simplest way to assign the
projection would be the first option (I'm using an 'lapply' command).
It would look something like this:
import <- lapply(filenames ,raster, crs="....") #where "filenames" is a
vector of filenames in the working directory.
In case it helps, these are PRISM Climate Data, and the header of my raster
file is this:
ncols 7025
nrows 3105
xllcorner -125.020833333333329
yllcorner 24.062500000000000
cellsize 0.008333333333333
NODATA_value -9999
Thanks for any suggestions!
Mike
[[alternative HTML version deleted]]
_______________________________________________
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