persistent-spatial-0.1.0.0: Database agnostic, spatially indexed type for geographic points.

Copyright© 2018-2019 Satsuma labs
Safe HaskellNone
LanguageHaskell2010

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

Documentation

newtype LatLong Source #

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)

Constructors

LatLongZ Morton

Underlying reperesentation and source of ordering for indexing

Bundled Patterns

pattern LatLong :: Double -> Double -> LatLong

Pattern for accessing latitide and longitude coordinates as Double values. This is not fully isomoprphic as latitude is clipped to ±90, longitude is wrapped mod 360 ±180, and rounding error exists due to the internal fixed-point reperesentation.

Instances
Eq LatLong Source # 
Instance details

Defined in Data.LatLong

Methods

(==) :: LatLong -> LatLong -> Bool #

(/=) :: LatLong -> LatLong -> Bool #

Ord LatLong Source # 
Instance details

Defined in Data.LatLong

Show LatLong Source # 
Instance details

Defined in Data.LatLong

ToJSON LatLong Source # 
Instance details

Defined in Data.LatLong

FromJSON LatLong Source # 
Instance details

Defined in Data.LatLong

ToHttpApiData LatLong Source # 
Instance details

Defined in Data.LatLong

FromHttpApiData LatLong Source # 
Instance details

Defined in Data.LatLong

PersistFieldSql LatLong Source # 
Instance details

Defined in Data.LatLong

PersistField LatLong Source # 
Instance details

Defined in Data.LatLong

lat :: Lens' LatLong Double Source #

Lens for latitude.

long :: Lens' LatLong Double Source #

Lens for longitude.

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.

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.