naqsha-0.3.0.0: A library for working with anything map related.

Safe HaskellNone
LanguageHaskell2010

Naqsha.Geometry

Contents

Description

The geometric types and values exposed by naqsha.

Synopsis

Basics

A point on the globe is specified by giving its geo coordinates represented by the type Geo. It is essentially a pair of the Latitude and Longitude of the point.

Examples

kanpurLatitude  :: Latitude
kanpurLatitude  = lat $ degree 26.4477777
kanpurLongitude :: Longitude
kanpurLongitude = lon $ degree 80.3461111
kanpurGeo       :: Geo
kanpurGeo       = Geo kanpurLatitude kanpurLongitude

You can also specify the latitude and longitude in units of degree, minute and seconds.

kanpurLatitude  = lat $ degree 26 <> minute 26 <> second 52
kanpurLongitude = lon $ degree 80 <> minute 20 <> second 46

The show and read instance of the Latitude and Longitude types uses degrees for displaying and reading respectively. Show and Read instances can express these quantities up to Nano degree precision.

Convention on sign.

For latitudes, positive means north of the equator and negative means south. In the case of longitudes, positive means east of the longitude zero and negative means west. However, if you find these conventions confusing you can use the combinators north, south, east, and west when constructing latitudes or longitudes.

data Geo Source #

The coordinates of a point on the earth's surface.

Constructors

Geo !Latitude !Longitude 
Instances
Eq Geo Source # 
Instance details

Defined in Naqsha.Geometry.Coordinate

Methods

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

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

Show Geo Source # 
Instance details

Defined in Naqsha.Geometry.Coordinate

Methods

showsPrec :: Int -> Geo -> ShowS #

show :: Geo -> String #

showList :: [Geo] -> ShowS #

Vector Vector Geo Source # 
Instance details

Defined in Naqsha.Geometry.Coordinate

MVector MVector Geo Source # 
Instance details

Defined in Naqsha.Geometry.Coordinate

newtype Vector Geo Source # 
Instance details

Defined in Naqsha.Geometry.Coordinate

newtype Vector Geo = GeoV (Vector (Angle, Angle))
newtype MVector s Geo Source # 
Instance details

Defined in Naqsha.Geometry.Coordinate

newtype MVector s Geo = MGeoV (MVector s (Angle, Angle))

northPole :: Geo Source #

The North pole

southPole :: Geo Source #

The South pole

Latitudes

data Latitude Source #

The latitude of a point. Positive denotes North of Equator where as negative South.

Instances
Bounded Latitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Eq Latitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Ord Latitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Read Latitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Show Latitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Bits Latitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Angular Latitude Source # 
Instance details

Defined in Naqsha.Geometry.Angle

Vector Vector Latitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

MVector MVector Latitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

newtype Vector Latitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

newtype MVector s Latitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

lat :: Angle -> Latitude Source #

Construct latitude out of an angle.

north :: Angle -> Latitude Source #

Convert an angle to a northern latitude

tropicOfCancer = north $ degree 23.5

south :: Angle -> Latitude Source #

Convert an angle to a southern latitude.

 tropicOfCapricon = south $ degree 23.5

equator :: Latitude Source #

The latitude of equator.

tropicOfCancer :: Latitude Source #

The latitude corresponding to the Tropic of Cancer.

tropicOfCapricon :: Latitude Source #

The latitude corresponding to the Tropic of Capricon

Longitudes.

data Longitude Source #

The longitude of a point. Positive denotes East of the Greenwich meridian where as negative denotes West.

Instances
Bounded Longitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Eq Longitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Ord Longitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Read Longitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Show Longitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Semigroup Longitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Monoid Longitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Bits Longitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Group Longitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Angular Longitude Source # 
Instance details

Defined in Naqsha.Geometry.Angle

Vector Vector Longitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

MVector MVector Longitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

newtype Vector Longitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

newtype MVector s Longitude Source # 
Instance details

Defined in Naqsha.Geometry.Internal

lon :: Angle -> Longitude Source #

Convert angles to longitude.

east :: Angle -> Longitude Source #

Convert angle to an eastern longitude.

kanpurLongitude = east $ degree 80.3461

west :: Angle -> Longitude Source #

Convert angle to a western longitude

newyorkLongitude = west $ degree 74.0059

greenwich :: Longitude Source #

The zero longitude.

Angles and angular quantities.

data Angle Source #

An abstract angle. Internally, angles are represented as a 64-bit integer with each unit contribute 1/2^64 fraction of a complete circle. This means that angles are accurate up to a resolution of 2 π / 2^64 radians. Angles form a group under the angular addition and the fact that these are represented as integers means one can expect high speed accurate angle arithmetic.

When expressing angles one can use a more convenient notation:

myAngle   = degree 21.71167
yourAngle = degree 21 <> minute 42 <> second 42
Instances
Bounded Angle Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Enum Angle Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Eq Angle Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Methods

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

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

Ord Angle Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Methods

compare :: Angle -> Angle -> Ordering #

(<) :: Angle -> Angle -> Bool #

(<=) :: Angle -> Angle -> Bool #

(>) :: Angle -> Angle -> Bool #

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

max :: Angle -> Angle -> Angle #

min :: Angle -> Angle -> Angle #

Read Angle Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Show Angle Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Methods

showsPrec :: Int -> Angle -> ShowS #

show :: Angle -> String #

showList :: [Angle] -> ShowS #

Semigroup Angle Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Methods

(<>) :: Angle -> Angle -> Angle #

sconcat :: NonEmpty Angle -> Angle #

stimes :: Integral b => b -> Angle -> Angle #

Monoid Angle Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Methods

mempty :: Angle #

mappend :: Angle -> Angle -> Angle #

mconcat :: [Angle] -> Angle #

Bits Angle Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Group Angle Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Methods

invert :: Angle -> Angle #

pow :: Integral x => Angle -> x -> Angle #

Unbox Angle Source # 
Instance details

Defined in Naqsha.Geometry.Internal

Angular Angle Source # 
Instance details

Defined in Naqsha.Geometry.Angle

Methods

toAngle :: Angle -> Angle Source #

Vector Vector Angle Source # 
Instance details

Defined in Naqsha.Geometry.Internal

MVector MVector Angle Source # 
Instance details

Defined in Naqsha.Geometry.Internal

newtype Vector Angle Source # 
Instance details

Defined in Naqsha.Geometry.Internal

newtype MVector s Angle Source # 
Instance details

Defined in Naqsha.Geometry.Internal

newtype MVector s Angle = MAngV (MVector s Int64)

degree :: Rational -> Angle Source #

Express angle in degrees.

minute :: Rational -> Angle Source #

Express angle in minutes.

second :: Rational -> Angle Source #

Express angle in seconds.

radian :: Double -> Angle Source #

Express angle in radians

toDegree :: Fractional r => Angle -> r Source #

Measure angle in degrees. This conversion may lead to loss of precision.

toRadian :: Angle -> Double Source #

Measure angle in radians. This conversion may lead to loss of precision.

class Angular a where Source #

Angular quantities.

Methods

toAngle :: a -> Angle Source #

Instances
Angular Longitude Source # 
Instance details

Defined in Naqsha.Geometry.Angle

Angular Latitude Source # 
Instance details

Defined in Naqsha.Geometry.Angle

Angular Angle Source # 
Instance details

Defined in Naqsha.Geometry.Angle

Methods

toAngle :: Angle -> Angle Source #

Geometric hashing.

Geometric hashing is a technique of converting geometric coordinates into 1-dimension strings. Often these hashes ensures that string with large common prefix are close by (although not the converse). Hence, these hashes can be used to stored geo-cordinates in database and build into it a sense of location awareness. We support the following geometric hashing:

Naqsha.Geometry.Coordinate.GeoHash:
The geohash standard (https://en.wikipedia.org/wiki/Geohash).

None of these modules are imported by default the user may import the one that is most desirable.

Distance calculation.

Calculating quantities like distance, bearing etc depends on the model of the globe that we choose. Even in a given model we might have different algorithms to compute the distance depending on speed-accuracy trade-offs. Choosing the correct model and algorithms is application dependent and hence we do not expose any default ones. The following modules can be imported depending on the need

Naqsha.Geometry.Spherical:
Assume a spherical model of the globe. Distance is calculated using the haversine formula.

Internal details

The basic types like Latitude or Longitude are exposed as opaque types from this module. This gives a certain amount of type safety when working with these quantities. A user should, whenever possible, only use this module. For the rare case when some non-trivial operations need to be defined, we expose the internal module Naqsha.Geometry.Internal. However, use this interface with caution.