如何从SpatialPolygon

时间:2015-06-09 18:21:49

标签: r gis sp

我使用以下方法从drawpoly获取多边形:

x<- ogrListLayers(file_map)
shape=readOGR(file_map, layer=x) #will load the shapefile to your dataset.
plot(shape)
polygon<- drawPoly()

但是,我试图从多边形中获取坐标,但我不能:

  

poligon @多边形       [[1]]       上课的对象&#34;多边形&#34;       Slot&#34; Polygons&#34;:       [[1]]       上课的对象&#34; Polygon&#34;       Slot&#34; labpt&#34;:       [1] -46.37327 -23.91955

Slot "area":
[1] 0.09747001

Slot "hole":
[1] FALSE

Slot "ringDir":
[1] 1

Slot "coords":
           [,1]      [,2]
 [1,] -46.20830 -23.73089
 [2,] -46.20089 -23.73691
 [3,] -46.19842 -23.74595
 [4,] -46.20336 -23.74670
 [5,] -46.20995 -23.76853
 [6,] -46.22313 -23.79338
 [7,] -46.20665 -23.79488
 [8,] -46.20171 -23.80467
 [9,] -46.20254 -23.82801
[10,] -46.21489 -23.84683
[11,] -46.19348 -23.84608
[12,] -46.17618 -23.87469
[13,] -46.11853 -23.84834
[14,] -46.12182 -23.86942
[15,] -46.14406 -23.90481

提前致谢

2 个答案:

答案 0 :(得分:0)

好吧,我发现函数clickpoly并使用了:

polygon <- clickpoly(add = TRUE, col = 2, lwd = 2)

并使用:

poligon$bdry[[1]][1]
poligon$bdry[[1]][2]

获取多边形中的x,y点

答案 1 :(得分:0)

如果添加MWE,会有所帮助。这是一个:

polygon = "POLYGON((186.547856450189 -46.4485209972227,182.523886136587 -87.3045772259105,170.606614118262 -126.59055812607,151.254014475596 -162.79672548354,125.209796759794 -194.531696591426,93.4748256519081 -220.575914307228,65.3272038227373 -235.621131625452,36.2687622716732 -244.435913500765,-9.05803921416017 -248.900213788796,-54.3848406999935 -244.435913500765,-97.9697586242894 -231.214573193132,-138.137849033921 -209.744281559306,-173.34547474097 -180.850129866096,-202.239626434179 -145.642504159047,-221.510885247941 -109.588514788964,-228.270643805406 -87.3045772259111,-232.294614119009 -46.4485209972234,-228.270643805406 -5.59246476853568,-216.353371787081 33.6935161316239,-197.000772144416 69.8996834890942,-170.956554428614 101.63465459698,-139.221583320728 127.678872312782,-103.015415963258 147.031471955448,-63.7294350630982 158.948743973773,-22.8733788344104 162.972714287376,17.9826773942774 158.948743973774,57.2686582944371 147.031471955449,93.4748256519074 127.678872312783,125.209796759793 101.634654596981,151.254014475596 69.8996834890953,170.606614118262 33.6935161316251,182.523886136587 -5.59246476853451,186.547856450189 -46.4485209972227))"

我不知道为什么这么困难,但是现在你去了:

polygon <- lapply(polygon, FUN = function(x) readWKT(x))

poly1 <- sapply(polygon, FUN=function(x) x@polygons)
poly2 <- sapply(poly1, FUN=function(x) x@Polygons)
poly3 <- lapply(poly2, FUN=function(x) x@coords)
plot(poly3[[1]])