An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20100919/1fb1477b/attachment.pl>
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:
I created contour a shape file using roughly the following code:
grd.contour<-contourLines(list.x,list.y,grd.mat,levels=nlevel)
grd.contour<-ContourLines2SLDF(grd.contour)
shapef<-tclvalue(tkgetSaveFile(filetypes="{{Shape Files} {.shp}} {{All
files} *}"))
writeLinesShape(grd.contour,shapef)
It works perfectly. The only problem is that all contours on the map with
the same value are attached to the same record. Basically if a select a
contour with elevation two, all contours on the map are selected even if
they are not spatially connected. Is there a way to create a contour shapes
with independant records even when values are equal.
Any help is greatly apprecciated.
? ? ? ?[[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Michael Sumner Institute for Marine and Antarctic Studies, University of Tasmania Hobart, Australia e-mail: mdsumner at gmail.com
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20100919/0fc96594/attachment.pl>
On Mon, Sep 20, 2010 at 1:17 AM, kapo coulibaly <kmcoulib at gmail.com> wrote:
I created contour a shape file using roughly the following code:
grd.contour<-contourLines(list.x,list.y,grd.mat,levels=nlevel)
grd.contour<-ContourLines2SLDF(grd.contour)
shapef<-tclvalue(tkgetSaveFile(filetypes="{{Shape Files} {.shp}} {{All
files} *}"))
writeLinesShape(grd.contour,shapef)
It works perfectly. The only problem is that all contours on the map with
the same value are attached to the same record. Basically if a select a
contour with elevation two, all contours on the map are selected even if
they are not spatially connected. Is there a way to create a contour shapes
with independant records even when values are equal.
Any help is greatly apprecciated.
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
?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
}
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20100920/53837b89/attachment.pl>