geojson-2.0.0: src/Data/Geospatial/Internal/Geometry/GeoPolygon.hs
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TemplateHaskell #-}
-------------------------------------------------------------------
-- |
-- Module : Data.Geospatial.Internal.Geometry.GeoPolygon
-- Copyright : (C) 2014-2018 HS-GeoJSON Project
-- License : BSD-style (see the file LICENSE.md)
-- Maintainer : Andrew Newman
--
-------------------------------------------------------------------
module Data.Geospatial.Internal.Geometry.GeoPolygon (
-- * Type
GeoPolygon(..)
-- * Lenses
, unGeoPolygon
) where
import Control.DeepSeq
import Control.Lens (makeLenses)
import Control.Monad (mzero)
import qualified Data.Aeson as Aeson
import Data.Geospatial.Internal.BasicTypes
import Data.Geospatial.Internal.Geometry.Aeson
import qualified Data.LinearRing as LinearRing
import qualified Data.Vector as Vector
import GHC.Generics (Generic)
newtype GeoPolygon = GeoPolygon { _unGeoPolygon :: Vector.Vector (LinearRing.LinearRing GeoPositionWithoutCRS) } deriving (Show, Eq, Generic, NFData)
-- Vector.Vector (LinearRing.LinearRing DoubleArray)
makeLenses ''GeoPolygon
-- instances
instance Aeson.ToJSON GeoPolygon where
-- toJSON :: a -> Value
toJSON = makeGeometryGeoAeson "Polygon" . _unGeoPolygon
instance Aeson.FromJSON GeoPolygon where
-- parseJSON :: Value -> Parser a
parseJSON (Aeson.Object o) = readGeometryGeoAeson "Polygon" GeoPolygon o
parseJSON _ = mzero