| Copyright | (c) Colin Woodbury 2016 - 2018 |
|---|---|
| License | BSD3 |
| Maintainer | Colin Woodbury <colingw@gmail.com> |
| Safe Haskell | None |
| Language | Haskell2010 |
Geography.VectorTile
Contents
Description
GIS Vector Tiles, as defined by Mapbox.
This library implements version 2.1 of the official Mapbox spec, as defined here: https://github.com/mapbox/vector-tile-spec/tree/master/2.1
Note that currently this library ignores top-level protobuf extensions, Value extensions, and UNKNOWN geometries.
Usage
This library reads and writes strict ByteStrings.
Given some legal VectorTile file called roads.mvt:
import qualified Data.ByteString as BS import Data.Text (Text) import Geography.VectorTile -- | Read in raw protobuf data and decode it into a high-level type. roads :: IO (Either Text VectorTile) roads = tile <$> BS.readFile "roads.mvt"
Likewise, use the untile function to convert a VectorTile back into a ByteString.
- newtype VectorTile = VectorTile {}
- tile :: ByteString -> Either Text VectorTile
- untile :: VectorTile -> ByteString
- type Lens' s a = forall f. Functor f => (a -> f a) -> s -> f s
- layers :: Lens' VectorTile (HashMap ByteString Layer)
- data Layer = Layer {}
- version :: Lens' Layer Word
- name :: Lens' Layer ByteString
- points :: Lens' Layer (Seq (Feature Point))
- linestrings :: Lens' Layer (Seq (Feature LineString))
- polygons :: Lens' Layer (Seq (Feature Polygon))
- extent :: Lens' Layer Word
- data Feature g = Feature {
- _featureId :: Word
- _metadata :: HashMap ByteString Val
- _geometries :: Seq g
- featureId :: Lens' (Feature g) Word
- metadata :: Lens' (Feature g) (HashMap ByteString Val)
- geometries :: Lens' (Feature g) (Seq g)
- data Val
- type Point = (Int, Int)
- x :: (Int, Int) -> Int
- y :: (Int, Int) -> Int
- newtype LineString = LineString {}
- data Polygon = Polygon {}
- area :: Polygon -> Double
- surveyor :: Vector Point -> Double
- distance :: Point -> Point -> Double
Vector Tiles
newtype VectorTile #
A high-level representation of a Vector Tile. Implemented internally
as a HashMap, so that access to individual layers can be fast if you
know the layer names ahead of time.
The layer name itself, a lazy ByteString, is guaranteed to be UTF-8.
If you wish to convert it to Text, consider
decodeUtf8.
Constructors
| VectorTile | |
Fields | |
Instances
| Eq VectorTile # | |
| Show VectorTile # | |
| Generic VectorTile # | |
| NFData VectorTile # | |
| Protobuffable VectorTile # | |
| type Rep VectorTile # | |
| type Protobuf VectorTile # | |
tile :: ByteString -> Either Text VectorTile #
Attempt to parse a VectorTile from a strict collection of bytes.
untile :: VectorTile -> ByteString #
Convert a VectorTile back into bytes.
type Lens' s a = forall f. Functor f => (a -> f a) -> s -> f s #
Simple Lenses compatible with both lens and microlens.
layers :: Lens' VectorTile (HashMap ByteString Layer) #
A layer, which could contain any number of Features of any Geometry type.
This codec only respects the canonical three Geometry types, and we split
them here explicitely to allow for more fine-grained access to each type.
Constructors
| Layer | |
name :: Lens' Layer ByteString #
linestrings :: Lens' Layer (Seq (Feature LineString)) #
A geographic feature. Features are a set of geometries that share some common theme:
- Points: schools, gas station locations, etc.
- LineStrings: Roads, power lines, rivers, etc.
- Polygons: Buildings, water bodies, etc.
Where, for instance, all school locations may be stored as a single
Feature, and no Point within that Feature would represent anything
else.
Note: Each Geometry type and their Multi* counterpart are considered
the same thing, as a Vector of that Geometry.
Note: The keys to the metadata are ByteString, but are guaranteed
to be UTF-8.
Constructors
| Feature | |
Fields
| |
geometries :: Lens' (Feature g) (Seq g) #
Legal Metadata Value types. Note that S64 are Z-encoded automatically
by the underlying Text.ProtocolBuffers library.
Geometries
Points in space. Using "Record Pattern Synonyms" here allows us to treat
Point like a normal ADT, while its implementation remains an unboxed
(Int,Int).
newtype LineString #
Constructors
| LineString | |
Instances
| Eq LineString # | |
| Show LineString # | |
| Generic LineString # | |
| NFData LineString # | |
| ProtobufGeom LineString # | A valid A |
| type Rep LineString # | |
A polygon aware of its interior rings.
VectorTiles require that Polygon exteriors have clockwise winding order, and that interior holes have counter-clockwise winding order. These assume that the origin (0,0) is in the *top-left* corner.
Instances
| Eq Polygon # | |
| Show Polygon # | |
| Generic Polygon # | |
| NFData Polygon # | |
| ProtobufGeom Polygon # | 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. |
| type Rep Polygon # | |
The area of a Polygon is the difference between the areas of its
outer ring and inner rings.