All Products
Search
Document Center

PolarDB:ST_AsGeometry

Last Updated:Oct 13, 2023

This topic describes the ST_AsGeometry function. This function obtains the geometry-represented range of a grid.

Syntax

geometry ST_AsGeometry(geomgrid grid);
geometry[] ST_AsGeometry(geomgrid[] grid);
geometry ST_AsGeometry(h3grid grid);

Parameters

Parameter

Description

grid

The grid object that you want to obtain. The data type is GeomGrid or H3Grid.

Examples

 select st_astext(
   st_asgeometry(st_gridfromtext('G0013103220310313')));
                                                                                
      st_astext                                                                 
                      
--------------------------------------------------------------------------------
 POLYGON((116.458888888889 39.3088888888889,116.458888888889 39.3166666666667,11
6.466666666667 39.3166666666667,116.466666666667 39.3088888888889,116.4588888888
89 39.3088888888889))

select st_astext(unnest(st_asgeometry(st_as3dgrid(
  'srid=4490;POLYGON Z ((116 39 1000,116.12 39 2000,116.12 39.09 2000,116 39.09 2000,116 39 1000),(116.024 39.018 5000,116.024 39.045 4000,116.06 39.045 3000,116.06 39.018 3000,116.024 39.018 5000))'::geometry,8))));
                                                                                                                                                            
                                          st_astext                             
--------------------------------------------------------------------------------
 GEOMETRYCOLLECTION Z (POLYGON Z ((114 38 0,114 40 0,116 40 0,116 38 0,114 38 0)
),POLYGON Z ((114 38 224581.873222534,116 38 224581.873222534,116 40 224581.8732
22534,114 40 224581.873222534,114 38 224581.873222534)),POLYGON Z ((114 38 0,114
 38 224581.873222534,114 40 224581.873222534,114 40 0,114 38 0)),POLYGON Z ((116
 38 0,116 40 0,116 40 224581.873222534,116 38 224581.873222534,116 38 0)),POLYGO
N Z ((114 38 0,116 38 0,116 38 224581.873222534,114 38 224581.873222534,114 38 0
)),POLYGON Z ((114 40 0,114 40 224581.873222534,116 40 224581.873222534,116 40 0
,114 40 0)))
 GEOMETRYCOLLECTION Z (POLYGON Z ((116 38 0,116 40 0,118 40 0,118 38 0,116 38 0)
),POLYGON Z ((116 38 224581.873222534,118 38 224581.873222534,118 40 224581.8732
22534,116 40 224581.873222534,116 38 224581.873222534)),POLYGON Z ((116 38 0,116
 38 224581.873222534,116 40 224581.873222534,116 40 0,116 38 0)),POLYGON Z ((118
 38 0,118 40 0,118 40 224581.873222534,118 38 224581.873222534,118 38 0)),POLYGO
N Z ((116 38 0,118 38 0,118 38 224581.873222534,116 38 224581.873222534,116 38 0
)),POLYGON Z ((116 40 0,116 40 224581.873222534,118 40 224581.873222534,118 40 0
,116 40 0)))

-- H3 encoding
select st_astext(st_asgeometry(st_h3fromlatlng(20.5,128.2,8)));
 st_astext                                                                         
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------
 POLYGON((128.191668807576 20.5021234642116,128.190846860853 20.4973493612535,128.194924841007 20.4945095494225,128.19982492147 20.4964439288771,128.200646976708 20.5012181556083,128.196568842975 20.504
0578791202,128.191668807576 20.5021234642116))