tiler
ADVANCED
We currently provide procedures to create the following kind of tilesets:
- Spatial index tiles (aggregates spatial indexes into tiles at specific resolutions)
- Geometry-based MVT tiles of two types:
- simple tilesets to visualize features individually
- aggregation tilesets to generate aggregated point visualizations
tiler.CREATE_SIMPLE_TILESET(input, output_table, options)
Description
Create a simple tileset from a table, with feature dropping.
input
:TEXT
that can either contain a table name (e.g.database.schema.tablename
) or a full query (e.g.(SELECT * FROM database.schema.tablename)
).output_table
:TEXT
of the formatdatabase.schema.tablename
where the resulting tileset will be stored. The database and schema must exist and the caller needs to have permissions to create a new table in it. The process will fail if the table already exists.options
:TEXT
containing a valid JSON with the different options. Valid options are described in the table below.
Option | Description |
---|---|
geom_column | Default: "geom" . A STRING that marks the name of the geometry column that will be used. It must be of type GEOMETRY . |
zoom_min | Default: 0 . An INTEGER that defines the minimum zoom level for tiles. Any zoom level under this level won't be generated. |
zoom_max | Default: 12 . An INTEGER that defines the maximum zoom level for tiles. Any zoom level over this level won't be generated. If not provided, the appropriate maximum zoom level is inferred from the size of the features. |
tile_extent | Default: 4096 . An INTEGER defining the extent of the tile in integer coordinates as defined by the MVT spec. |
tile_buffer | Default: 16 . An INTEGER defining the additional buffer added around the tiles in extent units, which is useful to facilitate geometry stitching across tiles in the renderers. In aggregation tilesets, this property is currently not available and always 0 as no geometries go across tile boundaries. |
max_tile_size_kb | Default: 1024 . An INTEGER that determines the maximum tile size, in kilobytes, before compression. |
max_tile_features | Default: 0 (disabled). An INTEGER that sets the maximum number of features a tile might contain. This limit is applied before max_tile_size_kb , i.e., the tiler will first drop as many features as needed to keep this amount, and then continue with the size limits (if required). To configure in which order are features kept, use in conjunction with tile_feature_order . |
tile_feature_order | Default: "" . A TEXT defining the order in which properties are added to a tile. This expects the SQL ORDER BY keyword definition, such as "aggregated_total DESC", the "ORDER BY" part isn't necessary. Note that in aggregation tilesets you can only use columns defined as properties, but in simple feature tilesets you can use any source column no matter if it's included in the tile as property or not. As suggestion, we recommend to use RANDOM() for points datasets, ST_LENGTH() from lines and ST_AREA() for polygons. |
max_tile_size_strategy | Default: "throw_error" . A STRING that specifies how to apply the limit defined by max_tile_features . There are three options available:
|
generate_feature_id | |
metadata | Default: {} . A JSON object to specify the associated metadata of the tileset. Use this to set the name, description and legend to be included in the TileJSON. Other fields will be included in the object extra_metadata. |
properties | Default: {} . A JSON object that defines the extra properties that will be included associated to each cell feature. Each property is defined by its name and type (Number, Boolean or String). Check out the examples included below. |
Result
The generated tileset consists of a table with the following columns, where each row represents a tile:
z
: zoom level of the tile.x
: X-index of the tile (0
to2^Z-1
).y
: Y-index of the tile (0
to2^Z-1
).data
: contents of the tile in MVT format. It will contain the resulting features and their attributes (as defined byproperties
).
Additionally, there is a row in the tileset, identified by
Z=-1
, in which the data
column contains metadata about the tileset in JSON format. It includes the following properties:bounds
: geographical extents of the source as a string inXmin, Ymin, Xmax, Ymax
format.center
: center of the geographical extents asX, Y, Z
, where theZ
represents the zoom level where a single tile spans the whole extents size.zmin
: minimum zoom level in the tileset.zmax
: maximum zoom level in the tileset.tilestats
: stats about the feature's properties. In addition to its name (attribute
) andtype
, it containsmin
,max
,average
andsum
.
Example
1
CALL carto.CREATE_SIMPLE_TILESET(
2
'select * from MYDB.MYSCHEMA.carto_geography_usa_censustract',
3
'MYDB.MYSCHEMA.carto_geography_usa_censustract_tileset',
4
'{
5
"zoom_min":0,
6
"zoom_max":5,
7
"metadata": {
8
"name": "censustract_tileset",
9
"description": "A description"
10
},
11
"properties":{
12
"geoid":"String",
13
"do_perimeter":"Number",
14
"do_label":"String"
15
}
16
}'
17
);
tiler.CREATE_POINT_AGGREGATION_TILESET(input, output_table, options)
Description
Generates a point aggregation tileset.
input
:TEXT
that can either contain a table name (e.g.database.schema.tablename
) or a full query (e.g.(SELECT * FROM database.schema.tablename)
).output_table
:TEXT
of the formatdatabase.schema.tablename
where the resulting tileset will be stored. The database and schema must exist and the caller needs to have permissions to create a new table in it. The process will fail if the table already exists.options
:TEXT
containing a valid JSON with the different options. Valid options are described in the table below.
Option | Description |
---|---|
geom_column | Default: "geom" . A STRING that marks the name of the geometry column that will be used. It must be of type GEOMETRY . |
zoom_min | Default: 0 . An INTEGER that defines the minimum zoom level for tiles. Any zoom level under this level won't be generated. |
zoom_max | Default: 12 . An INTEGER that defines the maximum zoom level for tiles. Any zoom level over this level won't be generated. |
aggregation_resolution | Default: 6 . An INTEGER that specifies the resolution of the spatial aggregation.
Aggregation for zoom z is based on quadgrid cells at z + resolution level . For example, with resolution 6 , the z0 tile will be divided into cells that match the z6 tiles, or the cells contained in the z10 tile will be the boundaries of the z16 tiles within them. In other words, each tile is subdivided into 4^resolution cells, which is the maximum number of resulting features (aggregated) that the tiles will contain..
Note that adding more granularity necessarily means heavier tiles which take longer to be transmitted and processed in the final client, and you are more likely to hit the internal memory limits. |
aggregation_placement | Default: "cell-centroid" . A TEXT that defines what type of geometry will be used to represent the cells generated in the aggregation, which will be the features of the resulting tileset. There are currently four options:
|
metadata | Default: {} . A JSON object to specify the associated metadata of the tileset. Use this to set the name, description and legend to be included in the TileJSON. Other fields will be included in the object extra_metadata. |
properties | Default: {} . A JSON object that defines the properties that will be included associated with each cell feature. Each property is defined by its name, type (Number, Boolean, String, etc.) and formula to be applied to the values of the points that fall under the cell. This formula can be any SQL formula that uses an aggregate function supported by Postgres and returns the expected type. Note that every property different from Number will be casted to String. |
tile_extent | Default: 4096 . An INTEGER defining the extent of the tile in integer coordinates as defined by the MVT spec. |
tile_buffer | Default: 16 . An INTEGER defining the additional buffer added around the tiles in extent units, which is useful to facilitate geometry stitching across tiles in the renderers. In aggregation tilesets, this property is currently not available and always 0 as no geometries go across tile boundaries. |
max_tile_size_kb | Default: 1024 . An INTEGER defining the approximate maximum size for a tile in kilobytes, before compression. |
max_tile_features | Default: 0 (disabled). An INTEGER that sets the maximum number of features a tile might contain. This limit is applied before max_tile_size_kb , i.e., the tiler will first drop as many features as needed to keep this amount, and then continue with the size limits (if required). To configure in which order are features kept, use in conjunction with tile_feature_order . |
tile_feature_order | Default: "" . A TEXT defining the order in which properties are added to a tile. This expects the SQL ORDER BY keyword definition, such as "aggregated_total DESC", the "ORDER BY" part isn't necessary. Note that in aggregation tilesets you can only use columns defined as properties, but in simple feature tilesets you can use any source column no matter if it's included in the tile as property or not. |
max_tile_size_strategy | Default: "throw_error" . A STRING that specifies how to apply the limit defined by max_tile_features . There are three options available:
|
Result
The generated tileset consists of a table with the following columns, where each row represents a tile:
z
: zoom level of the tile.x
: X-index of the tile (0
to2^Z-1
).y
: Y-index of the tile (0
to2^Z-1
).data
: contents of the tile in MVT format. It will contain the resulting points or cell (location of the aggregated features according toaggregation_placement
) and their attributes (as defined byproperties
).
Additionally, there is a row in the tileset, identified by
Z=-1
, in which the data
column contains metadata about the tileset in JSON format. It includes the following properties:bounds
: geographical extents of the source as a string inXmin, Ymin, Xmax, Ymax
format.center
: center of the geographical extents asX, Y, Z
, where theZ
represents the zoom level where a single tile spans the whole extents size.zmin
: minimum zoom level in the tileset.zmax
: maximum zoom level in the tileset.tilestats
: stats about the feature's properties. In addition to its name (attribute
) andtype
, it containsmin
,max
,average
andsum
.
Example
1
CALL carto.CREATE_POINT_AGGREGATION_TILESET(
2
'SELECT * FROM database.schema.cities_table',
3
'database.schema.cities_tileset',
4
'{
5
"geom_column": "geom",
6
"zoom_min": 0,
7
"zoom_max": 12,
8
"aggregation_resolution": 5,
9
"aggregation_placement": "cell-centroid",
10
"properties": {
11
"num_cities": {
12
"formula": "COUNT(*)",
13
"type": "Number"
14
},
15
"population_sum": {
16
"formula": "SUM(population)",
17
"type": "Number"
18
},
19
"city_name": {
20
"formula": "(CASE WHEN COUNT(*) <= 1 THEN MIN(city_name) ELSE NULL END)",
21
"type": "String"
22
}
23
},
24
"metadata": {
25
"name": "Population",
26
"description": "Population in the cities"
27
}
28
}'
29
);
In the example above, for all features we would get a property
"num_cities"
with the number of points that fall in it and "population_sum"
with the sum of the population in those cities. In addition to this, when there is only one point that belongs to this property (and only in that case) we will also get the column values from the source data in "city_name"
.CREATE_SPATIAL_INDEX_TILESET(source_table, target_table, options)
Description
Creates a tileset that uses a spatial index (H3 and QUADBIN are currently supported), aggregating data from an input table that uses that same spatial index.
Aggregated data is computed for all levels between
resolution_min
and resolution_max
. For each resolution level, all tiles for the area covered by the source table are added, with data aggregated at level resolution + aggregation_resolution
.source_table
:TEXT
that can either be a table name (e.g.schema.tablename
or a full query (e.g.SELECT * FROM database.schema.tablename
).target_table
: Where the resulting table will be stored. It must be aTEXT
of the formdatabase.schema.tablename
. Thedatabase
can be omitted (in which case the current one will be used). Theschema
can also be omitted and the first on thesearch_path
will be used. The schema must exist and the caller needs to have permissions to create a new table on it. The process will fail if the target table already exists.options
:TEXT
containing a valid JSON with the different options. Valid options are described the table below.
Option | Description |
---|---|
resolution_min | Default: 0 . An NUMBER that defines the minimum resolution level for tiles. Any resolution level under this level won't be generated. |
resolution_max | Default: 12 for QUADBIN tilesets, 6 for H3 tilesets. A NUMBER that defines the maximum resolution level for tiles. Any resolution level over this level won't be generated. |
spatial_index_column | A STRING in the format spatial_index_type:column_name , with spatial_index_type being the type of spatial index used in the input table (can only be quadbin at the moment), and column_name being the name of the column in that input table that contains the tile ids. Notice that the spatial index name is case-sensitive. The type of spatial index also defines the type used in the output table, which will be QUADBIN (for spatial index type quadbin ). |
resolution | A NUMBER defining the resolution of the tiles in the input table. |
aggregation_resolution | Defaults: 6 for QUADBIN tilesets, 4 for H3 tilesets. A NUMBER defining the resolution to use when aggregating data at each resolution level. For a given resolution , data is aggregated at resolution_level + aggregation resolution . |
properties | A JSON object containing the aggregated properties to add to each tile in the output table. It cannot be empty, since at least one property is needed for aggregating the original values |
metadata | Default: {} . A JSON object to specify the associated metadata of the tileset. Use this to set the name, description and legend to be included in the TileJSON. Other fields will be included in the object extra_metadata. |
tip
Any option left as
NULL
will take its default value if available.Examples
1
CALL carto.CREATE_SPATIAL_INDEX_TILESET(
2
'YOUR_DATABASE.YOUR_SCHEMA.INPUT_TABLE_QUADBIN_LEVEL14',
3
'YOUR_DATABASE.YOUR_SCHEMA.OUTPUT_TILESET_QUADBIN_LEVEL14',
4
'{
5
"spatial_index_column": "quadbin:index",
6
"resolution": 14,
7
"resolution_min": 0,
8
"resolution_max": 8,
9
"aggregation_resolution": 6,
10
"properties": {
11
"population": {
12
"formula": "SUM(population)",
13
"type": "Number"
14
}
15
}
16
}'
17
);
1
CALL carto.CREATE_SPATIAL_INDEX_TILESET(
2
'SELECT * FROM YOUR_DATABASE.YOUR_SCHEMA.INPUT_TABLE_H3_LEVEL10',
3
'YOUR_DATABASE.YOUR_SCHEMA.OUTPUT_TILESET_H3_LEVEL10',
4
'{
5
"spatial_index_column": "h3:index",
6
"resolution": 10,
7
"resolution_min": 0,
8
"resolution_max": 6,
9
"aggregation_resolution": 4,
10
"properties": {
11
"population": {
12
"formula": "SUM(population)",
13
"type": "Number"
14
}
15
}
16
}'
17
);
Additional examples
Last modified 6mo ago