【问题标题】:Export a polygon from an R plot as a shapefile将 R 图中的多边形导出为 shapefile
【发布时间】:2012-12-05 07:05:44
【问题描述】:

我一直在尝试将绘图的内容(线/多边形)导出为可以在 ArcMap 中打开的图层/形状文件。这些是我一直在使用的一些库,

library(shapefiles)
library(PBSmapping)
library(adehabitatHR)
library(maptools)
library(maps)
library(rgdal)
library(igraph)

我的经纬度数据如下所示:

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)。

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)

我知道如何将点导出/写入为可以在 ArcMap 或类似软件中打开的 shapefile,

例如:

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")

但是,我还没有找到使用多边形或折线对象的好方法。我希望能够使用 MCP 作为 shapefile 导出/写入多边形对象。有什么建议吗?

【问题讨论】:

  • 强制性开源布道:您为什么使用 ArcMap?为什么不试试量子 GIS?或者,如果您需要进一步分析,请在 R 中完成!

标签: r export polygon shapefile


【解决方案1】:

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")

您可以轻松地使用它来编写任何形状文件(点、多边形等),但它们必须是 SpatialxxxDataFrame 对象

coorddf <-  SpatialPointsDataFrame(coord, data = data.frame(dummy = rep(1,nrow(coord@coords))))
writeOGR(coorddf, dsn = '.', layer = 'mypoints', driver = "ESRI Shapefile")

【讨论】:

  • 那么如何将我绘制的 Ploy
  • 在你的问题中添加一个例子来说明你的意思
  • 您的对象polySpatialPolygonsDataFrame
  • SpatialxxxDataFrame 我的意思是 SpatialPointsDataFrame , SpatialPolygonsDataFrame 或类似
  • 知道了!非常感谢!我不确定是否需要一个指向我的多边形的 X/Y 属性表链接来将其导出为 shapefile。
猜你喜欢
  • 2021-08-15
  • 1970-01-01
  • 2014-01-30
  • 2016-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多