[R-sig-Geo] Creating random (but believable) geographies

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Mon Dec 28 12:33:29 CET 2009


On Mon, Dec 28, 2009 at 11:20 AM, Jim Lemon <jim at bitwrit.com.au> wrote:

>
> Hi Barry,
> The first thing I thought of was to specify nodes (intersections of borders
> = vertices of polygons) and then wiggle the lines between the nodes using
> something like this:
>
> wigglyLine<-function(xstart,ystart,xend,yend,nseg=20,mult=1) {
>  xvec<-seq(xstart,xend,length.out=nseg+1)
>  yvec<-seq(ystart,yend,length.out=nseg+1)
>  xvec[2:nseg]<-xvec[2:nseg]+(runif(nseg-1)-0.5)*mult
>  yvec[2:nseg]<-yvec[2:nseg]+(runif(nseg-1)-0.5)*mult
>  return(list(x=xvec,y=yvec))
> }
>
> Obviously there are a lot of things that you could fiddle with here,
> including the easiest way to specify the vertices and then turn the wiggled
> edges into polygons. It does solve the problem of having the polygons fit
> together, though.

 My preferred wiggle algorithm is a fractal - for a line from points A
to B, choose a point C "between" A and B and create two lines AC and
CB. Repeat (recurse) for lines AC and CB up to a number of recursions.
Three or four should be enough.

 If you start with Voronoi polygon edges then you only have to check
that point C is inside either of the polygons on either side of AB to
keep the topology.

 There's some more choices here - you could either fully fractalise
one segment at a time, or do all the first divisions over the space,
then the subdivisions and so on. Also there's the definition of
"between", which strictly doesn't even have to be between A and B
(it's just more likely to be in one of the polygons if it is).

 May I also suggest that if anyone does generate some fake countries
that we place them in the middle of an ocean...

Barry



More information about the R-sig-Geo mailing list