{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE Rank2Types #-}
module Geography.VectorTile.VectorTile
(
VectorTile(..)
, Layer(..)
, Feature(..)
, Val(..)
, Lens'
, layers
, version
, name
, points
, linestrings
, polygons
, extent
, featureId
, metadata
, geometries
) where
import Control.DeepSeq (NFData)
import qualified Data.ByteString.Lazy as BL
import Data.Hashable (Hashable)
import qualified Data.HashMap.Lazy as M
import Data.Int
import qualified Data.Vector as V
import qualified Data.Vector.Storable as VS
import Data.Word
import Geography.VectorTile.Geometry
import GHC.Generics (Generic)
type Lens' s a = forall f. Functor f => (a -> f a) -> s -> f s
newtype VectorTile = VectorTile { _layers :: M.HashMap BL.ByteString Layer } deriving (Eq,Show,Generic)
layers :: Lens' VectorTile (M.HashMap BL.ByteString Layer)
layers f v = VectorTile <$> f (_layers v)
{-# INLINE layers #-}
instance NFData VectorTile
data Layer = Layer { _version :: Word
, _name :: BL.ByteString
, _points :: V.Vector (Feature (VS.Vector Point))
, _linestrings :: V.Vector (Feature (V.Vector LineString))
, _polygons :: V.Vector (Feature (V.Vector Polygon))
, _extent :: Word
} deriving (Eq, Show, Generic)
version :: Lens' Layer Word
version f l = (\v -> l { _version = v }) <$> f (_version l)
{-# INLINE version #-}
name :: Lens' Layer BL.ByteString
name f l = (\v -> l { _name = v }) <$> f (_name l)
{-# INLINE name #-}
points :: Lens' Layer (V.Vector (Feature (VS.Vector Point)))
points f l = (\v -> l { _points = v }) <$> f (_points l)
{-# INLINE points #-}
linestrings :: Lens' Layer (V.Vector (Feature (V.Vector LineString)))
linestrings f l = (\v -> l { _linestrings = v }) <$> f (_linestrings l)
{-# INLINE linestrings #-}
polygons :: Lens' Layer (V.Vector (Feature (V.Vector Polygon)))
polygons f l = (\v -> l { _polygons = v }) <$> f (_polygons l)
{-# INLINE polygons #-}
extent :: Lens' Layer Word
extent f l = (\v -> l { _extent = v }) <$> f (_extent l)
{-# INLINE extent #-}
instance NFData Layer
data Feature gs = Feature { _featureId :: Word
, _metadata :: M.HashMap BL.ByteString Val
, _geometries :: gs } deriving (Eq, Show, Generic)
featureId :: Lens' (Feature gs) Word
featureId f l = (\v -> l { _featureId = v }) <$> f (_featureId l)
{-# INLINE featureId #-}
metadata :: Lens' (Feature gs) (M.HashMap BL.ByteString Val)
metadata f l = (\v -> l { _metadata = v }) <$> f (_metadata l)
{-# INLINE metadata #-}
geometries :: Lens' (Feature gs) gs
geometries f l = (\v -> l { _geometries = v }) <$> f (_geometries l)
{-# INLINE geometries #-}
instance (NFData gs) => NFData (Feature gs)
data Val = St BL.ByteString | Fl Float | Do Double | I64 Int64 | W64 Word64 | S64 Int64 | B Bool
deriving (Eq,Ord,Show,Generic,Hashable)
instance NFData Val