【发布时间】:2021-12-30 20:39:39
【问题描述】:
【问题讨论】:
-
您可以计算边界框,取 2 个较长的边并更新 2 个较短的边,用较长边的值在每端添加 50%,然后再次连接它们
-
嗨@TimothyDalton - 伟大的思想等等。那是我最终做到的。为了完整性,下面的代码
标签: sql postgresql postgis
【问题讨论】:
标签: sql postgresql postgis
Tim Dalton 也建议 - 我解决了这个问题,如下所示。这是使用 Python 和 SRS 27700,所以它适用于我的目的。边界来自 GeoPandas 和 4 个极值的元组。
bounds = tuple(reportData.total_bounds)
left,bottom,right,top = bounds
bounds_width = right-left
bounds_height = top-bottom
is_tall = True if bounds_height > bounds_width else False
if is_tall:
pad = (bounds_height-bounds_width) * 0.05
diff = (bounds_height-bounds_width) / 2
plt.xlim(bounds[0]-diff-pad, bounds[2]+diff+pad)
plt.ylim(bounds[1]-pad, bounds[3]+pad)
else:
pad = (bounds_width-bounds_height) * 0.05
diff = (bounds_width-bounds_height) / 2
plt.ylim(bounds[1]-diff-pad, bounds[3]+diff+pad)
plt.xlim(bounds[0]-pad, bounds[2]+pad)
【讨论】:
使用 PostGIS,您可以应用或多或少相同的原理:1) 计算距多边形质心最远点的距离,2) 使用此距离值设置缓冲区的半径,最后在缓冲区:
SELECT
ST_Envelope(
ST_Buffer(
ST_Centroid(geom),
(SELECT max(ST_Distance(ST_Centroid(j.geom),i.geom))
FROM ST_DumpPoints(j.geom) i))
)
FROM your_table j;
【讨论】: