GeoSQL.PostGIS.VectorTiles (GeoSQL v1.4.2)

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},
          compose_query_fn: fn query -> from(q in query, where: not is_nil(q.name)) end
        }
      ]


      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.

Custom clauses can be added per-layer using the the optional compose_query_fn which is called with the layer's Ecto query. The function must also return an ecto function. This is particularly useful for filtering with where clauses.

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()