gpt4 book ai didi

Python 如何使用 osgeo.ogr.Geometry 对象计算多边形周长

转载 作者:太空宇宙 更新时间:2023-11-03 13:03:04 25 4
gpt4 key购买 nike

首先,我很抱歉提出这个简单的问题。我需要计算一定数量的 gem 属性(面积、周长、圆度、长轴和短轴等)。我正在使用 GDAL/OGR读取我的多边形的 shapefile 格式。我想问的是:

  1. 是否有使用 osgeo.ogr.Geometry 计算周长的方法?
  2. 是否有构建模块来计算多边形的指标?

提前致谢

    import osgeo.gdal, ogr
poly="C:\\\myshape.shp"
shp = osgeo.ogr.Open(poly)
layer = shp.GetLayer()
# For every polygon
for index in xrange(len(allFID)):
feature = layer.GetFeature(index)
# get "FID" (Feature ID)
FID = str(feature.GetFID())
geometry = feature.GetGeometryRef()
# get the area
Area = geometry.GetArea()

最佳答案

        ref_geometry = ref_feature.GetGeometryRef()
pts = ref_geometry.GetGeometryRef(0)
points = []
for p in xrange(pts.GetPointCount()):
points.append((pts.GetX(p), pts.GetY(p)))

def edges_index(points):
"""
compute edges index for a given 2D point set

1- The number of edges which form the polygon
2- Perimeter
3- The length of the longest edge in a polygon
4- The length of the shortest edge in a polygon
5- The average length of all of edges in a polygon
6- The lengths of edges deviate from their mean value
"""
Nedges = len(points)-1
length = []
for i in xrange(Nedges):
ax, ay = points[i]
bx, by = points[i+1]
length.append(math.hypot(bx-ax, by-ay))
edges_perimeter = numpy.sum(length)
edges_max = numpy.amax(length)
edges_min = numpy.amin(length)
edges_average = numpy.average(length)
edges_std = numpy.std(length)
return (Nedges,edges_perimeter,edges_max,edges_min,edges_average,edges_std)

关于Python 如何使用 osgeo.ogr.Geometry 对象计算多边形周长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13517211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com