[R-sig-Geo] Raster stream network to lines

Andy Bunn Andy.Bunn at wwu.edu
Thu Apr 19 00:22:05 CEST 2018


Brilliant! And a heck of a workaround. But what if foo is a projected raster? I can add a projection system but all the coordinate info is lost in the shuffle.

On 4/18/18, 1:17 PM, "Joseph Stachelek" <joseph.stachelek at gmail.com> wrote:

    Hi Andy,
    
    I have posted some code showing one way of doing this
    with the `sf` package:
    
    https://gist.github.com/jsta/d8d8e8d79877c720b6842ae8efa2
    b9b8
    
    If you are doing this a lot I recommend picking up GRASS:
    
    https://grasswiki.osgeo.org/wiki/R.stream.*_modules
    https://grass.osgeo.org/grass74/manuals/r.to.vect.html
    
    --Joe
    
    -----Original Message-----
    From: Andy Bunn <Andy.Bunn at wwu.edu>
    To: R-sig-Geo <r-sig-geo at r-project.org>
    Subject: [R-sig-Geo] Raster stream network to lines
    Date: Wed, 18 Apr 2018 19:03:21 +0000
    
    I have a raster of streams with 0 being non-stream and 1
    being stream. Is there a way to convert this into a
    SpatialLinesDataFrame? rasterToContour() almost does what
    I want but fails to draw the line on queens rules, etc.
    Example here:
    
    library(raster)
    foo <- matrix(0,ncol=9,nrow=9)
    foo[1:4,3] <- 1
    foo[5,4] <- 1
    foo[6:9,5] <- 1
    foo <- raster(foo)
    plot(foo)
    bar <- rasterToContour(foo,nlevels=1)
    plot(bar)
    
    How can I get a continuous line in this example? Many
    thanks, Andy
    
    	[[alternative HTML version deleted]]
    
    _______________________________________________
    R-sig-Geo mailing list
    R-sig-Geo at r-project.org
    https://stat.ethz.ch/mailman/listinfo/r-sig-geo
    



More information about the R-sig-Geo mailing list