geometalab / Vector-Tiles-Reader-QGIS-Plugin

Vector Tiles Reader QGIS-Plugin - QGIS Python plugin which reads Mapbox Vector Tiles from a server, a local MBTiles file or a directory
http://plugins.qgis.org/plugins/vector_tiles_reader/
GNU General Public License v2.0
150 stars 30 forks source link

Support "type": "categorical". #194

Open erictheise opened 6 years ago

erictheise commented 6 years ago

Our stylesheets include sections such as:

    {
      "id": "landuse_areas_z13",
      "type": "fill",
      "source": "osm",
      "source-layer": "landuse_areas",
      "minzoom": 13,
      "maxzoom": 24,
      "layout": {
        "visibility": "visible"
      },
      "paint": {
        "fill-color": {
          "property": "type",
          "type": "categorical",
          "default": "transparent",
          "stops": [
            [
              "wetland",
              "rgba(227, 233, 226, 1)"
            ],
            [
              "salt_pond",
              "rgba(236, 240, 241, 1)"
            ],
            [
              "basin",
              "rgba(144, 204, 203, 1)"
            ],
            [
              "beach",
              "rgba(238, 229, 178, 1)"
            ],
            [
              "desert",
              "rgba(238, 229, 178, 1)"
            ],
            [
              "farmland",
              "rgba(222, 221, 190, 1)"
            ],
            [
              "farm",
              "rgba(222, 221, 190, 1)"
            ],
            [
              "orchard",
              "rgba(222, 221, 190, 1)"
            ],
...

The Log Messages Panel reports:

2018-04-01T13:53:18 0   Creating styles from: http://localhost:8080/nautical_active.json
2018-04-01T13:53:18 0   Styles will be written to: /var/folders/q2/3wp7snyh8xn46j008k8wdqr80000gn/T/vector_tiles_reader/styles/tegola-openseamap local
2018-04-01T13:53:18 2   Style generation failed: (<type 'exceptions.ValueError'>, ValueError("invalid literal for int() with base 10: 'wetland'",), <traceback object at 0x129830cb0>), Traceback (most recent call last):
              File "/Users/erictheise/.qgis2/python/plugins/vector_tiles_reader/vtr_plugin.py", line 409, in _create_styles
                core.generate_styles(data, output_directory, web_request_executor=self._load_style_data)
              File "/Users/erictheise/.qgis2/python/plugins/vector_tiles_reader/ext-libs/mapboxstyle2qgis/core/__init__.py", line 53, in generate_styles
                styles = process(style_json)
              File "/Users/erictheise/.qgis2/python/plugins/vector_tiles_reader/ext-libs/mapboxstyle2qgis/core/__init__.py", line 89, in process
                qgis_styles = get_styles(l)
              File "/Users/erictheise/.qgis2/python/plugins/vector_tiles_reader/ext-libs/mapboxstyle2qgis/core/__init__.py", line 277, in get_styles
                all_values.extend(get_properties_by_zoom(layer, "paint/fill-color", is_color=True, default="rgba(0,0,0,0)"))
              File "/Users/erictheise/.qgis2/python/plugins/vector_tiles_reader/ext-libs/mapboxstyle2qgis/core/__init__.py", line 498, in get_properties_by_zoom
                "zoom_level": int(lower_zoom),
            ValueError: invalid literal for int() with base 10: 'wetland'

which I interpret to mean that Vector-Tiles-Reader-QGIS-Plugin is unaware of legitimate uses of non-integer stops in the context of categorical variables.

This is peripheral to what I generally work on so any feedback or direction would be much appreciated, thanks.

mnboos commented 6 years ago

Thanks for your report. The current implementation of the style converter is indeed unable to handle such a style. I'll look into it as soon as possible and extend the converter in order to support categorical functions.