systemed / tilemaker

Make OpenStreetMap vector tiles without the stack
https://tilemaker.org/
Other
1.4k stars 226 forks source link

Merges compatible Point features into MultiPoint #725

Closed daniel-j-h closed 1 month ago

daniel-j-h commented 1 month ago

For #719: This changeset merges multiple compatible points into a single multipoint.

Motivation: while looking into the MVT spec and how it's implemented in Everything You Wanted to Know About Vector Tiles (But Were Afraid to Ask) I learned about inefficiencies in encoding single points in tiles and how multipoints help there. Turns out tilemaker did not emit multipoints - let's change that!

This changeset combines multiple point features into a single multipoint so that the tiles will be smaller, there is less to encode/decode, and the frontend clients only have to decode a single multipoint feature with multiple MoveTo commands.

How much this will help in practice depends on the configs and areas used and the points have to be compatible (attributes).

@systemed I would appreciate a review here since my C++ is a bit rusty nowadays! Also how do we best test this change? I ran it manually on a few pbf files but otherwise how do we make sure this is working as intended?

More context in


If you run with the --verbose flag you get to see the debug output

Merging 20 points into a multipoint
Merging 5 points into a multipoint
Merging 4 points into a multipoint
Merging 2 points into a multipoint
Merging 4 points into a multipoint
Merging 4 points into a multipoint
Merging 4 points into a multipoint
Merging 4 points into a multipoint
Merging 4 points into a multipoint
Merging 5 points into a multipoint
..
systemed commented 1 month ago

This looks really good - thank you!

I ran a quick test with a local pbf and then running the tile through vt2geojson, and the output is what you'd expect:

    {
      "type": "Feature",
      "geometry": {
        "type": "MultiPoint",
        "coordinates": [
          [
            -1.4897257089614868,
            51.87246698977762
          ],
          [
            -1.489870548248291,
            51.872523294874156
          ],
          [
            -1.4903587102890015,
            51.87297373310824
          ]
        ]
      },
      "properties": {
        "urban": 0,
        "type": "bicycle_parking",
        "vt_layer": "pois"
      }
    },

and they render properly:

Screenshot 2024-05-28 at 15 54 52

so I think this is good to go.