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

- data SequenceToLinearRingError a
- toSeq :: LinearRing a -> Seq a
- combineToSeq :: (a -> a -> b) -> LinearRing a -> Seq b
- fromSeq :: (Eq a, Show a, Validate v, Functor (v (NonEmpty (ListToLinearRingError a)))) => Seq a -> v (NonEmpty (SequenceToLinearRingError a)) (LinearRing a)
- fromLinearRing :: LinearRing a -> [a]
- fromList :: (Eq a, Show a, Validate v, Functor (v (NonEmpty (ListToLinearRingError a)))) => [a] -> v (NonEmpty (ListToLinearRingError a)) (LinearRing a)
- fromListWithEqCheck :: (Eq a, Show a, Validate v, Applicative (v (NonEmpty (ListToLinearRingError a)))) => [a] -> v (NonEmpty (ListToLinearRingError a)) (LinearRing a)
- makeLinearRing :: (Eq a, Show a) => a -> a -> a -> Seq 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

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 # |

data SequenceToLinearRingError a Source #

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

- The sequence can be too short
- The head may not be equal to the last element in the list

## Instances

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

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

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

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

# Functions

toSeq :: LinearRing a -> Seq a Source #

create a sequence from a LinearRing. LinearRing 1 2 3 [4,1] --> Seq [1,2,3,4,1)]

combineToSeq :: (a -> a -> b) -> LinearRing a -> Seq b Source #

create a sequence from a LinearRing by combining values. LinearRing 1 2 3 4,1 --> Seq [(1,2),(2,3),(3,4),(4,1)]

fromSeq :: (Eq a, Show a, Validate v, Functor (v (NonEmpty (ListToLinearRingError a)))) => Seq a -> v (NonEmpty (SequenceToLinearRingError a)) (LinearRing a) Source #

creates a LinearRing out of a sequence of elements, if there are enough elements (needs at least 3) elements

fromSeq (x:y:z:ws@(_:_)) = _Success # LinearRing x y z (fromListDropLast ws) fromSeq xs = _Failure # return (ListTooShort (length xs))

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

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

fromList :: (Eq a, Show a, 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, Show 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.

:: (Eq a, Show a) | |

=> a | The first element |

-> a | The second element |

-> a | The third element |

-> Seq 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.