Quite often it is necessary to interpolate a line between two other lines. A centerline between two banks is one example.

Since curvatures of both lines (banks) can differ significantly, it is not taken into account, but spatial proximity only.

This tool can handle degenerate geometries in general case, .e.g self intersecting.

library(rgdal)
library(lattice)
Bank_1 <- readOGR("..", "bank1")
Bank_2 <- readOGR("..", "bank2")
spar <- 0.4
Step_pattern <- "symmetricP05"
Step <- 25
Fraction <- .9
ff <- function(Fraction) {
  source('~/.qgis2/processing/rscripts/Banks to centerline.rsx', TRUE)
  Centerline@lines[[1]]@ID <- as.character(Fraction)
  rownames(Centerline@data) <- as.character(Fraction)
  Centerline@data$Fraction <- Fraction
  Centerline
}
l <- lapply(seq(.1, .9, .1), ff)
ll <- do.call('rbind.SpatialLinesDataFrame', l)
trellis.par.set(sp.theme())
spplot(ll, 'Fraction', panel=function(...){
  panel.polygonsplot(...)
  sp.lines(Bank_1, col='ForestGreen', lwd=2)
  sp.lines(Bank_2, col='ForestGreen', lwd=2)
})

centerline.svg

Figure 1: Line interpolation for various fractions

Last updated on .
blog comments powered by Disqus