[R] build a SpatialLines object from a list

Eric Berger ericjberger at gmail.com
Mon Sep 25 17:56:37 CEST 2017


Hi Ashraf,
It is not obvious to me what your structures are but one problem in your
function is the assignment tt1 <- SpatialLines(list(tt[[i]])).

This will set tt1 to just have one item.

Consider the following

test.func <- function(x) {
    tt1 <- list()
    for ( i in ... )  {
       ...
       tt1[[i]] <- SpatialLines(tt[[i]])
    }
    return(tt1)
}

HTH,
Eric


On Mon, Sep 25, 2017 at 3:40 PM, Ashraf Afana via R-help <
r-help at r-project.org> wrote:

> Hi all,I'm trying to build a SpatialLines object from a list that contains
> 124 river segments. Each segment in the list contains the x,y coordinates.
> I'm using the following code to create the SpatialLines object, but it just
> retrieves one segment. Any suggestions?
>
> test.func = function(x){
>      for (i in 1:length(x)) {        tt[[i]] <- x[i]; tt[[i]]  =
> Line(tt[[i]]); tt[[i]]  = Lines(list(tt[[i]] ), 'i')        tt1 =
> SpatialLines(list(tt[[i]]))           }    return(tt1)  }
> Ashraf,
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

	[[alternative HTML version deleted]]



More information about the R-help mailing list