iwpnd / tegola-cluster-points

Example on how to cluster points in PostGIS and serve via Tegola vector tiling service

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tegola-cluster-points

Example on how to cluster point data on different zoom levels.

Idea

Following a discussion on tegola issue #753

Say you have a bunch of points in your provider. You create two layers. First layer uses the center point of a cluster as geometry field. Second layer uses the default geometry field of your points. Then building your map, you use the first layer with the center points of the clusters from zoom level x to y and the second layer from y to z.

Usage

docker compose up

Generate 10.000 random points in a definied bounding box (here, Berlin). See sql/init.sql.

PGPASSWORD=password psql \
    -U user \
    -h localhost \
    -p 5433 \
    -d points \
    -a \
    -f /sql/init.sql

Open the tegola viewer at http://localhost/8080 and see the result.

Gotcha

The example clusters points in a proximity of 0.001 degree to each other. This is appoximately 111m, depending on where you are at in the world. For better results use another CRS and change the eps distance value of the provider sql to your liking.

License

MIT

Maintainer

Benjamin Ramser - @iwpnd. Project Link: https://github.com/iwpnd/tegola-cluster-points

Acknowledgements

Ying Wang - Generating random test data in PostGIS

Tegola - tegola.io

About

Example on how to cluster points in PostGIS and serve via Tegola vector tiling service

License:MIT License


Languages

Language:PLpgSQL 100.0%