mapnik / python-mapnik

Python bindings for mapnik
GNU Lesser General Public License v2.1
160 stars 91 forks source link

Mapnik Grid: Is there a way to include the layer name into the data attributes? #134

Open alculquicondor opened 7 years ago

alculquicondor commented 7 years ago

I'm rendering multiple layers (one on top of another), and I need a way to distinguish (on the utfgrid) to which layer the element corresponds to. Any other suggestion to accomplish this?

talaj commented 7 years ago

There is features=true parameter of encode method which should encode additional info into the grid JSON, see. This might be helpful.

alculquicondor commented 7 years ago

I guess you are referring to something like this:

mapnik.render_layer(self.mapnik, grid, layer=index, fields=fields)
encoded_grid = grid.encode('utf', resolution=self.scale, features=True)

But that's a boolean. How do I set the data? In case you refer to the fields parameter on render_layer call, AFAIK that refers to columns on the datasource, but I need the layer index, name or something equivalent.

talaj commented 7 years ago

But that's a boolean. How do I set the data?

The data should be already collected in the grid object. You will not get layer index or name directly, but you can distinguish it by the feature data. This is all I have, sorry.

alculquicondor commented 7 years ago

I see, we have solved it in TileStache by manually inserting the layer name when adding each mapnik layer. But I wanted to do if there was already another solution in mapnik directly. Thanks