Skip to content

Get contour of a map

7 messages · Pierre Bruyer, Duncan Murdoch, Barry Rowlingson +1 more

#
Hello everybody,

I search a function which returns the contour of map with levels like contourLines, but I would like this function return the border of the map too, because the function contourLines cannot consider the corner of the map and it is not adapted to fill polygon after that.

Thanks in advance

Pierre Bruyer
#
On 11-05-23 5:55 AM, Pierre Bruyer wrote:
I think writing that would be hard, but you can fake it.  Find the range 
of z first to work out the contour levels you want, then put very large 
values around the outside of the z matrix.  (You can't use Inf, but big 
finite values will work.)  For example:

x <- 1:10
y <- 1:20
z <- outer(x, y, function(x,y) sin(x)+cos(x*y/10))

range(z) # about -2 to 2, so 10000 is much bigger

z <- rbind(10000, z, 10000)
z <- cbind(10000, z, 10000)

x <- c(0.99, x, 10.01)
y <- c(0.99, y, 20.01)

Now contour plots of x,y,z with contour levels in the range of -2 to 2 
will show closed contours, and contourLines() will return paths around 
them.  They aren't exactly right (because 10000 is not infinity, and 
0.01 is not zero), but should be close enough for graphics purposes.

You'll have to write your own function to handle the general case, but 
it shouldn't be too hard.

Duncan Murdoch
#
I think it is a very good idea, thank a lot, I will try this!

Le 23 mai 2011 ? 21:00, Duncan Murdoch a ?crit :
#
On Mon, May 23, 2011 at 8:00 PM, Duncan Murdoch
<murdoch.duncan at gmail.com> wrote:
I had a play with this yesterday, expecting gPolygonize from rgeos to
do the heavy lifting. But all I could make it do with contours from
the standard volcano data, converted to the appropriate SpatialLines
form, was segfault. Works fine on the examples given in the
gPolygonize docs.

 That was an end-of-day ten minute experiment, so I might have another go later.

B
#
On May 23, 2011, at 5:55 AM, Pierre Bruyer wrote:

            
Frank Harrell has a `perimeter` function in his `rms` package which he  
uses to establish (and optionally draw)  boundaries around 2D regions  
with sufficient data to yield meaningful estimates. The plotting is  
handed off to lattice functions. His default plotting function for 2D  
plotting is contourplot. It didn't take that long to make the  
transition to rms+lattice and I have been very pleased with the  
integration of the two.

There is also a chull  (convex hull) function although at the moment I  
do not remember which package it resides in.
David Winsemius, MD
West Hartford, CT
#
I have seen this package and especially the 'perimeter' function, and it has not a 'levels' parameters like a lot of other functions, and this is a big problem for my project.
Otherwise I find this package have a better architecture than the other spatial package ^^


Le 24 mai 2011 ? 10:52, David Winsemius a ?crit :
#
My main problem is to use a spline cubic smooth (I hope this understanding, my english is not perfect ... ), and I would like to smooth the contours of my maps with my own scale of levels (e.G., levels are 1,3,5,10,20,30,40,50,75,...) so it is not easy to find a function which consider this two constrains, and I don't see how gPolygon can help me (in it doc, I have seen this function cut polygon in a set of subpolygon.


Le 24 mai 2011 ? 10:18, Barry Rowlingson a ?crit :