【问题标题】:how to get coordinates from SpatialPolygon如何从 SpatialPolygon 获取坐标
【发布时间】:2015-08-24 17:36:56
【问题描述】:

我从 drawpoly 中得到一个多边形:

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

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

poligon@polygons [[1]] “多边形”类的对象 插槽“多边形”: [[1]] “多边形”类的对象 插槽“labpt”: [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

提前致谢

【问题讨论】:

  • 没什么可做的,但coordinates(shape) 能给你想要的吗?
  • @GavinSimpson 我想要来自 drawPoly() 函数的多边形的坐标,我可以通过使用 polygon@polygon 看到它的坐标,但不能从它的坐标(多边形)中得到它跨度>

标签: r gis sp


【解决方案1】:

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

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

并使用:

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

获取多边形中的 x,y 点

【讨论】:

    【解决方案2】:

    添加 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]])
    

    【讨论】:

      猜你喜欢
      • 2021-12-26
      • 2020-06-15
      • 1970-01-01
      • 2021-10-22
      • 2015-08-01
      • 2021-11-24
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      相关资源
      最近更新 更多