[R-sig-Geo] Best way to plot cross sections of discrete-valued grids

Barry Rowlingson B.Rowlingson at lancaster.ac.uk
Tue Apr 11 13:25:32 CEST 2006


Waichler, Scott R wrote:
> I have a 3-D grid where the values of the cells are a small number of
> discrete values.  (The grid represents subsurface soil and geology
> types.)  Contiguous regions of the same value are relatively few in
> number and large in size in comparison to the whole domain.  I am
> looking for advice on two things:
> 
> 1)  What is the best way to sample the grid along any transect defined
> by a line between (x1, y1) and (x2, y2), and plot the 2-D vertical cross
> section?  I would like to sample not only in the orthogonal directions
> defined by the grid but along any other compass bearing as well.
> Lattice plotting capability is desired.
> 

  At first I thought the best thing to do here would be to use 
contourLines to get the contiguous region boundaries and then work out 
all the intersections of the contour lines with your transect from x1,y1 
to x2,y2. But... You've got categorical data, so the contour function, 
which only works with numerical data, might get messed up...

  So I can only think that you will have to walk along the transect with 
a small step size (1/4 grid size will only miss a few corners), sampling 
from your grid as you go, ending up with a vector of coordinates and 
grid samples.

  Code to do this is fairly straightforward, depending on how complex 
your grids are - evenly spaced, defined by edges or centres, similar in 
X and Y etc etc.

Here's how simple it is using the transectGrid function what I just wrote:

   vo=list(x=1:87,y=1:61,z=volcano)
   image(vo)
   t1=transectGrid(locator(1,type='p'),locator(1,type='p'),vo)
   plot(t1[,1],t1[,3],type='l')

Just click twice. Three short R functions are attached. Hopefully thats 
the sort of thing you are looking for!

Barry


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: rowlings.rIndex.R
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20060411/5e8f053f/attachment.pl>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: rowlings.rasterSampleIndices.R
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20060411/5e8f053f/attachment-0001.pl>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: rowlings.transectGrid.R
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20060411/5e8f053f/attachment-0002.pl>


More information about the R-sig-Geo mailing list