- 一个完整实例
with mvtgeom as( select st_asmvtgeom( geom, lsy_bboxxuz4490(218453,43497,18), --st_tileenvelope(18,218453,43496), 4096, 256, false ) as geom, id from yh_map_supplypipe where st_Intersects( geom, sy_bboxxuz4490(218453,43497,18), ) ) select st_asmvt(mvtgeom.*, 'layerName',4096,'geom')
from mvtgeom;
解析1:geometry ST_AsMVTGeom(
geometry geom, box2d bounds, integer extent=4096, integer buffer=256, boolean clip_geom=true)
;
把空间数据按照瓦片坐标方式进行坐标重新编排,在lsy_bboxxuz4490(218453,43497,18)里面的都是 0-4096,超出的有负数有更大的数
解析2:ST_AsMVT聚合函数用于将基于MapBox VectorTile坐标空间的几何图形转换为MapBox VectorTile二进制矢量切片
解析3:两个图层压缩成一个瓦片图层
WITH yh_map_supplypipemvt AS ( SELECT ST_AsMVTGeom ( geom, lsy_bboxxyz4490 (218453, 43497, 18), --st_tileenvelope(18,218453, 43496), 4096, 256, FALSE ) AS geom, ID FROM yh_map_supplypipe WHERE ST_Intersects ( geom, lsy_bboxxyz4490 (218453, 43497, 18) ) ), yh_map_drainpipemvt AS ( SELECT ST_AsMVTGeom ( geom, lsy_bboxxyz4490 (218453, 43497, 18), --st_tileenvelope(18,218453, 43496), 4096, 256, FALSE ) AS geom, ID FROM yh_map_drainpipe WHERE ST_Intersects ( geom, lsy_bboxxyz4490 (218453, 43497, 18) ) ) SELECT ( ( SELECT ST_AsMVT ( yh_map_supplypipemvt.*, 'yh_map_supplypipemvt', 4096, 'geom' ) AS mvt FROM yh_map_supplypipemvt ) || ( SELECT ST_AsMVT ( yh_map_supplypipemvt.*, 'yh_map_supplypipemvt', 4096, 'geom' ) AS mvt FROM yh_map_supplypipemvt ) ) AS mvt