[R-sig-Geo] Extract points from SpatialLines objects along with the corresponding Lines' ID
PONS Frederic - CEREMA/DTerMed/DREC/SRILH
Frederic.Pons at cerema.fr
Fri Dec 4 17:03:44 CET 2015
Dear
I think it is not possible because you can have one attribute for more
than one geometry...
Best regards
*Frédéric Pons *
*Expert hydraulique sur les inondations et aléas côtiers
**DREC/Service Risques Inondations Littoraux et Hydraulique **- Tél.:
(33)4 42 24 76 68 *
*Direction Territoriale Méditerranée
*
Centre d'études et d'expertise sur les risques, l'environnement, la
mobilité et l'aménagement
www.cerema.fr <http://www.cerema.fr>
Le 04/12/2015 16:49, "> Bastien Tran (par Internet, dépôt
r-sig-geo-bounces at r-project.org)" a écrit :
> Dear all,
>
> I am trying to extract the points that compose a SpatialLines object along
> with the Line's ID (provided when Lines() is called).
>
> Hoping it makes my question clearer this is what I am currently able to get
> (using the SpatialLines example):
>
>> library(sp)
>> l1 = cbind(c(1,2,3),c(3,2,2))
>> Sl1 = Line(l1)
>> S1 = Lines(list(Sl1), ID=c("a"))
>>
>> l2 = cbind(c(1,2,3),c(3,1.5,1))
>> Sl2 = Line(l2)
>> S2 = Lines(list(Sl2), ID="b")
>>
>>
>> L1 = SpatialLines(list(S1,S2))
>>
>> sapply(slot(L1, "lines"), function(x) lapply(slot(x, "Lines"),
> function(y) slot(y, "coords")))
> [[1]]
> [,1] [,2]
> [1,] 1 3
> [2,] 2 2
> [3,] 3 2
>
> [[2]]
> [,1] [,2]
> [1,] 1 3.0
> [2,] 2 1.5
> [3,] 3 1.0
>
> But I would rather like to obtain something like this:
>
> [[1]]
> [,1] [,2] [,3]
> [1,] "1" "3" "a"
> [2,] "2" "2" "a"
> [3,] "3" "2" "a"
>
> [[2]]
> [,1] [,2] [,3]
> [1,] "1" "3" "b"
> [2,] "2" "1.5" "b"
> [3,] "3" "1" "b"
>
> If possible I would like to avoid type conversions and get a data.frame
> directly though I could indeed recreate one with these matrices, without
> information loss I assume.
>
> Thank you in advance for any tips.
>
> Best regards,
> Bastien
>
> [[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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20151204/f472f882/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cerema.png
Type: image/png
Size: 6094 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20151204/f472f882/attachment.png>
More information about the R-sig-Geo
mailing list