Copyright | (c) Azavea 2016 - 2017 |
---|---|
License | Apache 2 |
Maintainer | Colin Woodbury <cwoodbury@azavea.com> |
Safe Haskell | None |
Language | Haskell2010 |
Raw Vector Tile data is stored as binary protobuf data. This module reads and writes raw protobuf ByteStrings between a data type which closely matches the current Mapbox vector tile spec defined here: https://github.com/mapbox/vector-tile-spec/blob/master/2.1/vector_tile.proto
As this raw version of the data is hard to work with, in practice we convert to a more canonical Haskell type for further processing. See Geography.VectorTile.VectorTile for the user-friendly version.
Please import this module qualified
to avoid namespace clashes:
import qualified Geography.VectorTile.Protobuf.Internal as PB
- type family Protobuf a = pb | pb -> a
- class Protobuffable a where
- class ProtobufGeom g where
- data RawVectorTile = RawVectorTile {}
- data RawLayer = RawLayer {}
- data RawVal = RawVal {}
- data RawFeature = RawFeature {}
- data GeomType
- = Unknown
- | Point
- | LineString
- | Polygon
- data Command
- commands :: [Word32] -> Either Text [Command]
- uncommands :: [Command] -> [Word32]
- zig :: Int -> Word32
- unzig :: Word32 -> Int
- features :: [Text] -> [RawVal] -> [RawFeature] -> Either Text (Vector (Feature Point), Vector (Feature LineString), Vector (Feature Polygon))
- unfeature :: ProtobufGeom g => Map Text Int -> Map Val Int -> GeomType -> Feature g -> RawFeature
Types
type family Protobuf a = pb | pb -> a Source #
A family of data types which can associated with concrete underlying Protobuf types.
class Protobuffable a where Source #
A type which can be converted to and from an underlying Protobuf type,
according to the Protobuf
type family.
fromProtobuf :: Protobuf a -> Either Text a Source #
toProtobuf :: a -> Protobuf a Source #
class ProtobufGeom g where Source #
Any classical type considered a GIS "geometry". These must be able
to convert between an encodable list of Command
s.
fromCommands :: [Command] -> Either Text (Vector g) Source #
toCommands :: Vector g -> [Command] Source #
ProtobufGeom Polygon Source # | A valid An Exterior Ring, followed by 0 or more Interior Rings. Any Ring must have a Performs no sanity checks for malformed Interior Rings. |
ProtobufGeom LineString Source # | A valid A |
ProtobufGeom Point Source # | A valid |
Contains a pseudo-map of metadata, to be shared across all RawFeature
s
of this RawLayer
.
The Value types of metadata fields.
The four potential Geometry types. The spec allows for encoders to set
Unknown
as the type, but our decoder ignores these.
Commands
The possible commands, and the values they hold.
commands :: [Word32] -> Either Text [Command] Source #
Attempt to parse a list of Command/Parameter integers, as defined here:
https://github.com/mapbox/vector-tile-spec/tree/master/2.1#43-geometry-encoding
uncommands :: [Command] -> [Word32] Source #
Convert a list of parsed Command
s back into their original Command
and Z-encoded Parameter integer forms.
Z-Encoding
Protobuf Conversions
Due to Protobuf Layers and Features having their data coupled,
we can't define a Protobuffable
instance for Feature
s,
and instead must use the two functions below.
features :: [Text] -> [RawVal] -> [RawFeature] -> Either Text (Vector (Feature Point), Vector (Feature LineString), Vector (Feature Polygon)) Source #
Convert a list of RawFeature
s of parsed protobuf data into Vector
s
of each of the three legal ProtobufGeom
types.
The long type signature is due to two things:
Feature
s are polymorphic at the high level, but not at the parsed protobuf mid-level. In a[RawFeature]
, there are features of points, linestrings, and polygons all mixed together.RawLayer
s andRawFeature
s are strongly coupled at the protobuf level. In order to achieve higher compression ratios,RawLayer
s contain all metadata in key/value lists to be shared across theirRawFeature
s, while thoseRawFeature
s store only indices into those lists. As a result, this function needs to be passed those key/value lists from the parentRawLayer
, and a more isomorphic:
feature :: ProtobufGeom g => RawFeature -> Either Text (Feature g)
is not possible.
unfeature :: ProtobufGeom g => Map Text Int -> Map Val Int -> GeomType -> Feature g -> RawFeature Source #
Encode a high-level Feature
back into its mid-level RawFeature
form.