use*_*688 6 export r polygon shapefile
我一直在尝试将绘图的内容(线/多边形)导出为我可以在ArcMap中打开的图层/ shapefile.这些是我一直使用的一些库,
Run Code Online (Sandbox Code Playgroud)library(shapefiles) library(PBSmapping) library(adehabitatHR) library(maptools) library(maps) library(rgdal) library(igraph)
我的纬度/经度数据如下所示:
Run Code Online (Sandbox Code Playgroud)tagdata<-read.table(text="meanlat meanlong -18.63327 147.0248 -18.6368 147.0238 -18.62068 147.294 -18.62953 147.2942 -18.62953 147.2942 -18.62091 147.2938 -18.62953 147.2942 -18.62466 147.2926 -18.73393 147.2816 -18.73393 147.2816 -18.75383 147.2541 -18.75383 147.2541 -18.75383 147.2541 -18.75383 147.2541 -18.6368 147.0238 -18.63063 147.0256 -18.63063 147.0256 -18.68133 147.1164 -18.6368 147.0238 -18.63063 147.0256 -18.63063 147.0256 -18.75383 147.2541 -18.61273 147.0682 -18.69655 147.09 -18.6368 147.0238 -18.63063 147.0256 -18.63063 147.0256 -18.63217 147.0251 -18.75383 147.2541 -18.75383 147.2541 -18.75383 147.2541 -18.63063 147.0256 -18.68133 147.1164 -18.68133 147.1164 -18.63217 147.0251 -18.69922 147.0909 -18.73393 147.2816 -18.63632 147.0792 -18.69522 147.0896 -18.6368 147.0238 -18.75383 147.2541 -18.75383 147.2541 -18.75383 147.2541",header=TRUE)
我绘制了位置并使用AdehabitatHR包计算了最小凸多边形(MCP).
Run Code Online (Sandbox Code Playgroud)plot(tagdata$meanlong,tagdata$meanlat, col="red",pch=1) loc<-tagdata[ ,c("meanlong","meanlat")] coord<-SpatialPoints(loc) poly<-mcp(coord,percent=100) plot(poly,add=TRUE)
我知道如何将点导出/写入shapefile,我可以在ArcMap或类似的软件中打开,
例如:
Run Code Online (Sandbox Code Playgroud)loc<-SpatialPoints(loc) # #convert loc to spatial points rem<-tagdata[c(-1:-2)] SpatialPointsDataFrame(coords=loc,data=rem) obj<-SpatialPointsDataFrame(coords=loc,data=rem) writePointsShape(obj,"myshape.shp")
但是,我还没有找到一个使用多边形o折线对象的好方法.我愿意能够使用MCP作为shapefile导出/写入多边形对象.有什么建议?
mne*_*nel 15
rgdal对于这种事情是极好的.http://www.gdal.org/提供了您可能希望获得的支持哪种格式的大部分信息.
在这种情况下,您需要该 writeOGR功能
# this will create a shapefile called poly within the working directory
library(rgdal)
writeOGR(poly, dsn = '.', layer = 'poly', driver = "ESRI Shapefile")
Run Code Online (Sandbox Code Playgroud)
您可以轻松地使用它来编写任何形状文件(点,多边形等),但它们必须是SpatialxxxDataFrame对象
coorddf <- SpatialPointsDataFrame(coord, data = data.frame(dummy = rep(1,nrow(coord@coords))))
writeOGR(coorddf, dsn = '.', layer = 'mypoints', driver = "ESRI Shapefile")
Run Code Online (Sandbox Code Playgroud)