Skip to content

Tile Generation

Vector Tile Generation is the process of creating a set of map tiles from geometric feature data. These slippy map tiles can be used to visualize the map data in a web map, mobile app, or desktop GIS software. SedonaMaps provides a set of APIs to generate vector tiles from a given set of geometries.

Class: sedonamaps.core.VectorTiles.GenerationConfiguration

This class is used to configure the tile generation process. The parameters help developer customers control the tiles to generate and their contents. The parameters are as follows:

  • minZoom the lowest zoom for which to generate tiles. Value may range from 0 to 20.
  • maxZoom the highest zoom for which to generate tiles. Value may range from 0 to 20.
  • tileResolution the resolution of the tiles to generate
  • buffer the buffer (in the same units as resolution) to apply to the tiles
  • featureFilter a predicate Column for filtering features, optional
  • tileFilter a Column for manipulating the array of features within a tile, optional
  • featureSimplify a Column for manipulating feature geometries, optional
  • maxFeaturesPerTile the maximum number of features to include in each tile, optional
  • cacheFrequency the frequency at which to cache the dataset, optional. e.g 2 means every 2nd zoom level. Default is 2

Class: sedonamaps.core.VectorTiles

This class is used to generate tiles from a set of features. The features must have a geometry column and a layer column.

  • Method: generate
    • Python definition:
      def generate(features: DataFrame, config: GenerationConfig = GenerationConfig()) -> DataFrame
      
    • Scala definition:
      def generate(features: Dataset[Row], config: GenerationConfig = GenerationConfig()): Dataset[Row]
      

Generates tiles from a set of features. The features must have a geometry column of the Geometry type and a layer column of string type represent what layer that feature belongs in. An optional Integer or Long column id can be included to persist an ID into the tilesThe features can be of any geometry type. The output dataset will have a tile column specifying the tile and a feature column containing clipped, simplified features that belong in that tile, projected into the [0..1] coordinate space of the tile for its x and y values.

Parameters - features the features to generate tiles from - config the configuration for generating tiles

Returns - a Dataset of tiles ready to be output as MVTs

from sedonamaps.core import VectorTiles

tiles_df = VectorTiles.generate(
    roads_df.union(buildings_df),
    VectorTiles.GenerationConfig(5, 17, 4096, .1)
)
tiles_df.show(3, 90, True)
import com.wherobots.sedonamaps.VectorTiles.generate
import com.wherobots.sedonamaps.VectorTiles.GenerationConfig

val featuresDf = sedona.read.parquet("path/to/features")
  .withColumn("layer", lit("roads"))
  .withColumn("geometry", st_geomFromWKT($"geometry"))
val tilesDf = generate(
  featuresDf,
  GenerationConfig(5, 17, 4096, .1)
)
tilesDf.show(3, 90, true)
import com.wherobots.sedonamaps.VectorTiles.generate;
import com.wherobots.sedonamaps.VectorTiles.GenerationConfig;

featuresDf Dataset<Row> = sedona.read.parquet("path/to/features");
tilesDf Dataset<Row> = generate(
        featuresDf,
        new GenerationConfig(5, 17, 4096, .1)
);

tilesDf.show(3, 90, true);

SedonaMaps also provides a FileFormat for writing out the tiles dataframe to a set of mvtile files. The mvtile files will be laid out in a directory structure that mirrors the z/x/y layout of the tiles:

<user-specified-output-path>/<z>/<x>/<y>.mvt

Warning

When generating tiles from zoom 0 to x, you will generate up to 4^(x+1) tiles (files) depending on the spatial extent of the data. This can be a very large number (billions) of tiles. The runtime and s3 transfer costs can thus also be high.

Users can pass the following options to the write method: - extent the extent of the tile grid, default is 4096. This is defacto the resolution of the tiles, defining the discrete positions that a coordinate can take in the tile grid. default is 4096. - extension the file extension of the output files, default is "mvt".

tiles_df.write.format("mvt").option("extent", 256).save("path/to/output")
tilesDf.write.format("mvt").option("extent", 256).save("path/to/output")
tilesDf.write.format("mvt").option("extent", 256).save("path/to/output");

Last update: March 9, 2024 00:18:26