[R-sig-Geo] SpatialPoint to SpatialGrid with unequal distributed points

smu at z107.de smu at z107.de
Fri Sep 17 15:53:59 CEST 2010


Thank you Edzer, the solution with the interpolation was exactly what I
was searching for.

best regards,
 stefan

On Thu, Sep 16, 2010 at 09:57:01PM +0200, Edzer Pebesma wrote:
> Stefan, your data are definitely not on a grid, so either you transform
> them back to the grid on which they were, or alternatively you could
> interpolate them to a new grid, e.g. by
> 
> library(sp)
> link <- "http://z107.de/uni/example16092010.RData"
> load(url(link))
> coordinates(data) <- c("lon","lat")
> diff(sort(unique(coordinates(data)[,2])))
> diff(sort(unique(coordinates(data)[,2])))
> bb = bbox(data)
> gt = GridTopology(c(bb[1,1],bb[2,1]), c(.18,.18), round(c(diff(bb[1,]),
>         diff(bb[2,]))/.18) + 1)
> plot(data)
> plot(SpatialGrid(gt),col='red',add=T)
> sp = SpatialGrid(gt)
> fullgrid(sp)=F
> spx = SpatialPixelsDataFrame(sp, data.frame(x = rep(NA, 44*16)))
> library(gstat)
> #proj4string(data)="+proj=longlat"
> #proj4string(spx)="+proj=longlat"
> sp2 = idw(Therm.Eignung~1,data,spx)
> image(sp2,axes=T)
> spplot(sp2[1], col.regions=bpy.colors())
> 
> 
> On 09/16/2010 08:31 PM, Stefan Muthers wrote:
> > Hello,
> > 
> > this is probably a beginners question, but I found no solution on the
> > web.
> > 
> > If am using data from a climate model with the cell positions given in
> > geographic coordinates. Unfortunatly the distance between the cells is
> > uneven (due to runding errors and maybe the projection) and the
> > "gridded" command fails to determine the correct cell size.
> > 
> > 
> > Consider the following example:
> > 
> > 
> > library(fields)
> > library(sp)   
> > 
> > link <- "http://z107.de/uni/example16092010.RData"
> > load(url(link))
> > 
> > coordinates(data) <- c("lon","lat")
> > gridded(data) <- TRUE  
> > # Warnmeldungen:
> > #1: In points2grid(points, tolerance, round, fuzz.tol) :  
> > #  grid has empty column/rows in dimension 1
> > #2: In points2grid(points, tolerance, round, fuzz.tol) :
> > #  grid has empty column/rows in dimension 2
> > 
> > data_sp <- as(data, "SpatialGridDataFrame")
> > g_plot <- as.image.SpatialGridDataFrame(data_sp["Therm.Eignung"])
> > image.plot(g_plot)
> > 
> > 
> > 
> > The resulting map contains only small stripes and much empty space.
> > summary(data) reveals, that the cellsize if much to small (cell should
> > be quadratic with a cellsize of ~ .16) and to many cells were found in
> > the y-direction. 
> > 
> > When I replace the lat and lon values with simple x and y coordinates,
> > everything works fine, but then it is not possible to overlay a shape
> > file, that displays the country borders.
> > 
> > Any ideas, why the cellsize-estimation is so different from the real
> > value and what I can do, to create a raster map with this data?
> > 
> > 
> > thank you and best regards,
> > 
> >  stefan
> > 
> > _______________________________________________
> > R-sig-Geo mailing list
> > R-sig-Geo at stat.math.ethz.ch
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 
> -- 
> Edzer Pebesma
> Institute for Geoinformatics (ifgi), University of Münster
> Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
> 8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
> http://www.52north.org/geostatistics      e.pebesma at wwu.de
> 
> _______________________________________________
> 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