Add a Simple WHERE Clause to Your Map

Include a simple SQL statement in your query, such as all counties with area over a certain size.

Map Tools

Map Tools allow you to easily display geospatial data based on simple statements, such as "all the counties in the state of Texas with area greater than 2,500 sqkm".

If you have a table with all of the counties in the US and their areas, you can easily create such a map. If you then want to change 2,500 sqkm to 3,000, you simply change that number, click publish, and the visual web map will update for all users.

Below we show this example query. The source table is demo.us_counties, and the field iso_3166_2 is the state field, which we set to be the US code for Texas, 'US-48'.

To implement such a query, you only need to add the additional statements after the intersection statement. The statement, of course, has to be a valid PostgreSQL condition.

WITH boundingbox AS(
  SELECT
    ST_MakeEnvelope(
      %(xmin)s,
      %(ymin)s,
      %(xmax)s,
      %(ymax)s,
      3857
    ) AS geom
),
mvtgeom AS (
  SELECT
    ST_AsMVTGeom(
      ST_Transform(sourceTable.geom, 3857),
      boundingbox.geom
    )
  FROM
    demo.counties_us sourceTable,
    boundingbox
  WHERE
    ST_Intersects(
      ST_Transform(boundingbox.geom, 4326),
      sourceTable.geom
    )
    AND sourceTable.area_sqkm > 2500
    AND iso_3166_2 = 'US-48'
)
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