[R-sig-Geo] Shapefile Created with R

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Mon Sep 20 12:05:37 CEST 2010


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

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
}

-- 
blog: http://geospaced.blogspot.com/
web: http://www.maths.lancs.ac.uk/~rowlings
web: http://www.rowlingson.com/
twitter: http://twitter.com/geospacedman
pics: http://www.flickr.com/photos/spacedman



More information about the R-sig-Geo mailing list