Skip to content
Prev 8695 / 29559 Next

spTransform changes the class

Thank you all for your ideas.
Please note though that the goal is to create a raster as a reference
object for running resample().
The original data is a high resolution raster in EPSG 3035 (Br) that I
want to resample
to a lon,lat grid of 0.25 deg resolution (Frankly, I'm astonished that
such a simple operation
is so complicated in R, I think that it would be very simple in grass)

After having created the grid eugrd025, my first idea was just
considering that a grid is not
but a set of adjacent rectangular polygons and hence
raster::polygonValues() would solve my problem. Thus I converted the
grid eugrd025 to SpatialPolygons (eugrd025DF),
reprojected to EPSG 3035 (eugrd025EFDC_SPDF) and tried polygonValues()
. This did not work
(see [1])
and I was advised to try an "all raster approach", which is a good
approximation in this case as the resolution of the grid is much
larger than the resolution of the original raster Br.

Therefore, I needed a raster version of SpPolygons object
eugrd025EFDC_SPDF.  raster() does not
accept SpPolygons (which makes sense) , but SpPixels or SpGrids.
Unfortunately, while you can convert from SpPixels to SpPolygons, the
reverse, i.e.,
eugrd025EFDC_SPX <- as(eugrd025EFDC_SPDF, "SpatialPixels")
does not work

Indefatigable, I decided to use the original grid eugrd025, reproject
it via spTransform(), convert to raster using raster() and then
resample(), but spTransform() had a low blow ready for me:
spTransform() does not work with Spgrids, its help page
rgdal/html/spTransform-methods.html does not mention it and it
silently converts the output to Sppoints, which ultimately results
on a wrong resample() result.

Finally, the following mixture of Mike and Robert advices worked (fast)
Thanks!

Agus

[1] http://r-sig-geo.2731867.n2.nabble.com/polygonValues-raster-Very-slow-tp5239776p5239776.html
2010/7/1 Robert J. Hijmans <r.hijmans at gmail.com>: