systemed / tilemaker

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

Setting _minzoom in attribute_function() doesn't work per feature #774

Open pdrhlik opened 4 weeks ago

pdrhlik commented 4 weeks ago

Hi,

I am using tilemaker to create contour tiles. I process some DEM data and use gdal to create shp contours. Each contour line has an elevation attribute. I want to show different contour lines on different zoom levels to reduce the tile size, eg.:

zoom 11: 50 m intervals zoom 12: 20 m intervals zoom 13: 10 m intervals zoom 14: 5 m intervals

Based on the documentation in the Shapefiles and GeoJSON section, this should be possible with a following attribute_function():

function attribute_function(attr, layer)
  if attr["elevation"] then
    local table = {}
    local elevation = math.floor(attr["elevation"])
    local minzoom = 14

    if elevation % 50 == 0 then
      minzoom = 11
    elseif elevation % 20 == 0 then
      minzoom = 12
    elseif elevation % 10 == 0 then
      minzoom = 13
    end

    table["elevation"] = elevation
    table["_minzoom"] = minzoom

    return table
  end

  return attr
end

This is my config.json file for reference.

{
  "layers": {
    "contour": { "minzoom": 11, "maxzoom": 14, "source": "contours/part1.shp", "source_columns": ["elevation"] },
    "contour_2": { "minzoom": 11, "maxzoom": 14, "source": "contours/part2.shp", "source_columns": ["elevation"], "write_to": "contour" },
    "contour_3": { "minzoom": 11, "maxzoom": 14, "source": "contours/part3.shp", "source_columns": ["elevation"], "write_to": "contour" }
  },
  "settings": {
    "minzoom": 11,
    "maxzoom": 14,
    "basezoom": 14,
    "include_ids": false,
    "bounding_box": [-180, -85, 180, 85]
  }
}

Unfortunately, this doesn't work. It seems that the _minzoom isn't applied per feature. Instead, the last _minzoom that is set is applied for the whole layer.

The code handling _minzoom is here (for shapefiles): https://github.com/systemed/tilemaker/blob/13b841d58f3f1bc1be6e4e7f86860e3eabfd91cf/src/shp_processor.cpp#L72-L74

Am I missing something here or is it not working as expected?

Thanks for any input, Patrik