mapbox / tippecanoe

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

filter features by field #893

Open luqinghui opened 3 years ago

luqinghui commented 3 years ago

My data has a "level" field(the start zoom this feature will been shown), I want to filter feature by "$zoom" and "level".

For example, feature id level
1 10
2 10
3 11
4 11
5 12
6 12

In zoom 10, the tiles only contain feature 1 and 2. In zoom 11, the tiles contain feature 1, 2, 3 and 4. In zoom 12, the tiles contain all feature.

I use thne command like 👇: ippecanoe -Z0 -z18 -o ./example.mbtiles -j '{ "*": [">=", "$zoom", "level"]}' -ps -pn -pt -pk -pf --force ./example.geojson

but it return an warn Warning: mismatched type in comparison: [">=","$zoom","level"], and the generated mbtiles's size is only 33kb, looks like there's no valid tile in mbtiles.

e-n-f commented 3 years ago

Your level field is probably stored as a string instead of a number. You should be able to convert it to a number with -Tlevel:int.

luqinghui commented 3 years ago

Your level field is probably stored as a string instead of a number. You should be able to convert it to a number with -Tlevel:int.

thanks for your answer, but I check the data, the "level" field type is "integer", and even I add the -Tlevel:int, it still have the same problem😄

benstrege commented 2 years ago

I am having the same problem. The issue appears to be that if the field is last, it does not convert it to the proper type.

These two filters work with no problems: --feature-filter='{ "*": [ "any", [ ">=", "show_at_zoom", 5 ] ] }' --feature-filter='{ "*": [ "any", [ ">=", "$zoom", 5 ] ] }'

However, this does not work and gives the mismatch error: --feature-filter='{ "*": [ "any", [ ">=", "$zoom", "show_at_zoom" ] ] }'

These two filters do not work, either, and give a "!has" key is not a string error. --feature-filter='{ "*": [ "any", [ ">=", 5, "$zoom" ] ] }' --feature-filter='{ "*": [ "any", [ ">=", 5, "show_at_zoom" ] ] }'

I have used the -T declaration, and it does not make a difference