2

如何将以下内容保存在 postgis 几何字段中?WKT 的弧形或扇形会是什么样子。是否有 ARC 众所周知的文本来保存它?

弧扇

4

1 回答 1

1

可以为根据以下三点定义的扇区定义自定义“构造函数” p1,p2,p3p1定义中心):

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';

然后,一个查询

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;

产生预期的结果

  st_perimeter   |      st_area      
-----------------+-------------------
 3.5707963267949 | 0.785082789238688
(1 row)
于 2016-12-14T11:56:00.533 回答