我正在使用HURDAT數據集繪製颶風軌跡。 我目前已經產生了R A SpatialPointsDataFrame對象,它看起來像這樣爲2004年。將SpatialPointsDataFrame轉換爲R中的SpatialLinesDataFrame
> str(cluster.2004.sdf)
Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots
[email protected] data :'data.frame': 2693 obs. of 4 variables:
.. ..$ Sid : int [1:2693] 1331 1331 1331 1331 1331 1331 1331 1331 1331 1331 ...
.. ..$ clusterid: num [1:2693] 2 2 2 2 2 2 2 2 2 2 ...
.. ..$ name : Factor w/ 269 levels "","ABBY ",..: 6 6 6 6 6 6 6 6 6 6 ...
.. ..$ WmaxS : num [1:2693] 78.9 82.8 80.9 70.9 76.9 ...
[email protected] coords.nrs : num(0)
[email protected] coords : num [1:2693, 1:2] 754377 612852 684956 991386 819565 ...
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : NULL
.. .. ..$ : chr [1:2] "lon" "lat"
[email protected] bbox : num [1:2, 1:2] -3195788 1362537 4495870 9082812
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "lon" "lat"
.. .. ..$ : chr [1:2] "min" "max"
[email protected] proj4string:Formal class 'CRS' [package "sp"] with 1 slots
.. .. [email protected] projargs: chr "+proj=lcc +lat_1=60 +lat_2=30 +lon_0=-60 +ellps=WGS84"
> summary(cluster.2004.sdf)
Object of class SpatialPointsDataFrame
Coordinates:
min max
lon -3195788 4495870
lat 1362537 9082812
Is projected: TRUE
proj4string :
[+proj=lcc +lat_1=60 +lat_2=30 +lon_0=-60 +ellps=WGS84]
Number of points: 2693
Data attributes:
Sid clusterid name WmaxS
Min. :1331 Min. :1.000 IVAN :517 Min. : 14.83
1st Qu.:1334 1st Qu.:2.000 FRANCES :403 1st Qu.: 31.35
Median :1337 Median :3.000 JEANNE :379 Median : 50.04
Mean :1337 Mean :2.898 KARL :283 Mean : 61.66
3rd Qu.:1339 3rd Qu.:4.000 DANIELLE :271 3rd Qu.: 90.40
Max. :1341 Max. :4.000 BONNIE :253 Max. :142.52
(Other) :587
每次風暴都有標記爲「錫德」的獨特風暴的id引用。 我想通過「Sid」對SpatialPointsDataFrame進行分組,並將所有點轉換爲一條線。
我已經有了從plyr包ddply去,但坦率地不知道我在做什麼。 我知道我可以通過循環數據框中的每一行並將座標附加到列表中,然後使用sp包中的Lines函數轉換該列表。
但是,我寧願更多的R轉換方式。 感謝 理查德
所有的「R方式」最終對付列表,但是你可以使用split(x,id)作爲開始。更重要的是你是否想要簡單(可能)或複雜的線條。你想爲每個唯一的ID的屬性的數據行? (簡單) – mdsumner