3

I'm new to spatial algorithms and PostGIS functionality. Currently I have a Pg 10 + Postgis 2.4 database with table of more than 400 000 records (points with additional properties), with Node.JS tile server that generates and serves tiles for Mapbox GL JS plugin using PostGIS ST_ASMvt function. An d everything seems ok (generates very fast, caching without problems, etc), but there is one problem.

The problem is very big tiles (more than 2 mb) with big amount of features, so Mapbox GL JS renders it veeery sloooowly and eat a lot of memory (sometime my app is chrashing even on my laptop with 16 gb RAM). I can't just reduce the number of features by SQL LIMIT (just believe me, there are some business problems with the data in this case and on the map it looks very ugly).

map examples, each tile contains N thsnd number of features

And I think that I need to cluster some points that have a big density. So I want to merge the neighbors (and show as one point) at a high zooms and I think it will help with the memory and rendering speed (because of lesser number of features and tile size). But I don't know and cant find how to do this.

3

2 Answers 2

0

One quick way that doesn't actually cluster the points (but with as many points as you have, no one may notice), is to use Mapbox's LabelGrid function to de-densify the points that are being returned:

https://github.com/mapbox/postgis-vt-util#labelgrid

3
  • One issue with this approach is that it is done client-side, so still requires all points to be encoded in the tiles and transferred.
    – dr_jts
    Commented Nov 20 at 3:34
  • 1
    No, this is done in the sql queries to construct the tiles, so it's not client side
    – chrismarx
    Commented Nov 21 at 18:22
  • Ah right, and it's just a thin wrapper over the PostGIS ST_SnapToGrid.
    – dr_jts
    Commented Nov 21 at 23:18
0

You could implement grid-based clustering with representative points. It's described in this answer: https://gis.stackexchange.com/a/352703/14766

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.