确定最小边界圆的半径或直径 [英] Determining the radius or diameter of a Minimum Bounding Circle
问题描述
如果我有一个类似于以下查询的 MBC:
If I have an MBC that looks like the following query:
SELECT ST_AsText(ST_MinimumBoundingCircle(geom)::geometry) AS Circle
FROM "Regions"
我想知道如何轻松确定它的半径.我已经求助于找到圆的质心,此时我可以尝试计算 MBC 中返回的多边形中的一个点与质心之间的距离,但是我似乎无法从多边形中只抓取一个顶点.
I'm wondering how I can easily determine it's radius. I've resorted to finding the centroid of the circle, at which point I can attempt to calculate the distance between one of the points in the MBCs returned polygon against the centroid however I can't seem to grab just one vertex from the polygon.
谢谢.
推荐答案
ST_MinimumBoundingCircle
是一个用户贡献的函数,源代码是用 PL/pgSQL 编写的.您可以
ST_MinimumBoundingCircle
is a user-contributed function with source written in PL/pgSQL. You can modify the source as a renamed function ST_MinimumBoundingRadius(inputgeom geometry)
with these modifications:
- 只需要一个参数
inputgeom geometry
- 将返回类型(靠近顶部)从
geometry
更改为double precision
- 对于 POINT 类型,将
RETURN hull;
更改为RETURN 0;
- 删除接近末尾的
ST_Buffer
语句,并返回radius
.
- Only needs one argument
inputgeom geometry
- Change return type (near top) from
geometry
todouble precision
- For POINT types, change
RETURN hull;
toRETURN 0;
- Remove the
ST_Buffer
statement near the end, and just return theradius
.
应该很容易.请注意,该算法存在一些问题,例如 ticket #2996.
Should be easy. Be aware there are some problems with the algorithm, such as ticket #2996.
这篇关于确定最小边界圆的半径或直径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!