This may be useful. It is part of a function that I put together a  
while ago to measure the length of common borders. It's been a while  
since I used it.

common.border <- function(shp){
		if(length(slot(shp,"polygons"))!=2) stop('This function only handles  
two polygons at a time.')
		proj <- slot(shp,"proj4string")
		xy <- lapply(slot(shp,"polygons"),function(x)  
lapply(slot(x,"Polygons"),function(y) slot(y,"coords")))
		x <- matrix(unlist(xy[1]),ncol=2) #separates the polygon node- 
coordinate matrices
		y <- matrix(unlist(xy[2]),ncol=2)
		x <- round(x,6); y <- round(y,6) #this is necessary once the  
topology of the Wyondotte data has changed
		if(identical(x,y)) stop('These are the same polygon.')
		
		ff <- function(a,b){ #returns the location of shared points
			a <- as.vector(a)
			b <- as.vector(t(b))
			n <- length(b)/2
			ans <- array(dim=1)
			i <- 1
			while(i<=n){
				if(identical(a,b[((i*2)-1):(i*2)])){
					ans <- i
					i <- n
					}
				i <- i +1}
			ans
			}
		
		res <- apply(x,1,ff,b=y) #returns the location of shared points
		k <- which(!is.na(res))	#determines if the selected points are  
listed sequentially
		is.seq <- identical((min(k):max(k)),k)
		if(is.seq==F){ #reorders the list so that they are listed sequentially
			k <- which(is.na(res))
			beg <- min(k); end <- max(k); n <- length(res)
			res <- c(res[(end+1):(n-1)],res[1:(beg-1)])
			}
		else res <- res[!is.na(res)] #if they are sequential, just remove  
the na values
		SL <- SpatialLines(list(Lines(list(Line(y[res,])))),proj4string=proj)
		list(line=SL,len=SpatialLinesLengths(SL))
		}


Jonathan B. Thayn
Ph.D. Candidate – Geography and Remote Sensing
University of Kansas
2101 Constant Avenue, Higuchi Hall, Rm 121
Lawrence, Kansas 66047-3759
jonthayn@ku.edu
http://people.ku.edu/~jonthayn

On Mar 30, 2009, at 3:07 PM, Peter Jepsen wrote:

> Dear R-helpers
>
>
>
> I have two SpatialPolygonsDataFrame objects, but I want to plot only  
> the
> boundary between them. The boundary object is to be overlaid I plot  
> that
> I have made, so I would strongly prefer a method that does not rely on
> grid graphics.
>
>
>
> Thank you in advance for any pointers.
>
>
>
> Kind regards,
>
> Peter.
>
>
>
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo


	[[alternative HTML version deleted]]

