gpt4 book ai didi

Python:具有简单解决方案的多边形形状文件中的轮廓特征

转载 作者:行者123 更新时间:2023-12-05 08:01:31 25 4
gpt4 key购买 nike

尊敬的成员(member)名单,

首先,我很抱歉发布这个问题,该问题是在上一篇文章的基础上修改和改进的。最近我正在研究 shapefiles 多边形以计算基本轮廓特征:

  1. 区域,
  2. 周边,
  3. 区域凸包,
  4. 周边凸包,
  5. 长轴长度=给出长轴的长度,
  6. minor axis length = 给出短轴的长度,

其中长轴和短轴长度是按照下图计算的:

enter image description here

使用 osgeo.gdal、ogr 和 shapely可以加载和计算所有索引,但不能加载和计算长轴和短轴长度。阅读在线解决方案可以使用

  1. scikit-image = 测量区域属性
  2. OpenCV

我正在寻找一个简单的解决方案,以使我的代码简单而优雅。一些博客建议对我的多边形进行椭圆近似,以检索长轴和短轴长度。这是最好的解决方案吗?

任何引用资料都会很有帮助。提前致谢


import osgeo.gdal, ogr
from shapely.geometry import Polygon

shp = osgeo.ogr.Open('../examples/mypoly.shp')
layer = shp.GetLayer()
feature = layer.GetFeature(0)
geometry = feature.GetGeometryRef()
# get area
Area = geometry.GetArea()
pts = geometry.GetGeometryRef(0)
points = []
for p in range(pts.GetPointCount()):
points.append((pts.GetX(p), pts.GetY(p)))
polygon = Polygon(points)
# get Perimeter
Perimeter = polygon.length
# convex Hull
ConvexHull = polygon.convex_hull
# get Perimeter convex Hull
PerimeterConvexHull = ConvexHull.length
# get Area convex Hull
AreaConvexHull = ConvexHull.area

这些是我的多边形的坐标顶点

polygon = Polygon([(560023.4495758876400000 6362057.3904932579000000),(560023.4495758876400000 6362060.3904932579000000),(560024.4495758876400000 6362063.3904932579000000),(560026.9495758876400000 6362068.3904932579000000),(560028.4495758876400000 6362069.8904932579000000),(560034.9495758876400000 6362071.8904932579000000),(560036.4495758876400000 6362071.8904932579000000),(560037.4495758876400000 6362070.3904932579000000),(560037.4495758876400000 6362064.8904932579000000),(560036.4495758876400000 6362063.3904932579000000),(560034.9495758876400000 6362061.3904932579000000),(560026.9495758876400000 6362057.8904932579000000),(560025.4495758876400000 6362057.3904932579000000),(560023.4495758876400000 6362057.3904932579000000)])

为了从这里测试我的代码:

polygon = Polygon(points)
# get Perimeter
Perimeter = polygon.length
# convex Hull
ConvexHull = polygon.convex_hull
# get Perimeter convex Hull
PerimeterConvexHull = ConvexHull.length
# get Area convex Hull
AreaConvexHull = ConvexHull.area

最佳答案

你好,我有一些关于 shapefiles polygon 的工作,喜欢你的工作。我使用 minimum_rotated_rectangle 匀称地定义 majoraxis_length 和 minoraxis_length。我的代码是:

polygon = Polygon(points)  
ConvexHull = polygon.convex_hull # convex Hull
#minimum_ rotated_ Rectangle is the minimum boundary rectangle, exterior is the external point coordinates of the minimum boundary matrix, and coords is the coordinates of the points
p1 = Point(ConvexHull.minimum_rotated_rectangle.exterior.coords[0])
p2 = Point(ConvexHull.minimum_rotated_rectangle.exterior.coords[1])
p3 = Point(ConvexHull.minimum_rotated_rectangle.exterior.coords[2])
majoraxis_length = p1.distance(p2)
minoraxis_length = p2.distance(p3)

关于Python:具有简单解决方案的多边形形状文件中的轮廓特征,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13541562/

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