{-# OPTIONS_GHC -Wno-orphans #-}
module HGeometry.GeoJSON
  ( GeoPositionWithoutCRS'
  , RestGeoPosition(..)
  , _GeoPositionWithoutCRS


  , _GeoPolygonPolygonalDomain
  ) where

import           Control.Lens
import           Data.Bifunctor
import           Data.Coerce
import qualified Data.Foldable as F
import           Data.Foldable1
import           Data.Functor.Apply (Apply, (<.*>), MaybeApply(..))
import           Data.Geospatial
import           Data.LinearRing
import           Data.List.NonEmpty (NonEmpty(..))
import           Data.Maybe (fromMaybe)
import           Data.Semigroup.Traversable
import           Data.Sequence (Seq(..))
import qualified Data.Sequence as Seq
import           GHC.Generics (Generic)
import           HGeometry.Cyclic
import           HGeometry.Ext
import           HGeometry.Foldable.Util
import           HGeometry.Point.Class
import           HGeometry.Polygon.Class
import           HGeometry.Polygon.Simple
import           HGeometry.Polygon.WithHoles
import           HGeometry.Properties
import           HGeometry.Sequence.NonEmpty
import           HGeometry.Vector

--------------------------------------------------------------------------------
-- * PointXY

type instance NumType   PointXY = Double
type instance Dimension PointXY = 2

instance HasVector PointXY PointXY where
  vector :: forall (d :: Nat) r s.
(Dimension PointXY ~ d, NumType PointXY ~ r, Dimension PointXY ~ d,
 NumType PointXY ~ s) =>
Lens PointXY PointXY (Vector d r) (Vector d s)
vector = (PointXY -> Vector d r)
-> (PointXY -> Vector d s -> PointXY)
-> Lens PointXY PointXY (Vector d r) (Vector d s)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens (\(PointXY Double
x Double
y) -> r -> r -> Vector 2 r
forall r. r -> r -> Vector 2 r
Vector2 r
Double
x r
Double
y) (\PointXY
_ (Vector2 s
x s
y) -> Double -> Double -> PointXY
PointXY s
Double
x s
Double
y)

instance HasCoordinates PointXY PointXY
instance Affine_ PointXY 2 Double
instance Point_  PointXY 2 Double

--------------------------------------------------------------------------------
-- * PointXYZ

type instance NumType   PointXYZ = Double
type instance Dimension PointXYZ = 3

instance HasVector PointXYZ PointXYZ where
  vector :: forall (d :: Nat) r s.
(Dimension PointXYZ ~ d, NumType PointXYZ ~ r,
 Dimension PointXYZ ~ d, NumType PointXYZ ~ s) =>
Lens PointXYZ PointXYZ (Vector d r) (Vector d s)
vector = (PointXYZ -> Vector d r)
-> (PointXYZ -> Vector d s -> PointXYZ)
-> Lens PointXYZ PointXYZ (Vector d r) (Vector d s)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens (\(PointXYZ Double
x Double
y Double
z) -> r -> r -> r -> Vector 3 r
forall r. r -> r -> r -> Vector 3 r
Vector3 r
Double
x r
Double
y r
Double
z) (\PointXYZ
_ (Vector3 s
x s
y s
z) -> Double -> Double -> Double -> PointXYZ
PointXYZ s
Double
x s
Double
y s
Double
z)

instance HasCoordinates PointXYZ PointXYZ
instance Affine_ PointXYZ 3 Double
instance Point_  PointXYZ 3 Double

--------------------------------------------------------------------------------
-- * PointXYZM

type instance NumType   PointXYZM = Double
type instance Dimension PointXYZM = 4

instance HasVector PointXYZM PointXYZM where
  vector :: forall (d :: Nat) r s.
(Dimension PointXYZM ~ d, NumType PointXYZM ~ r,
 Dimension PointXYZM ~ d, NumType PointXYZM ~ s) =>
Lens PointXYZM PointXYZM (Vector d r) (Vector d s)
vector = (PointXYZM -> Vector d r)
-> (PointXYZM -> Vector d s -> PointXYZM)
-> Lens PointXYZM PointXYZM (Vector d r) (Vector d s)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens (\(PointXYZM Double
x Double
y Double
z Double
m) -> r -> r -> r -> r -> Vector 4 r
forall r. r -> r -> r -> r -> Vector 4 r
Vector4 r
Double
x r
Double
y r
Double
z r
Double
m)
                (\PointXYZM
_ (Vector4 s
x s
y s
z s
m) -> Double -> Double -> Double -> Double -> PointXYZM
PointXYZM s
Double
x s
Double
y s
Double
z s
Double
m)

instance HasCoordinates PointXYZM PointXYZM
instance Affine_ PointXYZM 4 Double
instance Point_  PointXYZM 4 Double

--------------------------------------------------------------------------------
-- * GeoPositionWithoutCRS

type GeoPositionWithoutCRS' = PointXY :+ Maybe RestGeoPosition

type instance NumType GeoPositionWithoutCRS = Double

data RestGeoPosition = Z  {-#UNPACK#-}!Double
                     | ZM {-#UNPACK#-}!Double {-#UNPACK#-}!Double
                     deriving (Int -> RestGeoPosition -> ShowS
[RestGeoPosition] -> ShowS
RestGeoPosition -> String
(Int -> RestGeoPosition -> ShowS)
-> (RestGeoPosition -> String)
-> ([RestGeoPosition] -> ShowS)
-> Show RestGeoPosition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RestGeoPosition -> ShowS
showsPrec :: Int -> RestGeoPosition -> ShowS
$cshow :: RestGeoPosition -> String
show :: RestGeoPosition -> String
$cshowList :: [RestGeoPosition] -> ShowS
showList :: [RestGeoPosition] -> ShowS
Show,RestGeoPosition -> RestGeoPosition -> Bool
(RestGeoPosition -> RestGeoPosition -> Bool)
-> (RestGeoPosition -> RestGeoPosition -> Bool)
-> Eq RestGeoPosition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RestGeoPosition -> RestGeoPosition -> Bool
== :: RestGeoPosition -> RestGeoPosition -> Bool
$c/= :: RestGeoPosition -> RestGeoPosition -> Bool
/= :: RestGeoPosition -> RestGeoPosition -> Bool
Eq,Eq RestGeoPosition
Eq RestGeoPosition =>
(RestGeoPosition -> RestGeoPosition -> Ordering)
-> (RestGeoPosition -> RestGeoPosition -> Bool)
-> (RestGeoPosition -> RestGeoPosition -> Bool)
-> (RestGeoPosition -> RestGeoPosition -> Bool)
-> (RestGeoPosition -> RestGeoPosition -> Bool)
-> (RestGeoPosition -> RestGeoPosition -> RestGeoPosition)
-> (RestGeoPosition -> RestGeoPosition -> RestGeoPosition)
-> Ord RestGeoPosition
RestGeoPosition -> RestGeoPosition -> Bool
RestGeoPosition -> RestGeoPosition -> Ordering
RestGeoPosition -> RestGeoPosition -> RestGeoPosition
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: RestGeoPosition -> RestGeoPosition -> Ordering
compare :: RestGeoPosition -> RestGeoPosition -> Ordering
$c< :: RestGeoPosition -> RestGeoPosition -> Bool
< :: RestGeoPosition -> RestGeoPosition -> Bool
$c<= :: RestGeoPosition -> RestGeoPosition -> Bool
<= :: RestGeoPosition -> RestGeoPosition -> Bool
$c> :: RestGeoPosition -> RestGeoPosition -> Bool
> :: RestGeoPosition -> RestGeoPosition -> Bool
$c>= :: RestGeoPosition -> RestGeoPosition -> Bool
>= :: RestGeoPosition -> RestGeoPosition -> Bool
$cmax :: RestGeoPosition -> RestGeoPosition -> RestGeoPosition
max :: RestGeoPosition -> RestGeoPosition -> RestGeoPosition
$cmin :: RestGeoPosition -> RestGeoPosition -> RestGeoPosition
min :: RestGeoPosition -> RestGeoPosition -> RestGeoPosition
Ord)

-- | Convert between a GeoPositionWithoutCRS and a PointXY
_GeoPositionWithoutCRS :: Prism' GeoPositionWithoutCRS (PointXY :+ Maybe RestGeoPosition)
_GeoPositionWithoutCRS :: Prism' GeoPositionWithoutCRS (PointXY :+ Maybe RestGeoPosition)
_GeoPositionWithoutCRS = ((PointXY :+ Maybe RestGeoPosition) -> GeoPositionWithoutCRS)
-> (GeoPositionWithoutCRS
    -> Maybe (PointXY :+ Maybe RestGeoPosition))
-> Prism' GeoPositionWithoutCRS (PointXY :+ Maybe RestGeoPosition)
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' (PointXY :+ Maybe RestGeoPosition) -> GeoPositionWithoutCRS
toGeoP GeoPositionWithoutCRS -> Maybe (PointXY :+ Maybe RestGeoPosition)
fromGeoP
  where
    toGeoP :: (PointXY :+ Maybe RestGeoPosition) -> GeoPositionWithoutCRS
toGeoP (p :: PointXY
p@(PointXY Double
x Double
y) :+ Maybe RestGeoPosition
mr) = case Maybe RestGeoPosition
mr of
      Maybe RestGeoPosition
Nothing       -> PointXY -> GeoPositionWithoutCRS
GeoPointXY PointXY
p
      Just (Z Double
z)    -> PointXYZ -> GeoPositionWithoutCRS
GeoPointXYZ (PointXYZ -> GeoPositionWithoutCRS)
-> PointXYZ -> GeoPositionWithoutCRS
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Double -> PointXYZ
PointXYZ Double
x Double
y Double
z
      Just (ZM Double
z Double
m) -> PointXYZM -> GeoPositionWithoutCRS
GeoPointXYZM (PointXYZM -> GeoPositionWithoutCRS)
-> PointXYZM -> GeoPositionWithoutCRS
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Double -> Double -> PointXYZM
PointXYZM Double
x Double
y Double
z Double
m
    fromGeoP :: GeoPositionWithoutCRS -> Maybe (PointXY :+ Maybe RestGeoPosition)
fromGeoP = \case
      GeoPositionWithoutCRS
GeoEmpty                         -> Maybe (PointXY :+ Maybe RestGeoPosition)
forall a. Maybe a
Nothing
      GeoPointXY PointXY
p                     -> (PointXY :+ Maybe RestGeoPosition)
-> Maybe (PointXY :+ Maybe RestGeoPosition)
forall a. a -> Maybe a
Just ((PointXY :+ Maybe RestGeoPosition)
 -> Maybe (PointXY :+ Maybe RestGeoPosition))
-> (PointXY :+ Maybe RestGeoPosition)
-> Maybe (PointXY :+ Maybe RestGeoPosition)
forall a b. (a -> b) -> a -> b
$ PointXY
p             PointXY
-> Maybe RestGeoPosition -> PointXY :+ Maybe RestGeoPosition
forall core extra. core -> extra -> core :+ extra
:+ Maybe RestGeoPosition
forall a. Maybe a
Nothing
      GeoPointXYZ (PointXYZ Double
x Double
y Double
z)     -> (PointXY :+ Maybe RestGeoPosition)
-> Maybe (PointXY :+ Maybe RestGeoPosition)
forall a. a -> Maybe a
Just ((PointXY :+ Maybe RestGeoPosition)
 -> Maybe (PointXY :+ Maybe RestGeoPosition))
-> (PointXY :+ Maybe RestGeoPosition)
-> Maybe (PointXY :+ Maybe RestGeoPosition)
forall a b. (a -> b) -> a -> b
$ (Double -> Double -> PointXY
PointXY Double
x Double
y) PointXY
-> Maybe RestGeoPosition -> PointXY :+ Maybe RestGeoPosition
forall core extra. core -> extra -> core :+ extra
:+ RestGeoPosition -> Maybe RestGeoPosition
forall a. a -> Maybe a
Just (Double -> RestGeoPosition
Z Double
z)
      GeoPointXYZM (PointXYZM Double
x Double
y Double
z Double
m) -> (PointXY :+ Maybe RestGeoPosition)
-> Maybe (PointXY :+ Maybe RestGeoPosition)
forall a. a -> Maybe a
Just ((PointXY :+ Maybe RestGeoPosition)
 -> Maybe (PointXY :+ Maybe RestGeoPosition))
-> (PointXY :+ Maybe RestGeoPosition)
-> Maybe (PointXY :+ Maybe RestGeoPosition)
forall a b. (a -> b) -> a -> b
$ (Double -> Double -> PointXY
PointXY Double
x Double
y) PointXY
-> Maybe RestGeoPosition -> PointXY :+ Maybe RestGeoPosition
forall core extra. core -> extra -> core :+ extra
:+ RestGeoPosition -> Maybe RestGeoPosition
forall a. a -> Maybe a
Just (Double -> Double -> RestGeoPosition
ZM Double
z Double
m)


-- | An unsafe version, pretending  that GeoEmpty is not possible
_GeoPositionWithoutCRS' :: Iso' GeoPositionWithoutCRS (PointXY :+ Maybe RestGeoPosition)
_GeoPositionWithoutCRS' :: Iso' GeoPositionWithoutCRS (PointXY :+ Maybe RestGeoPosition)
_GeoPositionWithoutCRS' = (GeoPositionWithoutCRS -> PointXY :+ Maybe RestGeoPosition)
-> ((PointXY :+ Maybe RestGeoPosition) -> GeoPositionWithoutCRS)
-> Iso' GeoPositionWithoutCRS (PointXY :+ Maybe RestGeoPosition)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (GeoPositionWithoutCRS
-> Getting
     (Endo (PointXY :+ Maybe RestGeoPosition))
     GeoPositionWithoutCRS
     (PointXY :+ Maybe RestGeoPosition)
-> PointXY :+ Maybe RestGeoPosition
forall s a. HasCallStack => s -> Getting (Endo a) s a -> a
^?!Getting
  (Endo (PointXY :+ Maybe RestGeoPosition))
  GeoPositionWithoutCRS
  (PointXY :+ Maybe RestGeoPosition)
Prism' GeoPositionWithoutCRS (PointXY :+ Maybe RestGeoPosition)
_GeoPositionWithoutCRS)
                              ((PointXY :+ Maybe RestGeoPosition)
-> Getting
     (Endo GeoPositionWithoutCRS)
     (PointXY :+ Maybe RestGeoPosition)
     GeoPositionWithoutCRS
-> GeoPositionWithoutCRS
forall s a. HasCallStack => s -> Getting (Endo a) s a -> a
^?!AReview GeoPositionWithoutCRS (PointXY :+ Maybe RestGeoPosition)
-> Getter (PointXY :+ Maybe RestGeoPosition) GeoPositionWithoutCRS
forall t b. AReview t b -> Getter b t
re AReview GeoPositionWithoutCRS (PointXY :+ Maybe RestGeoPosition)
Prism' GeoPositionWithoutCRS (PointXY :+ Maybe RestGeoPosition)
_GeoPositionWithoutCRS)
  where
    err :: a
err = String -> a
forall a. HasCallStack => String -> a
error String
"_GeoPositionWithoutCRS'"

--------------------------------------------------------------------------------
-- * Polygon

type instance NumType   GeoPolygon = Double

type instance Dimension GeoPolygon = 2

instance Wrapped GeoPolygon
instance Rewrapped GeoPolygon GeoPolygon

----------------------------------------

type SimpleGeoPolygon point = SimplePolygonF (Cyclic ViewL1) point

type SimpleGeoPolygon' = SimpleGeoPolygon GeoPositionWithoutCRS'

-- | pre: the sequence has at leat 3 elements
_RingViewL1 :: (Eq b, Show b)
            => Iso (LinearRing a) (LinearRing b) (Cyclic ViewL1 a) (Cyclic ViewL1 b)
_RingViewL1 :: forall b a.
(Eq b, Show b) =>
Iso
  (LinearRing a) (LinearRing b) (Cyclic ViewL1 a) (Cyclic ViewL1 b)
_RingViewL1 = (LinearRing a -> Cyclic ViewL1 a)
-> (Cyclic ViewL1 b -> LinearRing b)
-> Iso
     (LinearRing a) (LinearRing b) (Cyclic ViewL1 a) (Cyclic ViewL1 b)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (ViewL1 a -> Cyclic ViewL1 a
forall {k} (v :: k -> *) (a :: k). v a -> Cyclic v a
Cyclic (ViewL1 a -> Cyclic ViewL1 a)
-> (LinearRing a -> ViewL1 a) -> LinearRing a -> Cyclic ViewL1 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LinearRing a -> ViewL1 a
forall a. LinearRing a -> ViewL1 a
ringToViewL1)
               (LinearRing b -> Maybe (LinearRing b) -> LinearRing b
forall a. a -> Maybe a -> a
fromMaybe LinearRing b
forall {a}. a
err (Maybe (LinearRing b) -> LinearRing b)
-> (Cyclic ViewL1 b -> Maybe (LinearRing b))
-> Cyclic ViewL1 b
-> LinearRing b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ViewL1 b -> Maybe (LinearRing b)
forall b. (Eq b, Show b) => ViewL1 b -> Maybe (LinearRing b)
viewL1ToRing (ViewL1 b -> Maybe (LinearRing b))
-> (Cyclic ViewL1 b -> ViewL1 b)
-> Cyclic ViewL1 b
-> Maybe (LinearRing b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Cyclic ViewL1 b -> ViewL1 b
forall a b. Coercible a b => a -> b
coerce)
  where
    err :: a
err = String -> a
forall a. HasCallStack => String -> a
error String
"_RingSeq: failed"

-- | Transform a ViewL1 into a LinearRing
ringToViewL1   :: LinearRing a -> ViewL1 a
ringToViewL1 :: forall a. LinearRing a -> ViewL1 a
ringToViewL1 LinearRing a
r = case LinearRing a -> Seq a
forall a. LinearRing a -> Seq a
toSeq LinearRing a
r of
  (a
x :<| (Seq a
s :|> a
_)) -> a
x a -> Seq a -> ViewL1 a
forall a. a -> Seq a -> ViewL1 a
:<< Seq a
s
    -- the last element is duplicated, we have at least three so this is s afe.
  Seq a
_                 -> String -> ViewL1 a
forall a. HasCallStack => String -> a
error String
"ringToViewL1"

-- | try to transform a ViewL1 into a LinearRing
viewL1ToRing           :: (Eq b, Show b) => ViewL1 b -> Maybe (LinearRing b)
viewL1ToRing :: forall b. (Eq b, Show b) => ViewL1 b -> Maybe (LinearRing b)
viewL1ToRing (b
x :<< Seq b
s) = (NonEmpty (SequenceToLinearRingError b) -> Maybe (LinearRing b))
-> (LinearRing b -> Maybe (LinearRing b))
-> Either (NonEmpty (SequenceToLinearRingError b)) (LinearRing b)
-> Maybe (LinearRing b)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe (LinearRing b)
-> NonEmpty (SequenceToLinearRingError b) -> Maybe (LinearRing b)
forall a b. a -> b -> a
const Maybe (LinearRing b)
forall a. Maybe a
Nothing) LinearRing b -> Maybe (LinearRing b)
forall a. a -> Maybe a
Just (Either (NonEmpty (SequenceToLinearRingError b)) (LinearRing b)
 -> Maybe (LinearRing b))
-> (Seq b
    -> Either (NonEmpty (SequenceToLinearRingError b)) (LinearRing b))
-> Seq b
-> Maybe (LinearRing b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Seq b
-> Either (NonEmpty (SequenceToLinearRingError b)) (LinearRing b)
forall a (v :: * -> * -> *).
(Eq a, Show a, Validate v,
 Functor (v (NonEmpty (ListToLinearRingError a)))) =>
Seq a -> v (NonEmpty (SequenceToLinearRingError a)) (LinearRing a)
fromSeq (Seq b -> Maybe (LinearRing b)) -> Seq b -> Maybe (LinearRing b)
forall a b. (a -> b) -> a -> b
$ b
x b -> Seq b -> Seq b
forall s a. Cons s s a a => a -> s -> s
<| (Seq b
s Seq b -> b -> Seq b
forall s a. Snoc s s a a => s -> a -> s
|> b
x)

--------------------------------------------------------------------------------

-- | Access the underlying container
_UncheckedSimplePolygon :: Iso (SimplePolygonF (Cyclic ViewL1) point)
                               (SimplePolygonF (Cyclic ViewL1) point')
                               (Cyclic ViewL1 point)
                               (Cyclic ViewL1 point')
_UncheckedSimplePolygon :: forall point point' (p :: * -> * -> *) (f :: * -> *).
(Profunctor p, Functor f) =>
p (Cyclic ViewL1 point) (f (Cyclic ViewL1 point'))
-> p (SimplePolygonF (Cyclic ViewL1) point)
     (f (SimplePolygonF (Cyclic ViewL1) point'))
_UncheckedSimplePolygon = p (Cyclic ViewL1 point) (f (Cyclic ViewL1 point'))
-> p (SimplePolygonF (Cyclic ViewL1) point)
     (f (SimplePolygonF (Cyclic ViewL1) point'))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso
  (SimplePolygonF (Cyclic ViewL1) point)
  (SimplePolygonF (Cyclic ViewL1) point')
  (Cyclic ViewL1 point)
  (Cyclic ViewL1 point')
coerced

-- | Convert a ring to a simple polygon
_UncheckedRingSimplePolygon' :: Iso' (LinearRing GeoPositionWithoutCRS)
                                    (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
_UncheckedRingSimplePolygon' :: Iso'
  (LinearRing GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
_UncheckedRingSimplePolygon' = p (Cyclic ViewL1 GeoPositionWithoutCRS)
  (f (Cyclic ViewL1 GeoPositionWithoutCRS))
-> p (LinearRing GeoPositionWithoutCRS)
     (f (LinearRing GeoPositionWithoutCRS))
forall b a.
(Eq b, Show b) =>
Iso
  (LinearRing a) (LinearRing b) (Cyclic ViewL1 a) (Cyclic ViewL1 b)
Iso
  (LinearRing GeoPositionWithoutCRS)
  (LinearRing GeoPositionWithoutCRS)
  (Cyclic ViewL1 GeoPositionWithoutCRS)
  (Cyclic ViewL1 GeoPositionWithoutCRS)
_RingViewL1
                             (p (Cyclic ViewL1 GeoPositionWithoutCRS)
   (f (Cyclic ViewL1 GeoPositionWithoutCRS))
 -> p (LinearRing GeoPositionWithoutCRS)
      (f (LinearRing GeoPositionWithoutCRS)))
-> (p (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
      (f (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS))
    -> p (Cyclic ViewL1 GeoPositionWithoutCRS)
         (f (Cyclic ViewL1 GeoPositionWithoutCRS)))
-> p (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
     (f (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS))
-> p (LinearRing GeoPositionWithoutCRS)
     (f (LinearRing GeoPositionWithoutCRS))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnIso
  (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
  (Cyclic ViewL1 GeoPositionWithoutCRS)
  (Cyclic ViewL1 GeoPositionWithoutCRS)
-> Iso
     (Cyclic ViewL1 GeoPositionWithoutCRS)
     (Cyclic ViewL1 GeoPositionWithoutCRS)
     (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
     (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
forall s t a b. AnIso s t a b -> Iso b a t s
from AnIso
  (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
  (Cyclic ViewL1 GeoPositionWithoutCRS)
  (Cyclic ViewL1 GeoPositionWithoutCRS)
forall point point' (p :: * -> * -> *) (f :: * -> *).
(Profunctor p, Functor f) =>
p (Cyclic ViewL1 point) (f (Cyclic ViewL1 point'))
-> p (SimplePolygonF (Cyclic ViewL1) point)
     (f (SimplePolygonF (Cyclic ViewL1) point'))
_UncheckedSimplePolygon

-- | Treat a LinearRing as a simple polygon
_UncheckedRingSimplePolygon :: Iso' (LinearRing GeoPositionWithoutCRS)
                                    (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS')
_UncheckedRingSimplePolygon :: Iso'
  (LinearRing GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
_UncheckedRingSimplePolygon  = p (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
  (f (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS))
-> p (LinearRing GeoPositionWithoutCRS)
     (f (LinearRing GeoPositionWithoutCRS))
Iso'
  (LinearRing GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
_UncheckedRingSimplePolygon' (p (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
   (f (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS))
 -> p (LinearRing GeoPositionWithoutCRS)
      (f (LinearRing GeoPositionWithoutCRS)))
-> (p (SimplePolygonF
         (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
      (f (SimplePolygonF
            (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)))
    -> p (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
         (f (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)))
-> p (SimplePolygonF
        (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
     (f (SimplePolygonF
           (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)))
-> p (LinearRing GeoPositionWithoutCRS)
     (f (LinearRing GeoPositionWithoutCRS))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p (SimplePolygonF
     (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
  (f (SimplePolygonF
        (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)))
-> p (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
     (f (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS))
Iso'
  (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
convert

-- | Convert the points
convert :: Iso'  (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
                 (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS')
convert :: Iso'
  (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
convert = (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS
 -> SimplePolygonF
      (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
-> (SimplePolygonF
      (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)
    -> SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
-> Iso'
     (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
     (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (ASetter
  (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
  GeoPositionWithoutCRS
  (PointXY :+ Maybe RestGeoPosition)
-> (GeoPositionWithoutCRS -> PointXY :+ Maybe RestGeoPosition)
-> SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS
-> SimplePolygonF
     (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter
  (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
  GeoPositionWithoutCRS
  (PointXY :+ Maybe RestGeoPosition)
(Vertex (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
 -> Identity
      (Vertex
         (SimplePolygonF
            (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))))
-> SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS
-> Identity
     (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
forall graph graph'.
HasVertices graph graph' =>
IndexedTraversal1
  (VertexIx graph) graph graph' (Vertex graph) (Vertex graph')
IndexedTraversal1
  (VertexIx (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS))
  (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
  (Vertex (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS))
  (Vertex
     (SimplePolygonF
        (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)))
vertices (Getting
  (PointXY :+ Maybe RestGeoPosition)
  GeoPositionWithoutCRS
  (PointXY :+ Maybe RestGeoPosition)
-> GeoPositionWithoutCRS -> PointXY :+ Maybe RestGeoPosition
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting
  (PointXY :+ Maybe RestGeoPosition)
  GeoPositionWithoutCRS
  (PointXY :+ Maybe RestGeoPosition)
Iso' GeoPositionWithoutCRS (PointXY :+ Maybe RestGeoPosition)
_GeoPositionWithoutCRS'))
              (ASetter
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
  (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
  (PointXY :+ Maybe RestGeoPosition)
  GeoPositionWithoutCRS
-> ((PointXY :+ Maybe RestGeoPosition) -> GeoPositionWithoutCRS)
-> SimplePolygonF
     (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)
-> SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
  (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
  (PointXY :+ Maybe RestGeoPosition)
  GeoPositionWithoutCRS
(Vertex
   (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
 -> Identity
      (Vertex (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)))
-> SimplePolygonF
     (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)
-> Identity (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
forall graph graph'.
HasVertices graph graph' =>
IndexedTraversal1
  (VertexIx graph) graph graph' (Vertex graph) (Vertex graph')
IndexedTraversal1
  (VertexIx
     (SimplePolygonF
        (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)))
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
  (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
  (Vertex
     (SimplePolygonF
        (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)))
  (Vertex (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS))
vertices (Getting
  GeoPositionWithoutCRS
  (PointXY :+ Maybe RestGeoPosition)
  GeoPositionWithoutCRS
-> (PointXY :+ Maybe RestGeoPosition) -> GeoPositionWithoutCRS
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view (Getting
   GeoPositionWithoutCRS
   (PointXY :+ Maybe RestGeoPosition)
   GeoPositionWithoutCRS
 -> (PointXY :+ Maybe RestGeoPosition) -> GeoPositionWithoutCRS)
-> Getting
     GeoPositionWithoutCRS
     (PointXY :+ Maybe RestGeoPosition)
     GeoPositionWithoutCRS
-> (PointXY :+ Maybe RestGeoPosition)
-> GeoPositionWithoutCRS
forall a b. (a -> b) -> a -> b
$ AnIso
  GeoPositionWithoutCRS
  GeoPositionWithoutCRS
  (PointXY :+ Maybe RestGeoPosition)
  (PointXY :+ Maybe RestGeoPosition)
-> Iso
     (PointXY :+ Maybe RestGeoPosition)
     (PointXY :+ Maybe RestGeoPosition)
     GeoPositionWithoutCRS
     GeoPositionWithoutCRS
forall s t a b. AnIso s t a b -> Iso b a t s
from AnIso
  GeoPositionWithoutCRS
  GeoPositionWithoutCRS
  (PointXY :+ Maybe RestGeoPosition)
  (PointXY :+ Maybe RestGeoPosition)
Iso' GeoPositionWithoutCRS (PointXY :+ Maybe RestGeoPosition)
_GeoPositionWithoutCRS'))


-- | Treat a LinearRing as a simple polygon
_InnerRingSimplePolygon :: Iso' (LinearRing GeoPositionWithoutCRS)
                                (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS')
_InnerRingSimplePolygon :: Iso'
  (LinearRing GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
_InnerRingSimplePolygon  = p (Cyclic ViewL1 GeoPositionWithoutCRS)
  (f (Cyclic ViewL1 GeoPositionWithoutCRS))
-> p (LinearRing GeoPositionWithoutCRS)
     (f (LinearRing GeoPositionWithoutCRS))
forall b a.
(Eq b, Show b) =>
Iso
  (LinearRing a) (LinearRing b) (Cyclic ViewL1 a) (Cyclic ViewL1 b)
Iso
  (LinearRing GeoPositionWithoutCRS)
  (LinearRing GeoPositionWithoutCRS)
  (Cyclic ViewL1 GeoPositionWithoutCRS)
  (Cyclic ViewL1 GeoPositionWithoutCRS)
_RingViewL1 (p (Cyclic ViewL1 GeoPositionWithoutCRS)
   (f (Cyclic ViewL1 GeoPositionWithoutCRS))
 -> p (LinearRing GeoPositionWithoutCRS)
      (f (LinearRing GeoPositionWithoutCRS)))
-> (p (SimplePolygonF
         (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
      (f (SimplePolygonF
            (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)))
    -> p (Cyclic ViewL1 GeoPositionWithoutCRS)
         (f (Cyclic ViewL1 GeoPositionWithoutCRS)))
-> p (SimplePolygonF
        (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
     (f (SimplePolygonF
           (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)))
-> p (LinearRing GeoPositionWithoutCRS)
     (f (LinearRing GeoPositionWithoutCRS))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p (Cyclic ViewL1 GeoPositionWithoutCRS)
  (f (Cyclic ViewL1 GeoPositionWithoutCRS))
-> p (Cyclic ViewL1 GeoPositionWithoutCRS)
     (f (Cyclic ViewL1 GeoPositionWithoutCRS))
forall a. Reversing a => Iso' a a
Iso'
  (Cyclic ViewL1 GeoPositionWithoutCRS)
  (Cyclic ViewL1 GeoPositionWithoutCRS)
reversed (p (Cyclic ViewL1 GeoPositionWithoutCRS)
   (f (Cyclic ViewL1 GeoPositionWithoutCRS))
 -> p (Cyclic ViewL1 GeoPositionWithoutCRS)
      (f (Cyclic ViewL1 GeoPositionWithoutCRS)))
-> (p (SimplePolygonF
         (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
      (f (SimplePolygonF
            (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)))
    -> p (Cyclic ViewL1 GeoPositionWithoutCRS)
         (f (Cyclic ViewL1 GeoPositionWithoutCRS)))
-> p (SimplePolygonF
        (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
     (f (SimplePolygonF
           (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)))
-> p (Cyclic ViewL1 GeoPositionWithoutCRS)
     (f (Cyclic ViewL1 GeoPositionWithoutCRS))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnIso
  (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
  (Cyclic ViewL1 GeoPositionWithoutCRS)
  (Cyclic ViewL1 GeoPositionWithoutCRS)
-> Iso
     (Cyclic ViewL1 GeoPositionWithoutCRS)
     (Cyclic ViewL1 GeoPositionWithoutCRS)
     (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
     (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
forall s t a b. AnIso s t a b -> Iso b a t s
from AnIso
  (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
  (Cyclic ViewL1 GeoPositionWithoutCRS)
  (Cyclic ViewL1 GeoPositionWithoutCRS)
forall point point' (p :: * -> * -> *) (f :: * -> *).
(Profunctor p, Functor f) =>
p (Cyclic ViewL1 point) (f (Cyclic ViewL1 point'))
-> p (SimplePolygonF (Cyclic ViewL1) point)
     (f (SimplePolygonF (Cyclic ViewL1) point'))
_UncheckedSimplePolygon (p (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
   (f (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS))
 -> p (Cyclic ViewL1 GeoPositionWithoutCRS)
      (f (Cyclic ViewL1 GeoPositionWithoutCRS)))
-> (p (SimplePolygonF
         (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
      (f (SimplePolygonF
            (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)))
    -> p (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
         (f (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)))
-> p (SimplePolygonF
        (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
     (f (SimplePolygonF
           (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)))
-> p (Cyclic ViewL1 GeoPositionWithoutCRS)
     (f (Cyclic ViewL1 GeoPositionWithoutCRS))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p (SimplePolygonF
     (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
  (f (SimplePolygonF
        (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)))
-> p (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
     (f (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS))
Iso'
  (SimplePolygonF (Cyclic ViewL1) GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
convert

-- | Helper type
type GeoPolygonalDomain = PolygonalDomainF Seq (Cyclic ViewL1) GeoPositionWithoutCRS'

-- | Interpret the GeoPolygon as a Polygonal domain
_GeoPolygonPolygonalDomain :: Iso' GeoPolygon GeoPolygonalDomain
_GeoPolygonPolygonalDomain :: Iso' GeoPolygon GeoPolygonalDomain
_GeoPolygonPolygonalDomain = (GeoPolygon -> GeoPolygonalDomain)
-> (GeoPolygonalDomain -> GeoPolygon)
-> Iso' GeoPolygon GeoPolygonalDomain
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso GeoPolygon -> GeoPolygonalDomain
toPD GeoPolygonalDomain -> GeoPolygon
fromPD
  where
    toPD :: GeoPolygon -> GeoPolygonalDomain
toPD (GeoPolygon Seq (LinearRing GeoPositionWithoutCRS)
rings) = case Seq (LinearRing GeoPositionWithoutCRS)
rings of
      Seq (LinearRing GeoPositionWithoutCRS)
Seq.Empty          -> String -> GeoPolygonalDomain
forall a. HasCallStack => String -> a
error String
"invalid"
      (LinearRing GeoPositionWithoutCRS
outer :<| Seq (LinearRing GeoPositionWithoutCRS)
inners) ->  SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)
-> Seq
     (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
-> GeoPolygonalDomain
forall (h :: * -> *) (f :: * -> *) point.
SimplePolygonF f point
-> h (SimplePolygonF f point) -> PolygonalDomainF h f point
PolygonalDomain (LinearRing GeoPositionWithoutCRS
outerLinearRing GeoPositionWithoutCRS
-> Getting
     (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
     (LinearRing GeoPositionWithoutCRS)
     (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
-> SimplePolygonF
     (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)
forall s a. s -> Getting a s a -> a
^.Getting
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
  (LinearRing GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
Iso'
  (LinearRing GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
_UncheckedRingSimplePolygon)
                                             (Seq (LinearRing GeoPositionWithoutCRS)
innersSeq (LinearRing GeoPositionWithoutCRS)
-> (Seq (LinearRing GeoPositionWithoutCRS)
    -> Seq
         (SimplePolygonF
            (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)))
-> Seq
     (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
forall a b. a -> (a -> b) -> b
&(LinearRing GeoPositionWithoutCRS
 -> Identity
      (SimplePolygonF
         (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)))
-> Seq (LinearRing GeoPositionWithoutCRS)
-> Identity
     (Seq
        (SimplePolygonF
           (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)))
forall (f :: * -> *) a b.
Traversable f =>
IndexedTraversal Int (f a) (f b) a b
IndexedTraversal
  Int
  (Seq (LinearRing GeoPositionWithoutCRS))
  (Seq
     (SimplePolygonF
        (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)))
  (LinearRing GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
traversed ((LinearRing GeoPositionWithoutCRS
  -> Identity
       (SimplePolygonF
          (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)))
 -> Seq (LinearRing GeoPositionWithoutCRS)
 -> Identity
      (Seq
         (SimplePolygonF
            (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))))
-> (LinearRing GeoPositionWithoutCRS
    -> SimplePolygonF
         (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
-> Seq (LinearRing GeoPositionWithoutCRS)
-> Seq
     (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Getting
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
  (LinearRing GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
-> LinearRing GeoPositionWithoutCRS
-> SimplePolygonF
     (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
  (LinearRing GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
Iso'
  (LinearRing GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
_InnerRingSimplePolygon)

    fromPD :: GeoPolygonalDomain -> GeoPolygon
fromPD (PolygonalDomain SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)
outer Seq
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
inners) =
      let outer' :: LinearRing GeoPositionWithoutCRS
outer'  = SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)
outerSimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)
-> Getting
     (LinearRing GeoPositionWithoutCRS)
     (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
     (LinearRing GeoPositionWithoutCRS)
-> LinearRing GeoPositionWithoutCRS
forall s a. s -> Getting a s a -> a
^.AnIso
  (LinearRing GeoPositionWithoutCRS)
  (LinearRing GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
-> Iso
     (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
     (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
     (LinearRing GeoPositionWithoutCRS)
     (LinearRing GeoPositionWithoutCRS)
forall s t a b. AnIso s t a b -> Iso b a t s
from AnIso
  (LinearRing GeoPositionWithoutCRS)
  (LinearRing GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
Iso'
  (LinearRing GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
_UncheckedRingSimplePolygon
          inners' :: Seq (LinearRing GeoPositionWithoutCRS)
inners' = Seq
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
innersSeq
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
-> (Seq
      (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
    -> Seq (LinearRing GeoPositionWithoutCRS))
-> Seq (LinearRing GeoPositionWithoutCRS)
forall a b. a -> (a -> b) -> b
&(SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)
 -> Identity (LinearRing GeoPositionWithoutCRS))
-> Seq
     (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
-> Identity (Seq (LinearRing GeoPositionWithoutCRS))
forall (f :: * -> *) a b.
Traversable f =>
IndexedTraversal Int (f a) (f b) a b
IndexedTraversal
  Int
  (Seq
     (SimplePolygonF
        (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)))
  (Seq (LinearRing GeoPositionWithoutCRS))
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
  (LinearRing GeoPositionWithoutCRS)
traversed ((SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)
  -> Identity (LinearRing GeoPositionWithoutCRS))
 -> Seq
      (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
 -> Identity (Seq (LinearRing GeoPositionWithoutCRS)))
-> (SimplePolygonF
      (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)
    -> LinearRing GeoPositionWithoutCRS)
-> Seq
     (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
-> Seq (LinearRing GeoPositionWithoutCRS)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ AReview
  (LinearRing GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
-> SimplePolygonF
     (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition)
-> LinearRing GeoPositionWithoutCRS
forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review AReview
  (LinearRing GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
Iso'
  (LinearRing GeoPositionWithoutCRS)
  (SimplePolygonF (Cyclic ViewL1) (PointXY :+ Maybe RestGeoPosition))
_UncheckedRingSimplePolygon
      in Seq (LinearRing GeoPositionWithoutCRS) -> GeoPolygon
GeoPolygon (Seq (LinearRing GeoPositionWithoutCRS) -> GeoPolygon)
-> Seq (LinearRing GeoPositionWithoutCRS) -> GeoPolygon
forall a b. (a -> b) -> a -> b
$ LinearRing GeoPositionWithoutCRS
outer' LinearRing GeoPositionWithoutCRS
-> Seq (LinearRing GeoPositionWithoutCRS)
-> Seq (LinearRing GeoPositionWithoutCRS)
forall s a. Cons s s a a => a -> s -> s
<| Seq (LinearRing GeoPositionWithoutCRS)
inners'


-- --------------------------------------------------------------------------------

-- instance HasVertices' GeoPolygon where
--   type VertexIx GeoPolygon = (Int,Int) -- first one is the ringId
--   type Vertex   GeoPolygon = GeoPositionWithoutCRS'

--   vertexAt (i,j) = _Wrapped .> iix i <.> _RingAsSimplePolygon .> vertexAt j
--                  <. _GeoPositionWithoutCRS

--   numVertices (GeoPolygon ss) = F.foldl' (\a s -> a + ringLength s - 1) 0 ss
--   -- -- the ring incluces a copy of the first element, so it overestimates the length by 1

-- instance HasVertices GeoPolygon GeoPolygon where
--   vertices = _Wrapped .> traversed1Seq <.> _RingAsSimplePolygon .> vertices
--           <. singular _GeoPositionWithoutCRS
-- -- TODO: the internal ones should be reversed

-- withRing   :: Int -> IndexedLens' Int GeoPolygon (SimplePolygonF Seq1 GeoPositionWithoutCRS)
-- withRing i = _Wrapped .> singular (iix i) <. _RingAsSimplePolygon

-- firstRing :: IndexedLens' Int GeoPolygon (SimplePolygonF Seq1 GeoPositionWithoutCRS)
-- firstRing = withRing 0

-- -- | unsafe conversion wrapping an edge
-- edge' :: Iso' (GeoPositionWithoutCRS, GeoPositionWithoutCRS)
--               (GeoPositionWithoutCRS', GeoPositionWithoutCRS')
-- edge' = iso (\(u,v) -> (u^?!_GeoPositionWithoutCRS, v^?!_GeoPositionWithoutCRS))
--             (\(u,v) -> (u^?!re _GeoPositionWithoutCRS, v^?!re _GeoPositionWithoutCRS))

-- reIndexEdge :: Indexable ( (Int,Int) , (Int,Int)) p
--             => (Indexed (Int,(Int,Int)) a b -> r) -> p a b -> r
-- reIndexEdge = reindexed (\(i,(u,v)) -> ((i,u), (i,v)))

-- instance HasOuterBoundary GeoPolygon where
--   outerBoundaryVertexAt (i,j)
--     | i == 0    = firstRing <.> singular (vertexAt j) <. singular _GeoPositionWithoutCRS
--     | otherwise = error "outerBoundaryVertex: not on first ring"
--   -- the first ring is outer boundary apparently

--   ccwOuterBoundaryFrom (i,j)
--     | i == 0    = firstRing <.> ccwOuterBoundaryFrom j <. singular _GeoPositionWithoutCRS
--     | otherwise = error "ccwOuterBoundaryFrom: not on first ring"

--   outerBoundary = firstRing <.> vertices <. singular _GeoPositionWithoutCRS

--   cwOuterBoundaryFrom (i,j)
--     | i == 0    = firstRing <.> cwOuterBoundaryFrom j <. singular _GeoPositionWithoutCRS
--     | otherwise = error "cwOuterBoundaryFrom: not on first ring"

--   outerBoundaryEdges = reIndexEdge
--                      $ firstRing <.> outerBoundaryEdges <. edge'


--   outerBoundaryEdgeAt (_,j) = reIndexEdge
--                             $ firstRing <.> outerBoundaryEdgeAt j <. edge'

-- -- instance Polygon_ GeoPolygon GeoPositionWithoutCRS' Double where
-- --   area pg = case toNonEmptyOf (_Wrapped.from _Seq1Seq.traverse1._RingAsSimplePolygon') pg of
-- --     outer :| inners -> area outer - sum (map area inners)

--   -- ccwPredecessorOf (i,j) = withRing i <.> ccwPredecessorOf j <. singular _GeoPositionWithoutCRS
--   -- ccwSuccessorOf   (i,j) = withRing i <.> ccwSuccessorOf   j <. singular _GeoPositionWithoutCRS

-- {-

-- instance SimplePolygon_ GeoPolygon GeoPositionWithoutCRS' Double where
--   uncheckedFromCCWPoints = undefined
--   fromPoints = undefined


-- -- featureCollection ::

-- -- just make instances

-- -}

-- -- parseGeoJSONFile      :: OsPath -> IO ()
-- -- parseGeoJSONFile path =