Add a Geometry Manipulation to Your Map

Include a simple geometry manipulation, such as buffer, bounding box or simplify.

Map Tools

The Map Tools allow for easily adding a geometry manipulation to your map. In the example below, the underlying dataset is a set of points at all airports in the world. We wrote a query that returns all airports in Japan and creates a circle at those points using the postgis function ST_Buffer.

Using ST_Buffer is just an example. One could use any other function that takes a geometry as input and returns a geometry, such as ST_Envelope or ST_Simplify. A manipulation like ST_Buffer demonstrates the advantage of creating vector tiles when they're called by a user rather than precomputing them. First, when choosing your buffer parameter, you'd like to see how the shapes look on the map. When the tiles are created on demand, you can instantly see them. You don't have to first create a full tiling. Second, if you want to change the buffer parameter, you simply change that value in the DB2Vector tool. You can preview the change before you publish it. Then, if you click publish, the change will propagate immediately. No need to recreate a full directory of tiles.

Our simple example creates a small ring showing a 50 km radius around all airports in Japan.

The code below demonstrates where to include the geometry manipulation. Additionally, this example shows a simple join, where we've selected all airports with geometry intersecting the geometry for Japan in the countries tables.

WITH boundingbox AS(
  SELECT
    ST_MakeEnvelope(
      %(xmin)s,
      %(ymin)s,
      %(xmax)s,
      %(ymax)s,
      3857
    ) AS geom
),
mvtgeom AS (
  SELECT
    ST_AsMVTGeom(
      ST_Transform(ST_Buffer(sourceTable.geom::geography, 50000)::geometry, 3857),
      boundingbox.geom
    )
  FROM
    demo.airports sourceTable,
    demo.countries countriesTable,
    boundingbox
  WHERE
    ST_Intersects(
      ST_Transform(boundingbox.geom, 4326),
      sourceTable.geom
    )
    AND ST_Intersects(sourceTable.geom, countriesTable.geom)
    AND countriesTable.sovereignt = 'Japan'
)
SELECT
  ST_AsMVT(mvtgeom.*)
FROM
  mvtgeom;

About

Clockwork Micro is based in Seattle.

Services

Contact

Email:

info@clockworkmicro.com
Copyright2024Clockwork Micro. All rights reserved.

Clockwork Micro