{-# 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
import Data.LinearRing
import Control.Lens (makeLenses)
import Control.Monad (mzero)
import Data.Aeson (FromJSON (..),
ToJSON (..),
Value (..))
newtype GeoMultiPolygon = GeoMultiPolygon { _unGeoMultiPolygon :: [[LinearRing GeoPositionWithoutCRS]] } deriving (Show, Eq)
splitGeoMultiPolygon :: GeoMultiPolygon -> [GeoPolygon]
splitGeoMultiPolygon = map GeoPolygon . _unGeoMultiPolygon
mergeGeoPolygons :: [GeoPolygon] -> GeoMultiPolygon
mergeGeoPolygons = GeoMultiPolygon . map _unGeoPolygon
makeLenses ''GeoMultiPolygon
instance ToJSON GeoMultiPolygon where
toJSON = makeGeometryGeoAeson "MultiPolygon" . _unGeoMultiPolygon
instance FromJSON GeoMultiPolygon where
parseJSON (Object o) = readGeometryGeoAeson "MultiPolygon" GeoMultiPolygon o
parseJSON _ = mzero