Name

ST_AsMVTGeom — 将几何图形转换为 MVT 瓦片的坐标空间。

Synopsis

geometry ST_AsMVTGeom(geometry geom, box2d bounds, integer extent=4096, integer buffer=256, boolean clip_geom=true);

描述

将几何图形转换为 MVT(Mapbox 矢量切片)瓦片的坐标空间,如果需要,将其剪切到图块边界。 几何图形必须位于目标地图的坐标系中(如果需要,请使用 ST_Transform)。 通常这是 Web 墨卡托 (SRID:3857)。

该函数尝试保持几何有效性,并在需要时进行纠正。 这可能会导致结果几何体塌陷到较低的维度。

The function performs geometry simplification appropriate to the integer tile coordinate space. After transforming to tile coordinates it snaps coordinates to the integer grid, removes repeated points, and removes points that lie on straight lines. It does not perform general-purpose, scale-dependent simplification such as ST_Simplify. To reduce detail before tile conversion, simplify the geometry in map coordinates before calling ST_AsMVTGeom.

必须提供目标地图坐标空间中瓦片的矩形边界,以便可以变换几何图形,并在需要时进行裁剪。 可以使用ST_TileEnvelope生成边界。

ST_AsMVT函数用于将几何图形转换为 ST_AsMVT 所需的瓦片坐标空间。

geom 是目标地图坐标系中要变换的几何图形。

bounds 是瓦片在地图坐标空间中的矩形边界,没有缓冲区。

extent是由 MVT 规范定义的切片坐标空间中切片的大小。 默认值为 4096。

buffer是切片坐标空间中用于裁剪几何图形的缓冲区大小。 默认值为 256。

Clip_geom 是一个布尔值,用于控制几何图形是否按原样剪切或编码。 默认为 true。

可用性:2.4.0

[Note]

从 3.0 开始,可以在配置时选择 Wagyu 来剪辑和验证 MVT 多边形。 该库比 GEOS 默认库速度更快,产生的结果更正确,但它可能会丢失小多边形。

示例

SELECT ST_AsText(ST_AsMVTGeom(ST_GeomFromText('POLYGON ((0 0, 10 0, 10 5, 0 -5, 0 0))'),
    ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)),
    4096, 0, false));
MULTIPOLYGON(((5 4096,10 4091,10 4096,5 4096)),((5 4096,0 4101,0 4096,5 4096)))

使用计算出的瓦片边界进行查询和裁剪几何的 Web Mercator 瓦片典型示例。本示例假设 data.geom 列的 SRID 为 4326。


SELECT ST_AsMVTGeom(ST_Transform(geom, 3857 ),
            ST_TileEnvelope(12, 513, 412),
            extent =
> 4096,
            buffer =
> 64) AS geom
  FROM data
  WHERE geom && ST_Transform(ST_TileEnvelope(12, 513, 412, margin =
> (64.0 / 4096)),4326)