Skip to content

Shapefile Created with R

6 messages · Michael Sumner, Barry Rowlingson, kapo coulibaly

#
What are you selecting them in? Do you need them separated in R, or in
some GIS? In software I use (Manifold) I would just use the Decompose
operation, but if you want to do this in R you'll need to regenerate
the SpatialLines object by working through the lists of coordinate
matrices that it contains.

It might be worth writing a function to do this for maptools, pretty
easy for lines as long as you don't need to check for actual
"touching" intersections.

Cheers, Mike.
On Mon, Sep 20, 2010 at 10:17 AM, kapo coulibaly <kmcoulib at gmail.com> wrote:

  
    
#
On Mon, Sep 20, 2010 at 1:17 AM, kapo coulibaly <kmcoulib at gmail.com> wrote:
The separate lines that you want are separate in the return from
contourLines, and its the ContourLines2SLDF function that puts each
line with the same height together.

 So you want to make a SLDF from the output from contourLines. This is
one of those fiddly jobs that involves me remembering again how to
build these things...

  See the help for SpatialLines, Lines, Line, and
SpatialLinesDataFrame... Or I might have a solution in half an hour...

Barry
#
Bit quicker than half an hour... Try this - its a simpliified version
of ContourLines2SLDF that keeps the level lines separate:

ContourLines2SLDF2 <-
  function (cL, proj4string = CRS(as.character(NA)))
{
  if (length(cL) < 1)
    stop("cL too short")

  df <- data.frame(level = sapply(cL,function(x){x$level}))
  m <- length(cL)
  res <- vector(mode = "list", length = m)
  IDs <- paste("C", 1:m, sep = "_")
  row.names(df) <- IDs
  for (i in 1:m) {
    res[[i]] <- Lines(Line(cbind(cL[[i]]$x,cL[[i]]$y)),
                      ID = IDs[i])
  }
  SL <- SpatialLines(res, proj4string = proj4string)
  res <- SpatialLinesDataFrame(SL, data = df)
  res
}