This topic describes the ST_AsPng function, which converts a specific tile of a pyramid to a PNG image based on the ID of the tile.
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 coordinate in the ID of the tile. |
y | The y coordinate in the ID of the tile. |
z | The z coordinate in the ID of the tile. |
style | The style that is used to render the PNG 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 PNG image. The default color is white. |
line_color | string | #000000FF | The RGBA color of dots and edges in the PNG image. The default color is black. |
fill_color | string | #F4A460FF | The RGBA color of the tile in the PNG image. The default color is brown. |
line_width | int | 1 | The width per line in the PNG image. Unit: pixels. |
point_size | int | 10 | The size per dot in the PNG image. Unit: pixels. By default, each dot is a circle with a diameter of 10 pixels. |
parallel_unit | int | 50000 | The number of elements that each task running in parallel renders. |
The following example shows the settings of the 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 in compliance with the EPSG:4326
or EPSG:3857
coordinate system.
Note
- A title consists of multiple chunks. 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 coordinate starts from 1. If the z coordinate is 1, the tile ID can only be1_0_0
or1_1_0
. - The size of the PNG image that is rendered based on the 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.
Examples
select ST_AsPng('roads', '3_1_6', '');
st_aspng
----------
0xFFAABB8D8A6678...
select ST_AsPng('roads', 1, 6, 3, '');
st_aspng
----------
0xFFAABB8D8A6678...