Maintainer | Dom De Re |
---|---|
Safe Haskell | None |
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.
- data LinearRing 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
Type
data LinearRing a Source
a LinearRing has at least 3 (distinct) elements
Functor LinearRing | |
Foldable LinearRing | This instance of Foldable will run through the entire ring, closing the loop by also passing the initial element in again at the end. (\xs -> (foldr (:) [] xs) == (fromLinearRing xs)) (xs :: LinearRing Int) (\xs -> (ringHead xs) == (foldr'' (\a -> const a) 0 xs)) (xs :: LinearRing Int) |
Traversable LinearRing | When traversing this Structure, the Applicative context of the last element will be appended to the end to close the loop |
Eq a => Eq (LinearRing a) | |
Show a => Show (LinearRing a) | |
ToJSON a => ToJSON (LinearRing a) | |
(FromJSON a, Show a) => FromJSON (LinearRing a) |
Functions
fromLinearRing :: LinearRing a -> [a]Source
This function converts it into a list and appends the given element to the end.
(xs -> safeLast (fromLinearRing xs) == Just (ringHead xs)) (xs :: LinearRing Int)
(xs -> length (fromLinearRing xs) >= 4) (xs :: LinearRing Int)
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.
>>>
fromList [] :: AccValidation (NonEmpty (ListToLinearRingError Int)) (LinearRing Int)
AccFailure (List too short: (length = 0) :| [])
>>>
fromList [0] :: AccValidation (NonEmpty (ListToLinearRingError Int)) (LinearRing Int)
AccFailure (List too short: (length = 1) :| [])
>>>
fromList [0, 1] :: AccValidation (NonEmpty (ListToLinearRingError Int)) (LinearRing Int)
AccFailure (List too short: (length = 2) :| [])
>>>
fromList [0, 1, 2] :: AccValidation (NonEmpty (ListToLinearRingError Int)) (LinearRing Int)
AccFailure (List too short: (length = 3) :| [])
>>>
fromList [0, 1, 2, 3] :: AccValidation (NonEmpty (ListToLinearRingError Int)) (LinearRing Int)
AccSuccess [0,1,2,0]
>>>
fromList [0, 1, 2, 4, 0] :: AccValidation (NonEmpty (ListToLinearRingError Int)) (LinearRing Int)
AccSuccess [0,1,2,4,0]
>>>
fromList [0, 1, 2, 4, 5, 0] :: AccValidation (NonEmpty (ListToLinearRingError Int)) (LinearRing Int)
AccSuccess [0,1,2,4,5,0]
Unfortunately it doesn't check that the last element is the same as the first at the moment...
>>>
fromList [0, 1, 2, 4, 5, 6] :: AccValidation (NonEmpty (ListToLinearRingError Int)) (LinearRing Int)
AccSuccess [0,1,2,4,5,0]
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 -> aSource
returns the element at the head of the ring