[R-sig-Geo] projection string when using asSGDF_GROD()
Robert Hijmans
r.hijmans at gmail.com
Tue Dec 9 07:10:37 CET 2008
Hi Harry,
I do not really see any evidence for your statement that "it doesn't
inherit the projection (lat and long)"
Are you sure that "dpath" has a defined projection? (the fact that the
data are in lat and long does not imply this.)
If it does, you should get something like this (like I get):
attr(x, "projection")
[1] "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs "
> wetland at proj4string
CRS arguments:
+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0
If the projection of the arcinfo data has not been defined (which I
assume is the problem), you can fix this with e.g. ArcInfo (command
line) projectdefine (or via ArcMap)
Somethings like this may also work for you:
dpath<-"./glwd_3/hdr.adf"
x <- new("GDALReadOnlyDataset", dpath)
attr(x, "projection") <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
etc.
Robert
On Tue, Dec 9, 2008 at 1:42 PM, Harry Kim <harryk at cal.berkeley.edu> wrote:
> Hi Paul,
>
> Thank you so much for the prompt response. Here is the actual code I ran:
>
> library(rgdal)
> dpath<-"./glwd_3/hdr.adf"
> x <- new("GDALReadOnlyDataset", dpath)
> getDriver(x)
> getDriverLongName(getDriver(x))
>
> wetland<-asSGDF_GROD(x, offset=c(3600,20400), region.dim=c(8140,
> 18000),CRS("+proj=longlat" ))
>
> save(wetland,file="wetland.Rdata" )
>
> If I run this code without the CRS() argument for p4s, I can read in
> the data without any errors--but it doesn't project correctly. It's
> very strange that it doesn't inherit the projection (lat and long)
> from the original raster image.
>
> traceback() produces the following:
>
> > traceback()
> 5: getRasterData(x, offset = offset, region.dim = region.dim,
> output.dim = output.dim,
> ...)
> 4: asSGDF_GROD(x, offset = c(3600, 20400), region.dim = c(8140,
> 18000), CRS("+proj=longlat"))
> 3: eval.with.vis(expr, envir, enclos)
> 2: eval.with.vis(ei, envir)
> 1: source("wetland.R")
>
> Thank you so much in advance!
> Harry
>
>
>
>
> On Mon, Dec 8, 2008 at 1:26 PM, Paul Hiemstra <p.hiemstra at geo.uu.nl> wrote:
>> Hi Harry,
>>
>> Without the output of traceback() to show what exactly went wrong in what
>> function it is hard to say what is wrong. A small piece of sample code
>> reproducing the error would also make this diagnosis much easier.
>>
>> good luck and cheers,
>> Paul
>>
>> Harry Kim wrote:
>>>
>>> Dear r-sig-geoers,
>>>
>>> I need some help reading in a raster data and at the same time
>>> project it so I can use the overlay() function. The data I am reading
>>> in is quite big, so I managed to source in the subset of the data by
>>> running:
>>>
>>> wetland= asSGDF_GROD(x, offset=c(3600,20400),
>>> region.dim=c(8140,18000))
>>>
>>> Running summary(wetland) gives:
>>>
>>> Object of class SpatialGridDataFrame
>>> Coordinates:
>>> min max
>>> x -9.999992 140.0000
>>> y -7.833337 60.0000
>>> Is projected: NA
>>> proj4string : [NA]
>>> Number of points: 2
>>> Grid attributes:
>>> cellcentre.offset cellsize cells.dim
>>> x -9.995825 0.008333334 18000
>>> y -7.829171 0.008333334 8140
>>> Data attributes:
>>> Min. 1st Qu. Median Mean 3rd Qu.
>>> Max.
>>> 1.000000e+00 3.000000e+00 4.000000e+00 5.594000e+00 9.000000e+00
>>> 1.200000e+01
>>> NA's
>>> 1.396304e+08
>>>
>>> ----------------------------------------------------------------------------------------------------------------------------------
>>>
>>> The original data is geocoded in latitude and longitude spanning from
>>> -180 to 180 for longitude and from -90 to 90 for latitude. As you
>>> probably noticed, the read-in raster image does not inherit the
>>> projection.
>>> I tried to project the data by running:
>>>
>>> asSGDF_GROD(x, offset=c(3600,20400),
>>> region.dim=c(8140,18000),CRS("+proj=longlat" ))
>>>
>>> and I get a message that says
>>>
>>> Error: object is not subsettable
>>>
>>> If anybody could help me out, I would greatly appreciate it.
>>>
>>> Thank you
>>> Harry
>>>
>>> _______________________________________________
>>> 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
>
More information about the R-sig-Geo
mailing list