| 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 (Vector (Feature (Vector Point)))
- linestrings :: Lens' Layer (Vector (Feature (Vector LineString)))
- polygons :: Lens' Layer (Vector (Feature (Vector Polygon)))
- extent :: Lens' Layer Word
- data Feature gs = Feature {
- _featureId :: Word
- _metadata :: HashMap ByteString Val
- _geometries :: gs
- featureId :: Lens' (Feature gs) Word
- metadata :: Lens' (Feature gs) (HashMap ByteString Val)
- geometries :: Lens' (Feature gs) gs
- data Val
- data Point = Point {}
- newtype LineString = LineString {}
- data Polygon = Polygon {}
- area :: Polygon -> Double
- surveyor :: Vector Point -> Double
- distance :: Point -> Point -> Double
Vector Tiles
newtype VectorTile Source #
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
tile :: ByteString -> Either Text VectorTile Source #
Attempt to parse a VectorTile from a strict collection of bytes.
untile :: VectorTile -> ByteString Source #
Convert a VectorTile back into bytes.
type Lens' s a = forall f. Functor f => (a -> f a) -> s -> f s Source #
Simple Lenses compatible with both lens and microlens.
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 | |
linestrings :: Lens' Layer (Vector (Feature (Vector LineString))) Source #
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 gs) gs Source #
Legal Metadata Value types. Note that S64 are Z-encoded automatically
by the underlying Text.ProtocolBuffers library.
Geometries
A strict pair of integers indicating some location on a discrete grid.
Point 0 0 is the top-left.
Instances
newtype LineString Source #
Constructors
| LineString | |
Instances
| Eq LineString Source # | |
| Show LineString Source # | |
| Generic LineString Source # | |
| NFData LineString Source # | |
| ProtobufGeom LineString Source # | A valid A |
| type Rep LineString Source # | |
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 Source # | |
| Show Polygon Source # | |
| Generic Polygon Source # | |
| NFData Polygon 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. |
| type Rep Polygon Source # | |
area :: Polygon -> Double Source #
The area of a Polygon is the difference between the areas of its
outer ring and inner rings.