mapbox / mapbox/tippecanoe

Feature filter error with valid Mapbox Style Expression

Open
#836 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
3.1k
Forks
430
PR merge metrics
No merged PRs in 30d

Description

It appears that `-j` doesn't work with an _expression_, but only the deprecated filter syntax, is that true? (Given that the link in the README points to https://docs.mapbox.com/mapbox-gl-js/style-spec/#other-filter, which says that it's deprecated syntax).

I'm making vector tiles from contour lines in a newline-delimited GeoJSON file. I'm trying to include only contours that have an elevation that is a multiple of 20, but I'm getting errors of `key is not a string`. Here's a simplified example, with data at the bottom:
```
> tippecanoe -Z11 -z13 -P -y ele_m -l contour_10m -j '{"*": ["==", ["%", ["get", "ele_m"], 20], 0]}' -f -o out.mbtiles contours.geojson
"!has" key is not a string: ["==",["%",["get","ele_m"],20],0]
"!has" key is not a string: ["==",["%",["get","ele_m"],20],0]
```

I believe that this is a valid expression because a simplified style that uses it as a filter passes `gl-style-validate`:
`tempstyle.json`
```json
{
"version": 8,
"name": "teststyle",
"sources": {
"contours": {
"type": "vector",
"url": ""
}
},
"sprite": "https://example.com",
"glyphs": "https://example.com/{fontstack}/{range}.pbf",
"layers": [
{
"id": "contour_label2",
"type": "symbol",
"source": "contours",
"source-layer": "contour_10m",
"filter": ["==", ["%", ["get", "ele_m"], 20], 0],
"layout": {},
"paint": {}
}
],
"id": "teststyle"
}
```

Example data:
`contours.geojson`
```json
{ "type": "Feature", "properties": { "ID": 0, "ele_m": 200.0 }, "geometry": { "type": "LineString", "coordinates": [ [ -116.0076389, 33.0005556 ], [ -116.0076389, 33.0005093 ], [ -116.0075463, 33.0004784 ], [ -116.0074537, 33.0004861 ], [ -116.0073611, 33.0005093 ], [ -116.0073611, 33.0005556 ] ] } }
{ "type": "Feature", "properties": { "ID": 1, "ele_m": 210.0 }, "geometry": { "type": "LineString", "coordinates": [ [ -116.0328858, 33.0005556 ], [ -116.0328858, 33.0005093 ], [ -116.0328241, 33.0004167 ], [ -116.0327315, 33.0004167 ], [ -116.0326389, 33.0005093 ], [ -116.0326389, 33.0005556 ] ] } }
{ "type": "Feature", "properties": { "ID": 2, "ele_m": 220.0 }, "geometry": { "type": "LineString", "coordinates": [ [ -116.1497685, 33.0005556 ], [ -116.1497685, 33.0005093 ], [ -116.1497685, 33.0005093 ], [ -116.1497685, 33.0005093 ], [ -116.1497685, 33.0005556 ] ] } }
{ "type": "Feature", "properties": { "ID": 3, "ele_m": 220.0 }, "geometry": { "type": "LineString", "coordinates": [ [ -116.1461883, 33.0005556 ], [ -116.1461883, 33.0005093 ], [ -116.14625, 33.000463 ], [ -116.1463426, 33.0004784 ], [ -116.1464352, 33.0004784 ], [ -116.1465278, 33.000463 ], [ -116.1465741, 33.0005093 ], [ -116.1465741, 33.0005556 ] ] } }
{ "type": "Feature", "properties": { "ID": 4, "ele_m": 220.0 }, "geometry": { "type": "LineString", "coordinates": [ [ -116.1409722, 33.0005556 ], [ -116.1409722, 33.0005093 ], [ -116.1409722, 33.0005093 ], [ -116.1410648, 33.0005093 ], [ -116.1411574, 33.0005093 ], [ -116.1411574, 33.0005093 ], [ -116.1411574, 33.0005556 ] ] } }
{ "type": "Feature", "properties": { "ID": 5, "ele_m": 230.0 }, "geometry": { "type": "LineString", "coordinates": [ [ -116.1105093, 33.0005556 ], [ -116.1105093, 33.0005093 ], [ -116.1104167, 33.0004907 ], [ -116.1103241, 33.0005093 ], [ -116.1103241, 33.0005556 ] ] } }
{ "type": "Feature", "properties": { "ID": 6, "ele_m": 230.0 }, "geometry": { "type": "LineString", "coordinates": [ [ -116.0056944, 33.0005556 ], [ -116.0056944, 33.0005093 ], [ -116.0056944, 33.0005093 ], [ -116.0056944, 33.0005093 ], [ -116.0056944, 33.0005556 ] ] } }
{ "type": "Feature", "properties": { "ID": 7, "ele_m": 240.0 }, "geometry": { "type": "LineString", "coordinates": [ [ -116.0543056, 33.0005556 ], [ -116.0543056, 33.0005093 ], [ -116.0543056, 33.0005093 ], [ -116.0543981, 33.000463 ], [ -116.0544907, 33.0004475 ], [ -116.0545833, 33.000463 ], [ -116.0546759, 33.0005093 ], [ -116.0546759, 33.0005093 ], [ -116.0546759, 33.0005556 ] ] } }
{ "type": "Feature", "properties": { "ID": 8, "ele_m": 270.0 }, "geometry": { "type": "LineString", "coordinates": [ [ -116.1717747, 33.0005556 ], [ -116.1717747, 33.0005093 ], [ -116.171713, 33.0004167 ], [ -116.1716204, 33.000463 ], [ -116.1715895, 33.0005093 ], [ -116.1715895, 33.0005556 ] ] } }
{ "type": "Feature", "properties": { "ID": 9, "ele_m": 280.0 }, "geometry": { "type": "LineString", "coordinates": [ [ -116.1694907, 33.0005556 ], [ -116.1694907, 33.0005093 ], [ -116.1694907, 33.0005093 ], [ -116.1694907, 33.0005093 ], [ -116.1694907, 33.0005556 ] ] } }
```

```
> tippecanoe --version
tippecanoe v1.34.3
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at tippecanoe's `-j` command-line handling and the expression parsing path, using the supplied `contours.geojson` command as a reproduction. Check how the expression is interpreted and compare it with the `gl-style-validate` example; done means the command accepts the valid expression without the `key is not a string` error and filters contours by elevation.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.