| Copyright | (c) Colin Woodbury 2016 - 2020 |
|---|---|
| License | BSD3 |
| Maintainer | Colin Woodbury <colin@fosskers.ca> |
| 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.
Synopsis
- 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
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 | |
Instances
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
| |
Instances
| Eq gs => Eq (Feature gs) Source # | |
| Show gs => Show (Feature gs) Source # | |
| Generic (Feature gs) Source # | |
| NFData gs => NFData (Feature gs) Source # | |
Defined in Geography.VectorTile.VectorTile | |
| type Rep (Feature gs) Source # | |
Defined in Geography.VectorTile.VectorTile type Rep (Feature gs) = D1 (MetaData "Feature" "Geography.VectorTile.VectorTile" "vectortiles-1.5.1-7MnYiWGlVzVJYfj7ka9AnU" False) (C1 (MetaCons "Feature" PrefixI True) (S1 (MetaSel (Just "_featureId") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Word) :*: (S1 (MetaSel (Just "_metadata") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (HashMap ByteString Val)) :*: S1 (MetaSel (Just "_geometries") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 gs)))) | |
geometries :: Lens' (Feature gs) gs Source #
Legal Metadata Value types. Note that S64 are Z-encoded automatically
by the underlying Text.ProtocolBuffers library.
Instances
Geometries
A strict pair of integers indicating some location on a discrete grid.
Point 0 0 is the top-left.
Instances
| Eq Point Source # | |
| Show Point Source # | |
| Generic Point Source # | |
| Semigroup Point Source # | |
| Monoid Point Source # | |
| Storable Point Source # | |
| NFData Point Source # | |
Defined in Geography.VectorTile.Geometry | |
| ProtobufGeom Point Source # | A valid |
Defined in Geography.VectorTile.Internal | |
| type Rep Point Source # | |
Defined in Geography.VectorTile.Geometry type Rep Point = D1 (MetaData "Point" "Geography.VectorTile.Geometry" "vectortiles-1.5.1-7MnYiWGlVzVJYfj7ka9AnU" False) (C1 (MetaCons "Point" PrefixI True) (S1 (MetaSel (Just "x") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Int) :*: S1 (MetaSel (Just "y") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Int))) | |
newtype LineString Source #
Constructors
| LineString | |
Instances
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 # | |
Defined in Geography.VectorTile.Geometry | |
| 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. |
Defined in Geography.VectorTile.Internal | |
| type Rep Polygon Source # | |
Defined in Geography.VectorTile.Geometry type Rep Polygon = D1 (MetaData "Polygon" "Geography.VectorTile.Geometry" "vectortiles-1.5.1-7MnYiWGlVzVJYfj7ka9AnU" False) (C1 (MetaCons "Polygon" PrefixI True) (S1 (MetaSel (Just "polyPoints") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (Vector Point)) :*: S1 (MetaSel (Just "inner") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (Vector Polygon)))) | |