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
| Parameter | Type | Description |
|---|---|---|
name | cstring | The name of the pyramid. |
key | cstring | The tile ID in 'z_x_y' format. |
x | int | The x coordinate of the tile. |
y | int | The y coordinate of the tile. |
z | int | The z coordinate of the tile. |
style | cstring | A JSON string that controls how the PNG is rendered. If you do not specify this parameter, the default style is used. |
Style fields
| Field | Type | Default | Description |
|---|---|---|---|
background | string | #FFFFFFFF | Background color in RGBA format. Default is white. |
line_color | string | #000000FF | Color of dots and edges in RGBA format. Default is black. |
fill_color | string | #F4A460FF | Fill color of the tile in RGBA format. Default is brown. |
line_width | int | 1 | Line width in pixels. |
point_size | int | 10 | Dot diameter in pixels. Each dot is a circle with a diameter of 10 pixels. |
parallel_unit | int | 50000 | Number 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 theEPSG:4326orEPSG:3857coordinate 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 are1_0_0and1_1_0.The output PNG dimensions match the
tileSizeset 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...该文章对您有帮助吗?