Man könnte einen individuellen "Konstruktor" für einen Sektor in Bezug auf den drei Punkte p1,p2,p3
definiert wie folgt definieren (p1
definiert die Mitte):
CREATE OR REPLACE FUNCTION ST_FormatPoint(p GEOMETRY)
RETURNS text AS
$$
BEGIN
RETURN ST_X(p) || ' ' || ST_Y(p);
END;
$$
LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION ST_Sector(p1 GEOMETRY, p2 GEOMETRY, p3 GEOMETRY)
RETURNS GEOMETRY AS
$$
DECLARE
phi double precision;
p4 geometry;
BEGIN
phi := (ST_Azimuth(p1, p3) - ST_Azimuth(p1, p2))/2;
p4 := ST_Rotate(p2, -phi, p1);
RETURN ST_GeomFromText(
'CURVEPOLYGON(CIRCULARSTRING(' ||
ST_FormatPoint(p1) || ', ' || ST_FormatPoint(p1) || ', ' ||
ST_FormatPoint(p2) || ', ' || ST_FormatPoint(p4) || ', ' || ST_FormatPoint(p3) || ', ' ||
ST_FormatPoint(p1) || ', ' || ST_FormatPoint(p1)
|| '))');
END;
$$
LANGUAGE 'plpgsql';
dann eine Abfrage
WITH s as (
select
ST_Sector(ST_Point(0,0), ST_Point(1,0), ST_Point(0, 1)) as poly
)
select st_perimeter(poly), st_area(poly) from s;
ergibt das erwartete Ergebnis
st_perimeter | st_area
-----------------+-------------------
3.5707963267949 | 0.785082789238688
(1 row)