全部產品
Search
文件中心

PolarDB:ST_AsGrid

更新時間:Jul 06, 2024

計算幾何對象相交的所有網格對象。

文法

geomgrid[] ST_AsGrid(geometry geom, integer precision, bool degenerated default false);

參數

參數名稱

描述

geom

需要計算的幾何對象。

precision

精度層級,取值:1~32,數值越大代表計算越精細。

degenerated

是否採用退化網格。

退化網格與普通網格的對比如下:退化網格

描述

幾何對象的空間參考必須是CGC2000(SRID=4490),如果不是則會調用空間投影變換函數(ST_Transform)對幾何對象的座標進行轉換,請確保能正確轉換到CGC2000座標系統。

本函數將返回幾何對象相交的網格對象數組,對於點、線或面資料分別返回對應的網格編碼,如下圖所示:

網格編碼圖

樣本

select st_astext(st_asgrid(
    ST_geomfromtext('POINT(116.31522216796875 39.910277777777778)',4490), 15));
    
     st_astext      
--------------------
 {G001310322230230}

select st_astext(st_asgrid(
    ST_geomfromtext('LINESTRING(122.48077 51.72814,122.47416 51.73714)',4490), 18));

                  st_astext                                                                          
--------------------------------------------------------------------------------
 {G001331032213300011,G001331032213300013,G001331032213122320,G00133103221312232
2,G001331032213300100,G001331032213122303,G001331032213122321,G00133103221312231
2}

select st_astext(st_asgrid(
  ST_geomfromtext('POLYGON((-0.08077 -0.02814, 0.0482 -0.03, 0.07426 0.03724, -0.08077 -0.02814))',4490),15));

                          st_astext
--------------------------------------------------------------------------------
 {G000000000000000,G000000000000001,G000000000000003,G000000000000010,G000000000
000011,G000000000000012,G000000000000013,G000000000000031,G000000000000102,G0000
00000000120,G100000000000000,G200000000000000,G200000000000001,G200000000000002,
G200000000000003,G200000000000010,G200000000000011,G200000000000012,G20000000000
0013,G300000000000000,G300000000000001,G300000000000002,G300000000000003,G300000
000000010,G300000000000011,G300000000000012,G300000000000013,G300000000000102}

select st_astext(st_asgrid(
  ST_geomfromtext('POLYGON((-0.08077 -0.02814, 0.0482 -0.03, 0.07426 0.03724, -0.08077 -0.02814))',4490),15,true));

                         st_astext
--------------------------------------------------------------------------------
 {G000000000000000,G000000000000001,G000000000000003,G00000000000001,G0000000000
00031,G000000000000102,G000000000000120,G100000000000000,G20000000000000,G200000
00000001,G30000000000000,G30000000000001,G300000000000102}