Name

ST_Perimeter — 返回多边形几何或地理的边界长度。

Synopsis

float ST_Perimeter(geometry g1);

float ST_Perimeter(geography geog, boolean use_spheroid = true);

描述

如果几何/地理是 ST_Surface、ST_MultiSurface(Polygon、MultiPolygon),则返回其 2D 周长。 对于非区域几何形状返回 0。 对于线性几何形状,请使用ST_Length。 对于几何类型,周长测量的单位由几何的空间参考系统指定。

对于地理类型,使用逆测地线问题执行计算,其中周长单位为米。 如果PostGIS是使用PROJ版本4.8.0或更高版本编译的,则椭球体由SRID指定,否则它是WGS84独有的。 如果use_spheroid = false,则计算将近似为球体而不是椭球体。

目前,这是 ST_Perimeter2D 的别名,但可能会更改以支持更高的维度。

此方法实现了 SQL 1.1 的 OGC 简单功能规范。 s2.1.5.1

该方法实现了SQL/MM规范。 SQL-MM 3: 8.1.3, 9.5.4

可用性 2.0.0:引入了对地理的支持

示例:几何

返回多边形和多重多边形的周长(以英尺为单位)。 请注意,单位为英尺,因为 EPSG:2249 是马萨诸塞州平面英尺

SELECT ST_Perimeter(ST_GeomFromText('POLYGON((743238 2967416,743238 2967450,743265 2967450,
743265.625 2967416,743238 2967416))', 2249));
st_perimeter
---------
 122.630744000095
(1 row)

SELECT ST_Perimeter(ST_GeomFromText('MULTIPOLYGON(((763104.471273676 2949418.44119003,
763104.477769673 2949418.42538203,
763104.189609677 2949418.22343004,763104.471273676 2949418.44119003)),
((763104.471273676 2949418.44119003,763095.804579742 2949436.33850239,
763086.132105649 2949451.46730207,763078.452329651 2949462.11549407,
763075.354136904 2949466.17407812,763064.362142565 2949477.64291974,
763059.953961626 2949481.28983009,762994.637609571 2949532.04103014,
762990.568508415 2949535.06640477,762986.710889563 2949539.61421415,
763117.237897679 2949709.50493431,763235.236617789 2949617.95619822,
763287.718121842 2949562.20592617,763111.553321674 2949423.91664605,
763104.471273676 2949418.44119003)))', 2249));
st_perimeter
---------
 845.227713366825
(1 row)
                        

示例:地理

返回多边形和多重多边形的周长(以米和英尺为单位)。 请注意,这是地理(WGS 84 经纬度)

SELECT  ST_Perimeter(geog) As per_meters, ST_Perimeter(geog)/0.3048 As per_ft
FROM ST_GeogFromText('POLYGON((-71.1776848522251 42.3902896512902,-71.1776843766326 42.3903829478009,
-71.1775844305465 42.3903826677917,-71.1775825927231 42.3902893647987,-71.1776848522251 42.3902896512902))') As geog;

   per_meters    |      per_ft
-----------------+------------------
37.3790462565251 | 122.634666195949


-- MultiPolygon example --
SELECT  ST_Perimeter(geog) As per_meters, ST_Perimeter(geog,false) As per_sphere_meters,  ST_Perimeter(geog)/0.3048 As per_ft
FROM ST_GeogFromText('MULTIPOLYGON(((-71.1044543107478 42.340674480411,-71.1044542869917 42.3406744369506,
-71.1044553562977 42.340673886454,-71.1044543107478 42.340674480411)),
((-71.1044543107478 42.340674480411,-71.1044860600303 42.3407237015564,-71.1045215770124 42.3407653385914,
-71.1045498002983 42.3407946553165,-71.1045611902745 42.3408058316308,-71.1046016507427 42.340837442371,
-71.104617893173 42.3408475056957,-71.1048586153981 42.3409875993595,-71.1048736143677 42.3409959528211,
-71.1048878050242 42.3410084812078,-71.1044020965803 42.3414730072048,
-71.1039672113619 42.3412202916693,-71.1037740497748 42.3410666421308,
-71.1044280218456 42.3406894151355,-71.1044543107478 42.340674480411)))') As geog;

    per_meters    | per_sphere_meters |      per_ft
------------------+-------------------+------------------
 257.634283683311 |  257.412311446337 | 845.256836231335