ST_AsPng

更新时间:
复制 MD 格式

Renders a tile from a vector pyramid as a PNG image and returns it as a bytea value. Pass either a tile ID string or explicit x/y/z coordinates.

Syntax

bytea ST_AsPng(cstring name, cstring key, cstring style);
bytea ST_AsPng(cstring name, int x, int y, int z, cstring style);

Parameters

ParameterTypeDescription
namecstringThe name of the pyramid.
keycstringThe tile ID in 'z_x_y' format.
xintThe x coordinate of the tile.
yintThe y coordinate of the tile.
zintThe z coordinate of the tile.
stylecstringA JSON string that controls how the PNG is rendered. If you do not specify this parameter, the default style is used.

Style fields

FieldTypeDefaultDescription
backgroundstring#FFFFFFFFBackground color in RGBA format. Default is white.
line_colorstring#000000FFColor of dots and edges in RGBA format. Default is black.
fill_colorstring#F4A460FFFill color of the tile in RGBA format. Default is brown.
line_widthint1Line width in pixels.
point_sizeint10Dot diameter in pixels. Each dot is a circle with a diameter of 10 pixels.
parallel_unitint50000Number of elements each parallel rendering task processes.

Example style JSON:

{
  "background": "#FFFFFFFF",
  "line_color": "#000000FF",
  "fill_color": "#F4A460FF",
  "line_width": 1,
  "point_size": 10
}

Usage notes

  • A tile consists of multiple chunks. The tile ID (key) uses the 'z_x_y' format and must be valid under either the EPSG:4326 or EPSG:3857 coordinate system.

  • For EPSG:4326, the number of chunks on the x axis is twice the number on the y axis, and the z coordinate starts at 1. At z=1, the only valid tile IDs are 1_0_0 and 1_1_0.

  • The output PNG dimensions match the tileSize set when the pyramid was created with ST_BuildPyramid.

Examples

Both examples render the same tile (z=3, x=1, y=6) from the roads pyramid using the default style.

-- Render a tile using the tile ID string
SELECT ST_AsPng('roads', '3_1_6', '');
-- Render the same tile using explicit x, y, z coordinates
SELECT ST_AsPng('roads', 1, 6, 3, '');

Both return the PNG image as a bytea value:

0xFFAABB8D8A6678...