All Products
Search
Document Center

PolarDB:ST_AsPng

Last Updated:Mar 28, 2026

Renders a specific tile of a pyramid as a PNG image and returns the result as a bytea value.

Syntax

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

Use the first overload to identify the tile by its ID string. Use the second overload to identify the tile by its x, y, and z coordinates.

Parameters

ParameterDescription
nameThe name of the pyramid.
keyThe tile ID in 'z_x_y' format, compatible with the EPSG:4326 and EPSG:3857 coordinate systems.
xThe x coordinate of the tile.
yThe y coordinate of the tile.
zThe z coordinate of the tile.
styleA JSON string that controls how the PNG is rendered. Pass an empty string ('') to use the default style.

Style fields

FieldTypeDefaultDescription
backgroundstring#FFFFFFFFRGBA color of the background. Default is white.
line_colorstring#000000FFRGBA color of dots and edges. Default is black.
fill_colorstring#F4A460FFRGBA color of the tile fill. Default is brown.
line_widthint1Line width in pixels.
point_sizeint10Dot diameter in pixels. Each dot is rendered as a circle.
parallel_unitint50000Number of elements each parallel rendering task processes.

All color values use RGBA hexadecimal format, for example #RRGGBBAA.

Example style JSON:

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

Usage notes

Tile ID format

The key parameter follows the 'z_x_y' format and is compatible with both the EPSG:4326 and EPSG:3857 coordinate systems.

For EPSG:4326:

  • The number of chunks on the x axis is twice the number on the y axis.

  • The z coordinate starts at 1. When z is 1, the only valid tile IDs are 1_0_0 and 1_1_0.

Output image size

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

Examples

The following examples use the roads pyramid and pass an empty style string to use the default rendering style.

-- Render a tile using a tile ID string
SELECT ST_AsPng('roads', '3_1_6', '');
st_aspng
----------
0xFFAABB8D8A6678...

-- Render the same tile using explicit x, y, z coordinates
SELECT ST_AsPng('roads', 1, 6, 3, '');
st_aspng
----------
0xFFAABB8D8A6678...