GeoSQL.PostGIS.VectorTiles (GeoSQL v1.2.0)

View Source

In addition to support for functions related to Mapbox vector tiles, this module also provides support for generating complete tiles via generate/6.

The generate/6 function takes a list of GeoSQL.PostGIS.VectorTiles.Layer structs along with the tile coordinates and an Ecto.Repo:

    use GeoSQL.PostGIS

    def tile(zoom, x, y) do
      layers = [
        %PostGIS.VectorTiles.Layer{
          name: "pois",
          source: "nodes",
          columns: %{geometry: :geom, id: :node_id, tags: :tags}
        },
        %PostGIS.VectorTiles.Layer{
          name: "buildings",
          source: "buildings",
          columns: %{geometry: :footprint, id: :id, tags: :tags}
        }
      ]


      PostGIS.VectorTiles.generate(MyApp.Repo, zoom, x, y, layers)
    end

The resulting data can be loaded directly into map renderers such as MapLibre or OpenLayers with the MVT vector tile layer format.

Database prefixes ("schemas" in PostgreSQL) are also supported both on the whole tile query as well as per-layer.

For non-trivial tables, ensure that a GIST index exists on the geometry columns used.

Summary

SQL Functions

as_mvt(rows)

(macro)

as_mvt(rows, name)

(macro)

as_mvt(rows, name, extent)

(macro)

as_mvt(rows, name, extent, geom_name)

(macro)

as_mvt(rows, name, extent, geom_name, feature_id_name)

(macro)

as_mvt_geom(geometry, bounds)

(macro)

as_mvt_geom(geometry, bounds, options)

(macro)

tile_envelope(zoom, x, y)

(macro)

tile_envelope(zoom, x, y, bounds, margin \\ 0.0)

(macro)

Tile Generation

generate(repo, zoom, x, y, layers, db_prefix \\ nil)

@spec generate(
  repo :: Ecto.Repo.t(),
  zoom :: non_neg_integer(),
  x :: non_neg_integer(),
  y :: non_neg_integer(),
  layers :: [GeoSQL.PostGIS.VectorTiles.Layer.t()],
  db_prefix :: String.t() | nil
) :: term()