Heuristic Experiment on Encoding Mapbox Vector Tiles In Scala
Scala Protocol Buffer Python
Failed to load latest commit information.


Heuristic Experiment on Encoding Mapbox Vector Tiles In Scala

This work in progress is a Scala based encoder of the Mapbox Vector Tile specification given a set of Esri Geometries and attributes. It is largely based on this Java implementation.

Encoding a Feature

val bytes = VectorTileEncoder(new Envelope2D(-180, -90, 180, 90))
  .addFeature("cities", new Point(35.4955, 33.8886), Map("id" -> 3533, "name" -> "Beirut"))

In the above example, a encoder is created with an envelope that is spanning the world in geographic coordinates. A point feature with lat/lon of Beirut is added to the cities layer with attribute values for the keys id and name. The encode() method returns an array of bytes.

The VectorTileEncoder accepts the following parameters:

  • envp : The vector tile envelope in "world" coordinates (Geographic, Mercator or Tile relative)
  • clip : A clipping envelope - useful for polygons and polyline features and usually slightly bigger than the parameter envp.
  • extent: The number of units comprise the width and height of the square tile. The default value is 4096
  • yOrigAtTop: Specifies whether y=0 should be at the top of the tile (per the specification) or at the bottom - The latter makes it easier to display world values. The default is false.
  • addPolygonLastPoint: Specifies if the last point in a polygon should be encoded. The specification dictates that this should not be done (thus the CLOSE command). However, I've seen situations in data sources where the last point should be encoded, as it is not the same as the first point.

Project Dependencies

Building the Project

mvn install

Maven uses the exec plugin to spawn ScalaBuff to generate the stubs based the Protocol Buffer messages in src/main/protobuf/vector_tile.proto.

See Also


Apache License, version 2.0