[R-sig-Geo] working with Z values in spatial data frames

Michael Sumner mdsumner at utas.edu.au
Mon Nov 5 20:35:57 CET 2007


I'm not totally sure what you mean:

You can use overlay() to transfer spatial attributes between *some* 
Spatial types, see ?"overlay-methods" for the allowed combinations.
Did you want to colour your polygons with values from the grid created 
by akima?

Cheers, Mike.

Steve Friedman wrote:
> Hello Michael,
>
> Thank you very much for providing this suggested approach.  I'm in the
> process of studying the code now to understand what it is doing and to
> prepare my data for use.
>
> Is there a way to use a polygon layer represented by a shapefile and use the
> SpatialPoints data set to color code the polygonal units in the former?
>
> Steve
>
>
> On 11/5/07, Michael Sumner <mdsumner at utas.edu.au> wrote:
>   
>> Here's one simple way, using package akima:
>>
>>
>> library(sp)
>>
>> data(meuse)
>>
>> ## assume your data is Spatial*
>>
>> coordinates(meuse) <- ~x+y
>>
>>
>>
>> ## use "elev" column in akima
>> library(akima)
>>
>> ## define a grid
>> xx <- coordinates(meuse)[,1]
>> yy <- coordinates(meuse)[,2]
>> ## modify offset of 100 to match your data, or use a proportion
>> grd <- expand.grid(x = seq(min(xx) - 200,  max(xx) + 200, length = 100),
>>          y = seq(min(yy) - 200, max(yy) + 200, length = 100))
>>
>>
>> res <- interpp(xx, yy, meuse$elev, grd$x, grd$y)
>> res <- as.data.frame(res) ## akima output is a list of 3 equal-length
>> vectors like grd passed in
>>
>>
>> ## if you want to interpolate on another "Z", repeat as desired, adding
>> to output
>> res$cadmium <- interpp(xx, yy, meuse$cadmium, grd$x, grd$y)$z
>>
>>
>> coordinates(res) <- ~x+y
>> gridded(res) <- TRUE
>>
>> ## if you don't have a lot of empty cells
>> fullgrid(res) <- TRUE
>>
>> image(res, "z")
>>
>> ## confirm where the high values were
>> points(meuse$x, meuse$y, cex = meuse$elev/5)
>>
>> image(res, "cadmium")  ## etc
>>
>> spplot(res)
>>
>>
>>
>>
>> Steve Friedman wrote:
>>     
>>> Hi,
>>>
>>> I have a spatial data set consisting of several z values and UTM
>>> coordinates.  Can someone direct me to documentation describing how I
>>>       
>> can
>>     
>>> plot specific z values using the coordinates to develop a continuous
>>>       
>> surface
>>     
>>> map?
>>>
>>> Thanks
>>> Steve
>>>
>>>       [[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
>>>
>>>
>>>
>>>       
>>     
>
>
>




More information about the R-sig-Geo mailing list