felt / tippecanoe

Build vector tilesets from large collections of GeoJSON features.
BSD 2-Clause "Simplified" License
874 stars 76 forks source link

Seemingly misleading tilestats when a source has more than 1 geometry type #215

Open zabop opened 4 months ago

zabop commented 4 months ago

Recently I noticed that I find the tilestats section of the metadata.json slightly surprising.

Short summary: I created a GeoJSON file with 3 geometries: a point, a line, and a polygon. I processed it using tippecanoe (creating both an mbtiles file and a directory tree of pbf files). All 3 input geometries show up in QGIS when the mbtiles file is loaded. However, the tilestats section of metadata.json only mentions Point as geometry.


Steps to reproduce the issue

Create example GeoJSON file:

#!/usr/bin/python3

import geopandas as gpd
import shapely.geometry

point = shapely.geometry.Point(12, 34)
linestring = shapely.geometry.LineString([[10,20],[-30,40]])
polygon = shapely.geometry.Polygon([[0,0],[0,10],[10,10],[0,0]])

gpd.GeoSeries([point,linestring,polygon]).set_crs(4326).to_file("example.geojson")

Tile data to an mbtiles file:

tippecanoe -Z2 -z10 -o out.mbtiles example.geojson

Tile data to a directory tree:

tippecanoe -Z2 -z10 -e out example.geojson

Open mbtiles file in QGIS:

image

Features show up as expected. Inspect the tilestats section of metadata.json:

cat out/metadata.json | jq '.json' | jq -c '. | fromjson' | jq '.tilestats'

Get:

{
  "layerCount": 1,
  "layers": [
    {
      "layer": "example",
      "count": 3,
      "geometry": "Point",
      "attributeCount": 0,
      "attributes": []
    }
  ]
}

It's nice that we have "count": 3 (we started with 3 features). However, why do we have "geometry": "Point"?

I think it would be nice to have ["Point","LineString","Polygon"] instead, for example. Or some other value which enables users to know that not only Point geometries where used to create the tiles. Alternatively, I think an option forcing tippecanoe to fail if tilestats doesn't accurately represent input geometries (perhaps --be-strict-with-tilestats?) would be very useful.

Thanks for sharing some insights on the matter :) Tippecanoe is awesome, thanks a lot for developing it.