scalavector-tilesgeotrellis

scala for mapbox vector tiles - getting an 'id' field into the Features written to vector tiles


I'm writing MapBox vector tiles using geotrellis vectorpipe.

see here for the basic flow: https://geotrellis.github.io/vectorpipe/usage.html

Typically GeoJson Features can have an id field, so that Features can be rolled up into FeatureCollections. I need to make use of this field, but vectorpipe doesn't (natively) have this capability.

This is the Feature type used, and you can see it only has space for 1) a Geometry and 2) a data object D (which ends up populating properties in the output). There is no spot for an id.

https://geotrellis.github.io/scaladocs/latest/index.html#geotrellis.vector.Feature

Upstream there's a method called writeFeatureJsonWithID() that does let you inject an id field into a Feature when writing GeoJson.

https://github.com/locationtech/geotrellis/blob/master/vector/src/main/scala/geotrellis/vector/io/json/FeatureFormats.scala#L41-L49

My question is this:

I have worked through the vectorpipe code (https://github.com/geotrellis/vectorpipe), and I can't figure out if/where the data ever exists as GeoJson in a way where I can override and inject the id, maybe using the writeFeatureJsonWithID() or something I write explicitly. A lot of conversions are implicit, but it also may never explicitly sit as json.

Any ideas for how to get an id field in the final GeoJson written to vector tiles?

EDIT

Right now I think the trick is going to be finding a way to override .unfeature() method here:

https://github.com/locationtech/geotrellis/blob/master/vectortile/src/main/scala/geotrellis/vectortile/Layer.scala

The problem is that the internal.vector_tile.Tile is private, so I can construct it without forking the project.


Solution

  • Ended up having to fork geotrellis, hard-code a metadata => id function in Layer.unfeature() and compile locally to include in my project. Not ideal, but it works fine.

    Also opened an issue here: https://github.com/locationtech/geotrellis/issues/2884