Postgis生成矢量切片主要使用以下两个方法
SELECT ST_AsMVT(tiletable.*,'dltb1000w',512) as tile FROM(
SELECT dlbm,ST_AsMVTGeom(ta.shape , ST_Transform(ST_MakeEnvelope(118.125,29.535229562948455,120.9375,31.952162238024957, 4326),4610),512 ) as geom from(
select * from
dltb1000w where 1=1 and ST_Intersects( ST_Transform(ST_MakeEnvelope(118.125,29.535229562948455,120.9375,31.952162238024957, 4326),4610) , shape )) ta) as tiletable where tiletable.geom is not null
ST_AsMVTGeom |
Synopsis
geometry **ST_AsMVTGeom**(
geometry <var class="pdparam" style="color: rgb(153, 0, 0);">geom</var>, box2d <var class="pdparam" style="color: rgb(153, 0, 0);">bounds</var>, integer <var class="pdparam" style="color: rgb(153, 0, 0);">extent=4096</var>, integer <var class="pdparam" style="color: rgb(153, 0, 0);">buffer=256</var>, boolean <var class="pdparam" style="color: rgb(153, 0, 0);">clip_geom=true</var>)
;
Description
Transform a geometry into the coordinate space of a Mapbox Vector Tile of a set of rows corresponding to a Layer. Makes best effort to keep and even correct validity and might collapse geometry into a lower dimension in the process.
geom
is the geometry to transform.
bounds
is the geometric bounds of the tile contents without buffer.
extent
is the tile extent in tile coordinate space as defined by the specification. If NULL it will default to 4096.
buffer
is the buffer distance in tile coordinate space to optionally clip geometries. If NULL it will default to 256.
clip_geom
is a boolean to control if geometries should be clipped or encoded as is. If NULL it will default to true.
| ST_AsMVT |
Synopsis
row row data with at least a geometry column.
name is the name of the layer. Default is the string "default".
extent is the tile extent in screen space as defined by the specification. Default is 4096.
geom_name is the name of the geometry column in the row data. Default is the first geometry column.
feature_id_name is the name of the Feature ID column in the row data. If NULL or negative the Feature ID is not set. The first column matching name and valid type (smallint, integer, bigint) will be used as Feature ID, and any subsequent column will be added as a property. JSON properties are not supported.
优化策略
如果通过pg生成切片时间过长可以尝试减少两个函数的extent参数
比如默认是4096,可以改为512 可以明显提高计算速度,同时减少前端消耗
优化前
![](https://img.haomeiwen.com/i1940906/e19161e2202281a2.png)
优化后
![](https://img.haomeiwen.com/i1940906/b2946563d5f5fe51.png)
网友评论