This topic describes the ST_AsPng function, which generates a PNG image based on the ID of a tile from a pyramid.

Syntax

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

Parameters

Parameter Description
name The name of the pyramid.
key The ID of the tile.
x The x value in the tile ID.
y The y value in the tile ID.
z The z value in the tile ID.
style The style that is used to render the image. The value of this parameter is a JSON string.

The following table describes the fields in the style parameter.

Field Type Default value Description
background string #FFFFFFFF The RGBA color of the background in the image. The default color is white.
line_color string #000000FF The RGBA color of dots and edges in the image. The default color is black.
fill_color string #F4A460FF The RGBA color of the tile in the image. The default color is brown.
line_width int 1 The width per line in the image. Unit: pixels.
point_size int 10 The size per dot in the image. Unit: pixels. By default, each dot is a circle with a diameter of 10 pixels.

The following example shows the settings of the preceding fields in the style parameter:

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

Description

The tile ID that is specified by the key parameter is in the 'z_x_y' format based on the EPSG:4326 or EPSG:3857 coordinate system.

Note
  • If the EPSG:4326 coordinate system is used, the number of chunks on the x axis is twice the number of chunks on the y axis. The z value starts from 1. If the z value is 1, the tile ID can only be 1_0_0 or 1_1_0.
  • The size of the PNG image that is rendered based on the specified style parameter is equal to the value of the tileSize parameter that is specified for the pyramid. If you do not specify the style parameter, the default style is used.

Example

select ST_AsPng('roads', '3_1_6', '');
st_aspng
----------
0xFFAABB8D8A6678...

select ST_AsPng('roads', 1, 6, 3, '');
st_aspng
----------
0xFFAABB8D8A6678...