Automatically add additional attributes
92a63df93367aa0678600c60dd960db9c094904b shows a problem with the current approach of creating the datasource. In a complex layer, there will be many rules referring to many attributes. We currently have to list all the attributes in the legend.json file, but a better approach would involve only listing e.g. "highway": "motorway"
Given we can assume that unmentioned attributes should be null (or equivalent), we could
- modify the csv datasource and add an "assume missing attributes are null" option
- figure out the full list of attributes mentioned in the style
For the latter, I've spent a while going through the mapnik source code, to see how it works. We already have access to the list of expressions (aka filters) e.g.
[13] pry(main)> map.styles["aerialways"].rules.first.filter
=> ([aerialway]='j-bar')
To get a list of attributes from a filter (which can be fairly complex) mapnik uses the attribute_collector (which happens during rendering at feature_style_processor_impl.hpp#L373).
Perhaps with some more ruby-mapnik bindings (specifically for attribute_collector), we could create our own attribute_collector instance to gather the attributes, then merge the missing ones in with the ones from legend.json and use the combined list when creating the datasource.
Other ideas welcome!