| Copyright | © 2018-2019 Satsuma labs |
|---|---|
| Safe Haskell | None |
| Language | Haskell2010 |
Data.LatLong
Contents
Description
Defines a type for georgraphic coordinates that can be spatially indexed by any database supporting 64 bit integer values.
This indexing works by reperesenting points using a Morton Z-Order curce, with each coordinate reperesented as a 32-bit fixed-point value
which then have their bits interleaved into a 64-bit integer to the internal reperesentation.
Taking binary prefixes of these values divides the globe into a hierarchy of rectangular tiles (repereseteh here as LatLongTile objects),
each of which is a contiguous interval when points are ordered according to their integer reperesentations.
As any geographic region can be covered by a small number of tiles of simillar size, this provides an easy to loop up data for specific reguions.
Instances and a filter for persistent are provided for this purpose.
Synopsis
- newtype LatLong where
- lat :: Lens' LatLong Double
- long :: Lens' LatLong Double
- earthRadius :: Double
- geoDistance :: LatLong -> LatLong -> Double
- geoSquare :: LatLong -> Double -> (LatLong, LatLong)
- data LatLongTile
- latLongTileInterval :: LatLongTile -> Interval LatLong
- latLongTileCover :: LatLong -> LatLong -> [LatLongTile]
- latLongTileCoverSquare :: LatLong -> Double -> [LatLongTile]
- tileSetElem :: LatLong -> [LatLongTile] -> Bool
- withinTileSet :: EntityField row LatLong -> [LatLongTile] -> Filter row
Documentation
Type for storing geographic coordinates that can be spatially indexed (Morton ordering).
Each coordinate is reperesented as as 32-bit fixed point value and is also accessible as a Double through a pattern synonym.
Order follows a Morton Z-order curve which can be used to search a database by tiles.
This works with any database capable of storing and indexing Word64 (although this type only uses those values fitting in a 64 bit signed integer)
Bundled Patterns
| pattern LatLong :: Double -> Double -> LatLong | Pattern for accessing latitide and longitude coordinates as |
Instances
| Eq LatLong Source # | |
| Ord LatLong Source # | |
| Show LatLong Source # | |
| ToJSON LatLong Source # | |
Defined in Data.LatLong | |
| FromJSON LatLong Source # | |
| ToHttpApiData LatLong Source # | |
Defined in Data.LatLong Methods toUrlPiece :: LatLong -> Text # toEncodedUrlPiece :: LatLong -> Builder # toHeader :: LatLong -> ByteString # toQueryParam :: LatLong -> Text # | |
| FromHttpApiData LatLong Source # | |
Defined in Data.LatLong Methods parseUrlPiece :: Text -> Either Text LatLong # parseHeader :: ByteString -> Either Text LatLong # | |
| PersistFieldSql LatLong Source # | |
| PersistField LatLong Source # | |
Defined in Data.LatLong Methods toPersistValue :: LatLong -> PersistValue # | |
earthRadius :: Double Source #
Earth's average radius in meters
geoDistance :: LatLong -> LatLong -> Double Source #
Calculate distance between two points using the Haversine formula (up to 0.5% due to the assumption of a spherical Earth). Distance is returned in meters.
geoSquare :: LatLong -> Double -> (LatLong, LatLong) Source #
Calculates the corner coordinates of a square with a given center and radius (in meters). Based on the Mercator projection thus has distortion near the poles (within 5% for a radius at most 200km and latitude within ±70).
Tiles
data LatLongTile Source #
Represents a LatLong tile, which is both a rectangle and a contoguous interval in the ordering.
Instances
| Eq LatLongTile Source # | |
Defined in Data.LatLong | |
| Read LatLongTile Source # | |
Defined in Data.LatLong Methods readsPrec :: Int -> ReadS LatLongTile # readList :: ReadS [LatLongTile] # readPrec :: ReadPrec LatLongTile # readListPrec :: ReadPrec [LatLongTile] # | |
| Show LatLongTile Source # | |
Defined in Data.LatLong Methods showsPrec :: Int -> LatLongTile -> ShowS # show :: LatLongTile -> String # showList :: [LatLongTile] -> ShowS # | |
latLongTileInterval :: LatLongTile -> Interval LatLong Source #
Gets the corners of a tile, which are also the bounds of its interval in sort order.
latLongTileCover :: LatLong -> LatLong -> [LatLongTile] Source #
Covers a rectangle (defined by its corners) tiles of at most its size.
latLongTileCoverSquare :: LatLong -> Double -> [LatLongTile] Source #
Covers a square (defined by its center and radius) by tiles.
tileSetElem :: LatLong -> [LatLongTile] -> Bool Source #
Tests whether a point is contasined in a tile set.
withinTileSet :: EntityField row LatLong -> [LatLongTile] -> Filter row Source #
Persistent filter producing the SQL equiveland ot tileSetElem.