参数化椭圆弧

对象构造

WKT 数据格式为 ELLIPTICALSTRING(xstart ystart,xend yend ,xcenter ycenter,minor,clockwise,rotation,axis,ratio);

  • xstart,ystart :起始点坐标

  • xend,yend: 终止点坐标

  • xcenter,ycenter: 中心点坐标

  • minor: 椭圆弧方向,只能是 0 或者 1,任何非 0 的数都会变为 1

  • clockwise 保留参数未使用

  • rotation :椭圆弧旋转角度

  • axis 长半轴长度

  • ratio 短轴与长轴之比

注意:椭圆的起始点和终止点必须要在椭圆上,否则会报错:

ERROR: the parameters of the ellipse must be valid

可以通过: select 'ELLIPTICALSTRING(-2 0,2 0,0 0,0,0,0,2,0.5)'::geometry; 来构造一个如下图所示的椭圆弧:

1.png

WKB 数据格式说明

select 'ELLIPTICALSTRING(-2 0,2 0,0 0,1,0,0,2,0.5)'::geometry;
01                           -- 小端
12000000                     -- 椭圆弧类型值 0x12(int)
03000000                     -- 点的个数 0x03 (int)
00000000000000C0             -- xstart       (double)    -2
0000000000000000             -- ystart       (double)    0
0000000000000040             -- xend         (double)    2
0000000000000000             -- yend         (double)    0
0000000000000000             -- xcenter      (double)    0
0000000000000000             -- ycenter      (double)    0
000000000000F03F             -- minor        (double)    1
0000000000000000             -- clockwise    (double)    0
0000000000000000             -- rotation     (double)    0
0000000000000040             -- axis         (double)    2
000000000000E03F             -- ratio        (double)    0.5

ZM 属性支持

create table ellipsetest(id serial,geom geometry(ELLIPTICALSTRING ,4326));
create table ellipsetest1(id serial,geom geometry(ELLIPTICALSTRINGZ ,4326));
create table ellipsetest2(id serial,geom geometry(ELLIPTICALSTRINGM ,4326));

COMPOUNDCURVE 支持

select 'COMPOUNDCURVE((1 2,2 0),ELLIPTICALSTRING(2 0,-2 0,0 0,0,0,0,2,0.5))'::geometry;
-- 结果
010900000002000000010200000002000000000000000000F03F0000000000000040000000000000004000000000000000000112000000030000000000000000000040000000000000000000000000000000C00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000E03F
select st_astext('COMPOUNDCURVE((1 2,2 0),ELLIPTICALSTRING(2 0,-2 0,0 0,0,0,0,2,0.5))'::geometry);
-- 结果
COMPOUNDCURVE((1 2,2 0),ELLIPTICALSTRING(2 0,-2 0,0 0,0,0,0,2,0.5))

注意 COMPOUNDCURVE 中上一个对象与新添加的对象必须是连接在一起的。

同时支持 st_curvetoline 函数,转换为 LINESTRING 后可以在 QGIS 中显示如下:

select ST_AsText(st_curvetoline('COMPOUNDCURVE((1 0,2 0),ELLIPTICALSTRING(2 0 ,4 0, 3 0 ,1,0,0,1,0.5))'));

2.png

将两个椭圆连在一起,转换为线后再 QGIS 中的显示

select ST_AsText(st_curvetoline('COMPOUNDCURVE(ELLIPTICALSTRING(-2 0,1.1602773 0.8145177,0 0,0,0,0,2,0.5),ELLIPTICALSTRING(1.1602773 0.8145177,4.3205547 0,2.3205547 0,0,0,0,2,0.5))'));

3.png

CURVEPOLYGON 支持

select st_curvetoline(st_astext('CURVEPOLYGON(ELLIPTICALSTRING(2 0,2 0,0 0,0,0,0,2,0.5),CIRCULARSTRING(-0.5 0,0.5 0,-0.5 0))'));

Note

CURVEPOLYGON 中的各个子对象必须是闭合的,例如其中的 ELLIPTICALSTRING 对象,起始点和终止点必须是一样的。

绘制图形如果所示:

4.png

API

ST_AsText

将 geometry 转换为 text 数据

语法

text ST_AsText(geometry geom);

参数

参数名称

描述

geom

椭圆弧对象

示例

select ST_AsText('ELLIPTICALSTRINGM (-2 0 0,2 0 0,0 0 0,0,0,0,2,0.5)'::geometry);

-- 结果

ELLIPTICALSTRING M (-2 0 0,2 0 0,0 0 0,0,0,0,2,0.5)

ST_Curvetoline

将参数化椭圆对象转换为线对象

语法

geometry ST_Curvetoline(geometry geom);

参数

参数名称

描述

geom

椭圆弧对象

示例

select ST_Curvetoline('ELLIPTICALSTRING(-2 0,1.1602773 0.8145177,0 0,0,0,0,2,0.5)');

-- 输出

0102000020E61000004000000000000000000000C0075C143326A6A13C4387327875FFFFBFBC07AA7B168A873FE128DAC918F7FFBF3583AAE032DDA73FD5FF6AB8A2E4FFBF96A165FD2AE8B43F22560F1919C8FFBF08A76F9021DBBD3F3D0AEFEF84A1FFBFE272BEAC5462C33F8C50566DF270FFBF130CC3C1F8D0C73FD1DDDBE97036FFBF6776188C1638CC3F04B287E112F2FEBF543595F8244BD03FB60BFCEDEDA3FEBF2AD1BFD31875D23F675CA2BF1A4CFEBF76112CD33799D43FB565DE15B5EAFDBFC73822CAD4B6D63F55F649B6DB7FFDBF085F499A44CDD83FE60BFC62B00BFDBF95B9B769DEDBDA3FE86BDECF578EFCBF0A814BD8FBE1DC3F91121597F907FCBF1B9A3B34F9DEDE3F51217B2CC078FBBFE9B2E7D61A69E03F114139D0D8E0FABF1FB116C5895DE13FF9B479807340FABF1F47982A7C4CE23F0FA23EEAC297F9BFE2681A89A635E33F1A565F59FCE6F8BFD87FE535BF18E43FBE9CB1A7572EF8BF7DAF22717EF5E43FB474642B0F6EF7BF2403877C9ECBE53F68B891A45FA6F6BF755B5CB1DB9AE63F9A8C0C2A88D7F5BF6825E195F462E73F80A57215CA01F5BF131AF8F1A923E83F8DAE86EE6825F4BF007E21E3BEDCE83FC65ADA55AA42F3BFB690B7EFF88DE93F5EDBCEEED559F2BF771868192037EA3FC7AFF248356BF1BF1434E5EEFED7EA3FE2F5C3C81377F0BFE0DBC79C6270EB3F1C24BD1F7DFBEEBF29BC9EFD1A00EC3F4B6B3BC908FFECBF6F5624A9FA86EC3FD9ED70326BF9EABFF69A9702D704ED3FDCAEC2E447EBE8BF707232468879ED3F987AE11A45D5E6BFCCF6B995E9E4ED3FEE11458C0BB8E4BF0F632404D946EE3F9626DE374694E2BF0D0C51A0379FEE3F42FF0F2EA26AE0BF16FFCE7EE9EDEE3FD7AA05B49C77DCBFF42FAFC2D532EF3F6966C094F610D8BFB46C5FA5E66DEF3F488E15F3B5A2D3BFE99B8B7D099FEF3F24368D55825CCEBFF71803C52EC6EF3FF04DB11A016AC5BF8C51A01D4AE3EF3FAEB1F5C077E1B8BF8017315552F6EF3F64501BA8439C9BBF286B5E6841FFEF3F2449D56E082BA63F13D3928414FEEF3FF218FCDA980EBD3F85A7DE08CCF2EF3FEF23C4A93F7FC73F9009DA856BDDEF3FB99D9B36E337D03F5B8F84BCF9BDEF3FC1C07BD606ABD43F8C00239C8094EF3F392283CDA217D93F8ECF1B3F0D61EF3FCF52D844517CDD3F7D4DD3E6AF23EF3F8C246B73D7EBE03F95E788F67BDCEE3F3C24A8A72D14E33F800D37ED878BEE3F3BDD73BD7C36E53F05B0775EED30EE3FC666A81A1852E73FD2966FEAC8CCED3F698131435566E93F1B1BC3343A5FED3F969AE90E8C72EB3F6C2297DA63E8EC3F8788BADE1676ED3F4782A1676B68EC3F4C35F1D05270EF3F00414C4A79DFEB3F65D859FA4FB0F03F5273EFC6B84DEB3FB9B344BE30A3F13FD5BF25EA57B3EA3F44C3F2F77E90F23FFAD93F7A8710EA3F

ST_Area

计算椭圆弧面积

语法

float ST_Area(geometry geom);

参数

参数名称

描述

geom

用于计算面积的 geometry 对象

示例

select ST_Area('COMPOUNDCURVE(ELLIPTICALSTRING(-1 0, -1 0, 0 0,1,0,0,1,0.5))');

-- 输出

1.5707963267948966

ST_Length

计算椭圆弧长

语法

float ST_Length(geometry geom);

参数

参数名称

描述

geom

用于计算弧长的 geometry 对象

示例

select ST_Length('ELLIPTICALSTRING(0 0,0 0,2 0,0,1,0,2,0.5)'); -- 1 ellipse

-- 输出

9.685374273494208

ST_AreaParam

计算参数化对象精确面积

语法

float ST_AreaParam(geometry geom);

参数

参数名称

描述

geom

用于计算精确面积的 geometry 对象

示例

select ST_AreaParam('CURVEPOLYGON(CIRCULARSTRING(-1 5, 1 5 ,-1 5))');

-- 输出

3.141592653589793

Note

与圆弧对象类似,参数化的椭圆弧对象在参与其它计算时(比如计算缓冲区、空间关系判断等),需要转化成普通线或面对象(可调用ST_Curvetoline)。