将shapefile转换为多边形

时间:2017-07-20 14:51:43

标签: r polygon shapefile

我有一个shapefile,它是我将在R中映射的湖的轮廓。我在shapefile中加载:

Lake <- readOGR("File directory", "Lake")

我需要将此shapefile设置为Polygon,而不是SpatialPolygon或SpatialPolygonDataFrame。

str(Lake)
Formal class 'SpatialPolygons' [package "sp"] with 4 slots
..@ polygons   :List of 1
.. ..$ :Formal class 'Polygons' [package "sp"] with 5 slots
.. .. .. ..@ Polygons :List of 3
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt  : num [1:2] -84.7 39.6
.. .. .. .. .. .. ..@ area   : num 0.000255
.. .. .. .. .. .. ..@ hole   : logi FALSE
.. .. .. .. .. .. ..@ ringDir: int 1
.. .. .. .. .. .. ..@ coords : num [1:1333, 1:2] -84.8 -84.8 -84.8 -84.8 
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt  : num [1:2] -84.8 39.6
.. .. .. .. .. .. ..@ area   : num 7.39e-07
.. .. .. .. .. .. ..@ hole   : logi TRUE
.. .. .. .. .. .. ..@ ringDir: int -1
.. .. .. .. .. .. ..@ coords : num [1:40, 1:2] -84.8 -84.8 -84.8 -84.8 
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt  : num [1:2] -84.8 39.6
.. .. .. .. .. .. ..@ area   : num 3.21e-06
.. .. .. .. .. .. ..@ hole   : logi TRUE
.. .. .. .. .. .. ..@ ringDir: int -1
.. .. .. .. .. .. ..@ coords : num [1:65, 1:2] -84.8 -84.8 -84.8 -84.8  
.. .. .. ..@ plotOrder: int [1:3] 1 3 2
.. .. .. ..@ labpt    : num [1:2] -84.7 39.6
.. .. .. ..@ ID       : chr "0"
.. .. .. ..@ area     : num 0.000255
..@ plotOrder  : int 1
..@ bbox       : num [1:2, 1:2] -84.8 39.6 -84.7 39.6
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "x" "y"
.. .. ..$ : chr [1:2] "min" "max"
..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
.. .. ..@ projargs: chr "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84   
+towgs84=0,0,0"

使用RGeostats包进行地质统计分析,我必须使用多边形,而不是任何其他对象类型。这是因为我必须选择包含整个湖泊的区域来进行进一步的分析。对象db.data存储特定纬度/经度点的鱼密度。

db.data=db.polygon(db.data, Lake)
The input object is of type ' SpatialPolygons '. It should be of type '   
polygon '
The function is interrupted
Error: Invalid object type

如何将shapefile读取为多边形?

1 个答案:

答案 0 :(得分:0)

尝试将@polygons对象分配给新对象。

像这样:

LakePolygons<-Lake@polygons
相关问题