{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TemplateHaskell #-}
module Data.Geospatial.Internal.Geometry.GeoMultiPolygon (
GeoMultiPolygon(..)
, unGeoMultiPolygon
, splitGeoMultiPolygon, mergeGeoPolygons
) where
import Data.Geospatial.Internal.BasicTypes
import Data.Geospatial.Internal.Geometry.Aeson
import Data.Geospatial.Internal.Geometry.GeoPolygon as GeoPolygon
import qualified Data.LinearRing as LinearRing
import Control.DeepSeq
import Control.Lens (makeLenses)
import Control.Monad (mzero)
import qualified Data.Aeson as Aeson
import qualified Data.Sequence as Sequence
import GHC.Generics (Generic)
newtype GeoMultiPolygon = GeoMultiPolygon { _unGeoMultiPolygon :: Sequence.Seq (Sequence.Seq (LinearRing.LinearRing GeoPositionWithoutCRS)) } deriving (Show, Eq, Generic, NFData)
splitGeoMultiPolygon :: GeoMultiPolygon -> Sequence.Seq GeoPolygon
splitGeoMultiPolygon = fmap GeoPolygon . _unGeoMultiPolygon
mergeGeoPolygons :: Sequence.Seq GeoPolygon -> GeoMultiPolygon
mergeGeoPolygons = GeoMultiPolygon . fmap GeoPolygon._unGeoPolygon
makeLenses ''GeoMultiPolygon
instance Aeson.ToJSON GeoMultiPolygon where
toJSON = makeGeometryGeoAeson "MultiPolygon" . _unGeoMultiPolygon
instance Aeson.FromJSON GeoMultiPolygon where
parseJSON (Aeson.Object o) = readGeometryGeoAeson "MultiPolygon" GeoMultiPolygon o
parseJSON _ = mzero