Convert SpatialPointsDataFrame to a SpatialGridDataFrame
On Wed, 23 Sep 2009, Brendan Malone wrote:
Hi everyone, I would like to know a good way in which to convert a SpatialPointsDataFrame to a SpatialGridDataFrame. The reason that I ask is that when I change the CRS of a SpatialGridDataFrame, I inadvertently create a point data frame with the new CRS.
Your input data are in geographical coordinates, and you are projecting (no datum transformation) to UTM. This inevitably means that while the input points are evenly spaced, the projected points are not, and do not constitute a regular grid (see any introduction to projections). To get a regular grid out, you will have to warp, that is interpolate, to a regular grid from the irregular points that you have generated. Either use an interpolator such as idw() in gstat (see the task view for more), or use for example gdal_warp externally. This is getting to be a FAQ, isn't it? Could someone put it in the R-wiki under spatial data? Roger
To better illustrate my problem:
I have a grid file
grid90m <- readGDAL("edgeroi_dem.asc")
names(grid90m) <- "edgeroi_dem"
I give it a CRS
proj4string(grid90m)<- CRS("+init=epsg:4283")
Then I change it to a projected CRS
grid90.UTM <- spTransform(grid90m, CRS("+init=epsg:32755"))
Get a summary
summary(grid.UTM)
Object of class SpatialPointsDataFrame
Coordinates:
min max
x 738742 790718.3
y 6643860 6679923.8
Is projected: TRUE
proj4string :
[+init=epsg:32755 +proj=utm +zone=55 +south +ellps=WGS84 +datum=WGS84
+units=m +no_defs +towgs84=0,0,0]
Number of points: 220805
Data attributes:
Min. 1st Qu. Median Mean 3rd Qu. Max.
180.2 200.7 225.0 254.1 280.6 988.6
I have tried various ways to convert this points file to grid via a few
methods with resultant failure. Essentially I need to input some measure
of the pixel size.
My original thoughts were that the problem was to do with the
asymmetrical shape of my DEM layer. This may be true, but it would be
useful if people could provide some ideas on how to get around this.
Cheers,
Brendan Malone
PhD candidate
University of Sydney
[[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
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