Skip to content
Prev 7266 / 29559 Next

Creating random (but believable) geographies

On 12/28/2009 09:33 PM, Barry Rowlingson 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.

Jim