2012-12-18 36 views
4

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

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) 

我知道如何导出/写点作为shape文件,我可以在ArcMap或类似的软件打开,

例如:

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的poly对象作为shapefile导出/写入。有什么建议么?

+0

[ 'rgdal'' writeOGR'](http://www.inside-r.org/packages/cran/rgdal/docs/writeOGR) – mnel

+2

必须遵守的开放源码布道:你为什么使用ArcMap?为什么不尝试Quantum GIS?或者如果您有进一步的分析,请在R中完成! – Spacedman

回答

10

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

你可以很方便地用它来写任何形状文件(点,多边形等),但它们必须​​对象

coorddf <- SpatialPointsDataFrame(coord, data = data.frame(dummy = rep(1,nrow([email protected])))) 
writeOGR(coorddf, dsn = '.', layer = 'mypoints', driver = "ESRI Shapefile") 
+0

那么如何将我绘制到SpatialxxxDataFrame中的我的Ploy <-MCP“对象”转换。我知道如何用积分做到这一点,但我怎样才能用没有明确空间参考的物体来做到这一点? – user1626688

+0

为你的问题添加一个你的意思的例子 – mnel

+0

你的对象'poly'是一个'SpatialPolygonsDataFrame' – mnel