獲取幾何圖形元數據信息:
ST_GeometryType(geometry) —— 返回幾何圖形的類型
ST_NDims(geometry) —— 返回幾何圖形的維數
ST_SRID(geometry) —— 返回幾何圖形的空間參考標識碼
postgis=# select name,ST_GeometryType(geom),ST_NDims(geom),ST_SRID(geom) from t_gis;
name | st_geometrytype | st_ndims | st_srid
-----------------+-----------------------+----------+---------
Point | ST_Point | 2 | 4326
Linestring | ST_LineString | 2 | 4326
Polygon | ST_Polygon | 2 | 4326
PolygonWithHole | ST_Polygon | 2 | 4326
Collection | ST_GeometryCollection | 2 | 4326
(5 rows)
返回點座標信息:
postgis=# select st_x(geom),st_y(geom) from t_gis where name='Point';
st_x | st_y
------+------
0 | 0
(1 row)
計算長度:
postgis=# select st_length(geom) from t_gis where name='Linestring';
st_length
------------------
3.41421356237309
(1 row)
計算面積:
postgis=# select st_area(geom) from t_gis where name='Polygon';
st_area
---------
1
(1 row)
不僅僅是規則圖形,不規則圖形的面積也可以直接計算:
postgis=# select st_area(geom) from t_gis where name='PolygonWithHole';
st_area
---------
99
(1 row)
更多的函數使用可以參考官方文檔:
http://postgis.net/docs/manual-3.0/reference.html