Copyright | (C) 2014-2018 HS-GeoJSON Project |
---|---|

License | BSD-style (see the file LICENSE.md) |

Maintainer | Andrew Newman |

Safe Haskell | None |

Language | Haskell2010 |

Refer to the GeoJSON Spec http://geojson.org/geojson-spec.html#polygon

A LinearRing is a List with at least 4 elements, where the first element is expected to be the same as the last.

## Synopsis

- data LinearRing a
- data ListToLinearRingError a
- = ListTooShort Int
- | HeadNotEqualToLast a a

- fromLinearRing :: LinearRing a -> [a]
- fromList :: (Validate v, Functor (v (NonEmpty (ListToLinearRingError a)))) => [a] -> v (NonEmpty (ListToLinearRingError a)) (LinearRing a)
- fromListWithEqCheck :: (Eq a, Validate v, Applicative (v (NonEmpty (ListToLinearRingError a)))) => [a] -> v (NonEmpty (ListToLinearRingError a)) (LinearRing a)
- makeLinearRing :: a -> a -> a -> [a] -> LinearRing a
- ringHead :: LinearRing a -> a
- ringLength :: LinearRing a -> Int

# Type

data LinearRing a Source #

a LinearRing has at least 3 (distinct) elements

## Instances

Functor LinearRing Source # | |

Defined in Data.LinearRing fmap :: (a -> b) -> LinearRing a -> LinearRing b # (<$) :: a -> LinearRing b -> LinearRing a # | |

Foldable LinearRing Source # | This instance of Foldable will run through the entire ring, closing the loop by also passing the initial element in again at the end. |

Defined in Data.LinearRing fold :: Monoid m => LinearRing m -> m # foldMap :: Monoid m => (a -> m) -> LinearRing a -> m # foldr :: (a -> b -> b) -> b -> LinearRing a -> b # foldr' :: (a -> b -> b) -> b -> LinearRing a -> b # foldl :: (b -> a -> b) -> b -> LinearRing a -> b # foldl' :: (b -> a -> b) -> b -> LinearRing a -> b # foldr1 :: (a -> a -> a) -> LinearRing a -> a # foldl1 :: (a -> a -> a) -> LinearRing a -> a # toList :: LinearRing a -> [a] # null :: LinearRing a -> Bool # length :: LinearRing a -> Int # elem :: Eq a => a -> LinearRing a -> Bool # maximum :: Ord a => LinearRing a -> a # minimum :: Ord a => LinearRing a -> a # sum :: Num a => LinearRing a -> a # product :: Num a => LinearRing a -> a # | |

Traversable LinearRing Source # | When traversing this Structure, the Applicative context of the last element will be appended to the end to close the loop |

Defined in Data.LinearRing traverse :: Applicative f => (a -> f b) -> LinearRing a -> f (LinearRing b) # sequenceA :: Applicative f => LinearRing (f a) -> f (LinearRing a) # mapM :: Monad m => (a -> m b) -> LinearRing a -> m (LinearRing b) # sequence :: Monad m => LinearRing (m a) -> m (LinearRing a) # | |

Eq a => Eq (LinearRing a) Source # | |

Defined in Data.LinearRing (==) :: LinearRing a -> LinearRing a -> Bool # (/=) :: LinearRing a -> LinearRing a -> Bool # | |

Show a => Show (LinearRing a) Source # | |

Defined in Data.LinearRing showsPrec :: Int -> LinearRing a -> ShowS # show :: LinearRing a -> String # showList :: [LinearRing a] -> ShowS # | |

ToJSON a => ToJSON (LinearRing a) Source # | |

Defined in Data.LinearRing toJSON :: LinearRing a -> Value # toEncoding :: LinearRing a -> Encoding # toJSONList :: [LinearRing a] -> Value # toEncodingList :: [LinearRing a] -> Encoding # | |

(FromJSON a, Show a) => FromJSON (LinearRing a) Source # | |

Defined in Data.LinearRing parseJSON :: Value -> Parser (LinearRing a) # parseJSONList :: Value -> Parser [LinearRing a] # |

data ListToLinearRingError a Source #

When converting a List to a LinearRing there are some things that can go wrong

- The list can be too short
- The head may not be equal to the last element in the list (NB this is not currently checked due to performance concerns, and it also doesnt make much sense since its likely to contain doubles)

## Instances

Eq a => Eq (ListToLinearRingError a) Source # | |

Defined in Data.LinearRing (==) :: ListToLinearRingError a -> ListToLinearRingError a -> Bool # (/=) :: ListToLinearRingError a -> ListToLinearRingError a -> Bool # | |

Show a => Show (ListToLinearRingError a) Source # | |

Defined in Data.LinearRing showsPrec :: Int -> ListToLinearRingError a -> ShowS # show :: ListToLinearRingError a -> String # showList :: [ListToLinearRingError a] -> ShowS # |

# Functions

fromLinearRing :: LinearRing a -> [a] Source #

This function converts it into a list and appends the given element to the end.

fromList :: (Validate v, Functor (v (NonEmpty (ListToLinearRingError a)))) => [a] -> v (NonEmpty (ListToLinearRingError a)) (LinearRing a) Source #

creates a LinearRing out of a list of elements, if there arent enough elements (needs at least 4) elements

This version doesnt check equality of the head and tail in case you wish to use it for elements with no Eq instance defined.

Also its a list, finding the last element could be expensive with large lists. So just follow the spec and make sure the ring is closed.

Ideally the Spec would be modified to remove the redundant last element from the Polygons/LineRings. Its just going to waste bandwidth...

And be aware that the last element of the list will be dropped.

Unfortunately it doesn't check that the last element is the same as the first at the moment...

fromListWithEqCheck :: (Eq a, Validate v, Applicative (v (NonEmpty (ListToLinearRingError a)))) => [a] -> v (NonEmpty (ListToLinearRingError a)) (LinearRing a) Source #

The expensive version of fromList that checks whether the head and last elements are equal.

:: a | The first element |

-> a | The second element |

-> a | The third element |

-> [a] | The rest of the optional elements (WITHOUT the first element repeated at the end) |

-> LinearRing a |

Creates a LinearRing
`makeLinearRing x y z xs`

creates a `LinearRing`

homomorphic to the list `[x, y, z] ++ xs`

the list `xs`

should NOT contain the first element repeated, i.e the loop does not need to
be closed, makeLinearRing will close it off.

Repeating the first element is just redundant.

ringHead :: LinearRing a -> a Source #

returns the element at the head of the ring

ringLength :: LinearRing a -> Int Source #

returns the number of elements in the list, including the replicated element at the end of the list.