Finally, I got a SpatialLines from a psp object (here named aix.psp)

Here's how I got it:

coords <- aix.psp$ends
nc <- nrow(coords)
out <- vector(mode="list", length=nc)

for (i in seq(along=out)) {
  lLine <-Line(cbind(c(coords[i,1], coords[i,3]), c(coords[i,2],
coords[i,4])))
  out[[i]] <- Lines(list(lLine), ID=i)
}

aix.lines <- SpatialLines(out)

I don't find my solution very elegant. I wondered if a simpler code could
be written using lapply function.

For that purpose, I did:
liste<-lapply(coords, function(x) Line(cbind(c(x[1], x[3]), c(x[2], x[4]))))
but I don't know how to create a list of this one, with an incrementating
ID, which is required for constructing a Lines object as
Lines(list(LineList), ID=i)
It's more a general R problem than an R-sig-geo one but if anyone here has
the issue, I would be thankful.

Mathieu

2011/11/16 Mathieu Rajerison <[email protected]>

> Thanks for the answer.
>
> Otherwise, would you have any idea on how to convert a psp to a
> SpatialLines object?
>
>
> 2011/11/15 Roger Bivand <[email protected]>
>
>> On Tue, 15 Nov 2011, Mathieu Rajerison wrote:
>>
>>  Hi,
>>>
>>>
>>> I've generated random segment patterns with spatstat::rpoisline so as to
>>> plot differences of profile lines between two different digital elevation
>>> models.
>>>
>>> Now, I want to use raster::extract function to get the raster values on
>>> both rasters for each segment but for this, I have to coerce a psp to a
>>> SpatialLines object but I don't know how to do the coercion.
>>> (SpatialLines
>>> to psp is OK).
>>> as(psp, "SpatialLines") doesn't seem to work.
>>>
>>
>> The coercion functions in maptools, contributed by Adrian Baddeley, go
>> from SpatialLines to psp, not the reverse. You need to create the set of
>> coercion methods to go the other way - contributions welcome!
>>
>> Roger
>>
>>
>>>
>>> Any help would be appreciated,
>>>
>>> Mathieu
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> ______________________________**_________________
>>> R-sig-Geo mailing list
>>> [email protected]
>>> https://stat.ethz.ch/mailman/**listinfo/r-sig-geo<https://stat.ethz.ch/mailman/listinfo/r-sig-geo>
>>>
>>>
>> --
>> Roger Bivand
>> Department of Economics, NHH Norwegian School of Economics,
>> Helleveien 30, N-5045 Bergen, Norway.
>> voice: +47 55 95 93 55; fax +47 55 95 95 43
>> e-mail: [email protected]
>>
>>
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to