[R-sig-Geo] Convert SpatialPointsDataFrame to a SpatialGridDataFrame

Paul Hiemstra p.hiemstra at geo.uu.nl
Wed Sep 23 10:44:02 CEST 2009


Hi,

I'm adding a section on changing coordinate systems for Spatial objects 
on the r tips wiki, including a section on reprojecting grids:

http://wiki.r-project.org/rwiki/doku.php?id=tips:spatial-data:change_crs

I'm still working on it right now, but everyone is welcome to add to it 
later this day.

cheers,
Paul

Roger Bivand wrote:
> 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
>>
>


-- 
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone:  +3130 274 3113 Mon-Tue
Phone:  +3130 253 5773 Wed-Fri
http://intamap.geo.uu.nl/~paul



More information about the R-sig-Geo mailing list