默认情况下,PostGIS根据多边形((MINX, MINY), (MINX, MAXY), (MAXX, MAXY), (MAXX, MINY), (MINX, MINY))
的边界框计算多边形的包络或范围。
这给出了如下结果:
但是,我正在寻找更像这样的结果:
据我所知,我能提出的最佳算法是:
a
旋转为与x轴平行X
X
度,计算旋转多边形a
的信封Y
X
Y
度如何计算PostGIS中的第1步?
答案 0 :(得分:0)
这是一个实现。它不会处理堕落的情况和你 如果区域相关,可能不喜欢矩形选择。我正在尝试 postgis的提交,但这应该足以使用直到 我得到了postgis补丁。
create or replace function ST_MinimumRectangle(g geometry) returns geometry
language 'plpgsql' as $$
declare
hull geometry;
begin
hull = ST_ExteriorRing(ST_ConvexHull(g));
-- one side must lie along the rectangle.
-- so, for each side, rotate, bbox, counter-rotate bbox
with sides as (
select ST_PointN(hull, n) as a, ST_PointN(hull, n+1) as b,
n as side
from generate_series(1,ST_NPoints(hull)-1) n
),
angles as (
select side, a, b, st_azimuth(a, b) as angle from sides
),
boxes as (
select ST_Rotate(ST_Envelope(ST_Rotate(hull, -angle)),angle) as rect, side, angle from angles
)
select rect into hull from boxes order by ST_Area(rect), side limit 1
;
return hull;
end;
$$ immutable strict;
答案 1 :(得分:0)
小修复。
不知何故,它对我有用:
select ST_Rotate(ST_Envelope(ST_Rotate(hull, **angle**)),**-angle**)