[R-sig-Geo] spplot with two rasters

Agustin Lobo Agustin.Lobo at ija.csic.es
Thu Mar 13 19:42:11 CET 2008


Edzer,

Edzer Pebesma escribió:
> Agus, I disagree with your claim that R plot functions are not ok for 
> real applications. Also, I use real applications for learning and 
> teaching -- they are not fundamentally different.

Yes they are: we use the results of real applications as examples
for teaching. Real applications need a lot of (geo)graphical interaction
for being developed, which cannot be done in the (not geo)graphical
display of R, you need a GIS display for that. In my case, in most cases 
I have to export the
sp objects as rasters or shp files, bring them to a GIS and interact
with them (and many other layers of information) there (for example,
getting on-screen values as tips, zooming in and out, changing the
background from one color composite to another, calculating buffers,
interactively measuring distances, selecting polygons according to an
associated database...). These operations are required to evaluate
results and to think on alternative approaches, and have to be done
easily and fast. If your problem is
solved with one single cycle involving one analysis in R, exporting to shp
and displaying, this is fine. But if you have to iterate
this process, having the option of displaying the sp
objects directly in the GIS display would be an advantage.

> In the trellis panel functions, or in the direct plot/image/lines etc 
> functions, you plot in data coordinates. The main thing that the plot 
> and spplot methods in package sp control is the aspect ratio. How else 
> do data coordinates differ from geographical coordinates when it comes 
> to plotting?
> 
> Are you refering to taking care of geographic (re)projection at that level?

This is one case, yes: if your GIS supports on-the-fly reprojection, you
can use layers from geodata distribution centers that work with a
different projection
than yours and display them along with your R (exported) layers,
no need for the user to run a reprojection, it's automatically done.
This is often the case here, where we normally work with UTM but get
many layers at European scale that are in a different projection.

In a previous message you said:
>>>>>> I find it hard to imagine how you want to plot two raster files on
>>>>>> top
>>>>>> of each other.

Well, in many GIS displays you just define a rectangle that you can move
on top of one raster as a window through which you can see (and check
values of) an underlying raster. This is most useful, and is set up in
seconds. Also, perhaps Dylan's problem could have been solved in a
GIS by
displaying the Z values as terrain, and draping the other raster on top
of it. Or just defining shades for the second raster. Or perhaps setting
a 50% of transparency for some regions of one raster...

Geographic information requires GIS display, that's why GIS displays exist.

In much the same way as the analysis of geographic data required the
design of sp
objects, the visualization of geographic data requires a geographic
display. Getting sp objects directly displayed on a GIS would be great.

Agus

> -- 
> Edzer
> 
> Agustin Lobo wrote:
>> Well, the problem is that R does not have a real geographical
>> display. While things can be done going back and forth from R to GIS,
>> this procedure soon becomes very inconvenient. It's ok
>> for learning and teaching, but not for real applications.
>> Maybe getting an existing GIS to display spatial R objects
>> is actually easier than developing a geographical display for R.
>> Agus
>>
>> Dylan Beaudette escribió:
>>  
>>> On Thursday 06 March 2008, Thomas Adams wrote:
>>>    
>>>> Dylan,
>>>>
>>>> I think a solution using GRASS can be found on pages 110-111 of "Open
>>>> Source GIS: A GRASS GIS Approach", 3rd Ed. The same material is covered
>>>> in the 2nd Ed. as well, where you use r.mapcalc to combine two rasters
>>>> and judicious use of MASKs; a conditional statement in r.mapcalc is the
>>>> key.
>>>>
>>>> Regards,
>>>> Tom
>>>>       
>>> Hi Tom,
>>>
>>> Thanks for the suggestion. This works, but we were hoping to make the 
>>> plot in R-- as the PDF output is hard to match with GRASS alone. I 
>>> suppose I will just have to try using two rasters with spplot() and 
>>> see what happens.
>>> Cheers,
>>>
>>> Dylan
>>>
>>>    
>>>> Dylan Beaudette wrote:
>>>>      
>>>>> On Tuesday 04 March 2008, Edzer Pebesma wrote:
>>>>>        
>>>>>> I find it hard to imagine how you want to plot two raster files on 
>>>>>> top
>>>>>> of each other. Do you want some form of transparency? If it is 
>>>>>> just one
>>>>>> overlaying the other, you could use overlay to find out which 
>>>>>> cells in
>>>>>> raster 1 to replace with those in raster 2 before plotting.
>>>>>> -- 
>>>>>> Edzer
>>>>>>           
>>>>> Hi Edzer,
>>>>>
>>>>> I generally agree that plotting one raster file "over" another raster
>>>>> file would be of little use. In this case, one of the raster files 
>>>>> (the
>>>>> interesting one) has been masked with nodata, such that it only really
>>>>> covers about 30% of the region of interest. The other raster is just
>>>>> contextual data, and thus would be useful to plot "behind" the first
>>>>> raster.
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Dylan
>>>>>
>>>>>        
>>>>>> Dylan Beaudette wrote:
>>>>>>          
>>>>>>> Hi,
>>>>>>>
>>>>>>> Is it possible to plot two raster images using spplot() in a manner
>>>>>>> similar to:
>>>>>>>
>>>>>>> pts <- list("sp.points", points_file, pch = 4, col = "black", 
>>>>>>> cex=0.5)
>>>>>>> spplot(raster_file, zcol="elev.pred", sp.layout=list(pts))
>>>>>>>
>>>>>>> Note that one of the raster images is an aerial photo, used only for
>>>>>>> context, while the second one is one with interesting z-values. The
>>>>>>> second raster is masked and thus does not cover the entire region.
>>>>>>>
>>>>>>> Thanks,
>>>>>>>
>>>>>>> Dylan
>>>>>>>             
>>>
>>>     
>>
>>   
> 
> 

-- 
Dr. Agustin Lobo
Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
LLuis Sole Sabaris s/n
08028 Barcelona
Spain
Tel. 34 934095410
Fax. 34 934110012
email: Agustin.Lobo at ija.csic.es
http://www.ija.csic.es/gt/obster




More information about the R-sig-Geo mailing list