esqueleto-postgis-4.0.0: postgis bindings for esqueleto.
Safe HaskellNone
LanguageHaskell2010

Database.Esqueleto.Postgis

Description

Haskell bindings for postgres postgis for a good explenation see https://postgis.net/

Make sure to use the correct SpatialType. Earth spanning applications should use Geography, local applications should use Geometry because it's more convenient.

if you can't use a function for example when you're using Geography. there is the option to st_transform_geography.

Synopsis

Documentation

data Postgis (spatialType :: SpatialType) point Source #

like GeospatialGeometry but not partial, eg no empty geometries. Also can put an inveriant on dimensions if a function requires it. for example st_intersects PostgisGeometry PointXY can't work with PostgisGeometry PointXYZ. PointXY indicates a 2 dimension space, and PointXYZ a three dimension space.

Instances

Instances details
Functor (Postgis spatialType) Source # 
Instance details

Defined in Database.Esqueleto.Postgis

Methods

fmap :: (a -> b) -> Postgis spatialType a -> Postgis spatialType b #

(<$) :: a -> Postgis spatialType b -> Postgis spatialType a #

Show point => Show (Postgis spatialType point) Source # 
Instance details

Defined in Database.Esqueleto.Postgis

Methods

showsPrec :: Int -> Postgis spatialType point -> ShowS #

show :: Postgis spatialType point -> String #

showList :: [Postgis spatialType point] -> ShowS #

Eq point => Eq (Postgis spatialType point) Source # 
Instance details

Defined in Database.Esqueleto.Postgis

Methods

(==) :: Postgis spatialType point -> Postgis spatialType point -> Bool #

(/=) :: Postgis spatialType point -> Postgis spatialType point -> Bool #

HasPgType spatialType => PersistField (Postgis spatialType PointXY) Source # 
Instance details

Defined in Database.Esqueleto.Postgis

HasPgType spatialType => PersistField (Postgis spatialType PointXYZ) Source # 
Instance details

Defined in Database.Esqueleto.Postgis

HasPgType spatialType => PersistField (Postgis spatialType PointXYZM) Source # 
Instance details

Defined in Database.Esqueleto.Postgis

HasPgType spatialType => PersistFieldSql (Postgis spatialType PointXY) Source # 
Instance details

Defined in Database.Esqueleto.Postgis

Methods

sqlType :: Proxy (Postgis spatialType PointXY) -> SqlType #

HasPgType spatialType => PersistFieldSql (Postgis spatialType PointXYZ) Source # 
Instance details

Defined in Database.Esqueleto.Postgis

Methods

sqlType :: Proxy (Postgis spatialType PointXYZ) -> SqlType #

HasPgType spatialType => PersistFieldSql (Postgis spatialType PointXYZM) Source # 
Instance details

Defined in Database.Esqueleto.Postgis

Methods

sqlType :: Proxy (Postgis spatialType PointXYZM) -> SqlType #

data SpatialType Source #

Guarantees we don't accidently mix curved space with flat space. Postgis will catch this too, this just put's it in the type system.

Constructors

Geometry

assume a flat space.

Geography

assume curvature of the earth.

getPoints :: PostgisGeometry point -> NonEmpty point Source #

unwrap postgis geometry so you can for example return it from an API

functions

st_contains Source #

Arguments

:: SqlExpr (Value (Postgis 'Geometry a))

geom a

-> SqlExpr (Value (Postgis 'Geometry a))

geom b

-> SqlExpr (Value Bool) 

Returns TRUE if geometry A contains geometry B. https://postgis.net/docs/ST_Contains.html

st_intersects Source #

Arguments

:: forall (spatialType :: SpatialType) a. SqlExpr (Value (Postgis spatialType a))

geomA or geogA

-> SqlExpr (Value (Postgis spatialType a))

geomB or geogB

-> SqlExpr (Value Bool) 

Returns true if two geometries intersect. Geometries intersect if they have any point in common. https://postgis.net/docs/ST_Intersects.html

st_union :: SqlExpr (Value (Postgis 'Geometry a)) -> SqlExpr (Value (Postgis 'Geometry a)) Source #

allows union of geometries, eg group a bunch together, https://postgis.net/docs/ST_Union.html for example:

 mCombined <- selectOne $ do
   grid <- from $ table Grid
   pure $ st_union $ grid ^. GridGeom


 select $  do
   unit <- from $ table Unit
   forM_ mCombined $ combined ->
     where_ $ (unit ^. UnitGeom) st_intersects (val $ unValue combined)
   pure unit

st_dwithin Source #

Arguments

:: forall (spatialType :: SpatialType) a. SqlExpr (Value (Postgis spatialType a))

geometry g1

-> SqlExpr (Value (Postgis spatialType a))

geometry g2

-> SqlExpr (Value Double)

distance of srid

-> SqlExpr (Value Bool) 

Returns true if the geometries are within a given distance https://postgis.net/docs/ST_DWithin.html

st_distance :: forall (spatialType :: SpatialType) a. SqlExpr (Value (Postgis spatialType a)) -> SqlExpr (Value (Postgis spatialType a)) -> SqlExpr (Value Double) Source #

calculate the distance between two points https://postgis.net/docs/ST_Distance.html

points

point :: forall (spatialType :: SpatialType). Double -> Double -> Postgis spatialType PointXY Source #

point_v :: forall (spatialType :: SpatialType). HasPgType spatialType => Double -> Double -> SqlExpr (Value (Postgis spatialType PointXY)) Source #

st_point :: forall (spatialType :: SpatialType). SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value (Postgis spatialType PointXY)) Source #

st_point_xyz :: forall (spatialType :: SpatialType). SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value Double) -> SqlExpr (Value (Postgis spatialType PointXYZ)) Source #

transform

st_transform_geography Source #

Arguments

:: SRID 'Linear 
-> SqlExpr (Value (Postgis 'Geography a))

g1 (library handles the conversion)

-> SqlExpr (Value (Postgis 'Geometry a)) 

Project a geography onto a geometry. allows using of functions such as st_union which only work in flat space (geometry). https://postgis.net/docs/ST_Transform.html

st_transform_geometry Source #

Arguments

:: SqlExpr (Value (Postgis 'Geometry a))

g1 (library handles the conversion)

-> SqlExpr (Value (Postgis 'Geography a)) 

project a geometry as a geography, assumes wgs84. https://postgis.net/docs/ST_Transform.html

srid

data SRID (unit :: SridUnit) Source #

SRID you can find your local like this: https://blog.rustprooflabs.com/2020/11/postgis-find-local-srid geography appears to use wgs84. So I hardcoded the use going from geom to geography as that.

you can use the num instance to put in whatever. however, if you miss a srid please submit a PR.

Instances

Instances details
Num (SRID unit) Source # 
Instance details

Defined in Database.Esqueleto.Postgis

Methods

(+) :: SRID unit -> SRID unit -> SRID unit #

(-) :: SRID unit -> SRID unit -> SRID unit #

(*) :: SRID unit -> SRID unit -> SRID unit #

negate :: SRID unit -> SRID unit #

abs :: SRID unit -> SRID unit #

signum :: SRID unit -> SRID unit #

fromInteger :: Integer -> SRID unit #

PersistField (SRID unit) Source # 
Instance details

Defined in Database.Esqueleto.Postgis

wgs84 :: SRID 'Degree Source #

default for geography type in postgis. Geodetic CRS: WGS 84 https://epsg.io/4326

mercator :: SRID 'Linear Source #

most maps are in this, it has some large distortions further away from equator https://epsg.io/3857

britishNationalGrid :: SRID 'Linear Source #

if you're in england this is pretty good. https://epsg.io/27700

data SridUnit Source #

Diferent SRID come in different units, important for converting from geograhy to geometry.

Constructors

Linear

meters or feet

Degree

spheroids

other

makePolygon :: (Eq point, Show point) => point -> point -> point -> Seq point -> LinearRing point Source #

checks if the first point is the last, and if not so makes it so. this is required for inserting into the database

type PostgisGeometry = Postgis 'Geometry Source #

backwards compatibility, initial version only dealt in geometry

class HasPgType (spatialType :: SpatialType) Source #

technical typeclass to bind a spatial type to a string value. because we represent the constructors as a datakind, we need this to go back to a value.

Minimal complete definition

pgType

Instances

Instances details
HasPgType 'Geography Source # 
Instance details

Defined in Database.Esqueleto.Postgis

Methods

pgType :: Proxy 'Geography -> Text

HasPgType 'Geometry Source # 
Instance details

Defined in Database.Esqueleto.Postgis

Methods

pgType :: Proxy 'Geometry -> Text

re-exports

data PointXY #

(GeoPositionWithoutCRS is a catch all for indeterminate CRSs and for expression of positions before a CRS has been determined

Constructors

PointXY 

Fields

Instances

Instances details
Generic PointXY 
Instance details

Defined in Data.Geospatial.Internal.BasicTypes

Associated Types

type Rep PointXY 
Instance details

Defined in Data.Geospatial.Internal.BasicTypes

type Rep PointXY = D1 ('MetaData "PointXY" "Data.Geospatial.Internal.BasicTypes" "geojson-4.1.3-CvRMTkCmXKrLRGaX0qKQVX" 'False) (C1 ('MetaCons "PointXY" 'PrefixI 'True) (S1 ('MetaSel ('Just "_xyX") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double) :*: S1 ('MetaSel ('Just "_xyY") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double)))

Methods

from :: PointXY -> Rep PointXY x #

to :: Rep PointXY x -> PointXY #

Show PointXY 
Instance details

Defined in Data.Geospatial.Internal.BasicTypes

NFData PointXY 
Instance details

Defined in Data.Geospatial.Internal.BasicTypes

Methods

rnf :: PointXY -> () #

Eq PointXY 
Instance details

Defined in Data.Geospatial.Internal.BasicTypes

Methods

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

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

HasPgType spatialType => PersistField (Postgis spatialType PointXY) Source # 
Instance details

Defined in Database.Esqueleto.Postgis

HasPgType spatialType => PersistFieldSql (Postgis spatialType PointXY) Source # 
Instance details

Defined in Database.Esqueleto.Postgis

Methods

sqlType :: Proxy (Postgis spatialType PointXY) -> SqlType #

type Rep PointXY 
Instance details

Defined in Data.Geospatial.Internal.BasicTypes

type Rep PointXY = D1 ('MetaData "PointXY" "Data.Geospatial.Internal.BasicTypes" "geojson-4.1.3-CvRMTkCmXKrLRGaX0qKQVX" 'False) (C1 ('MetaCons "PointXY" 'PrefixI 'True) (S1 ('MetaSel ('Just "_xyX") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double) :*: S1 ('MetaSel ('Just "_xyY") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double)))

data PointXYZ #

Constructors

PointXYZ 

Fields

Instances

Instances details
Generic PointXYZ 
Instance details

Defined in Data.Geospatial.Internal.BasicTypes

Associated Types

type Rep PointXYZ 
Instance details

Defined in Data.Geospatial.Internal.BasicTypes

type Rep PointXYZ = D1 ('MetaData "PointXYZ" "Data.Geospatial.Internal.BasicTypes" "geojson-4.1.3-CvRMTkCmXKrLRGaX0qKQVX" 'False) (C1 ('MetaCons "PointXYZ" 'PrefixI 'True) (S1 ('MetaSel ('Just "_xyzX") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double) :*: (S1 ('MetaSel ('Just "_xyzY") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double) :*: S1 ('MetaSel ('Just "_xyzZ") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double))))

Methods

from :: PointXYZ -> Rep PointXYZ x #

to :: Rep PointXYZ x -> PointXYZ #

Show PointXYZ 
Instance details

Defined in Data.Geospatial.Internal.BasicTypes

NFData PointXYZ 
Instance details

Defined in Data.Geospatial.Internal.BasicTypes

Methods

rnf :: PointXYZ -> () #

Eq PointXYZ 
Instance details

Defined in Data.Geospatial.Internal.BasicTypes

HasPgType spatialType => PersistField (Postgis spatialType PointXYZ) Source # 
Instance details

Defined in Database.Esqueleto.Postgis

HasPgType spatialType => PersistFieldSql (Postgis spatialType PointXYZ) Source # 
Instance details

Defined in Database.Esqueleto.Postgis

Methods

sqlType :: Proxy (Postgis spatialType PointXYZ) -> SqlType #

type Rep PointXYZ 
Instance details

Defined in Data.Geospatial.Internal.BasicTypes

type Rep PointXYZ = D1 ('MetaData "PointXYZ" "Data.Geospatial.Internal.BasicTypes" "geojson-4.1.3-CvRMTkCmXKrLRGaX0qKQVX" 'False) (C1 ('MetaCons "PointXYZ" 'PrefixI 'True) (S1 ('MetaSel ('Just "_xyzX") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double) :*: (S1 ('MetaSel ('Just "_xyzY") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double) :*: S1 ('MetaSel ('Just "_xyzZ") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double))))

data PointXYZM #

Constructors

PointXYZM 

Fields

Instances

Instances details
Generic PointXYZM 
Instance details

Defined in Data.Geospatial.Internal.BasicTypes

Associated Types

type Rep PointXYZM 
Instance details

Defined in Data.Geospatial.Internal.BasicTypes

type Rep PointXYZM = D1 ('MetaData "PointXYZM" "Data.Geospatial.Internal.BasicTypes" "geojson-4.1.3-CvRMTkCmXKrLRGaX0qKQVX" 'False) (C1 ('MetaCons "PointXYZM" 'PrefixI 'True) ((S1 ('MetaSel ('Just "_xyzmX") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double) :*: S1 ('MetaSel ('Just "_xyzmY") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double)) :*: (S1 ('MetaSel ('Just "_xyzmZ") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double) :*: S1 ('MetaSel ('Just "_xyzmM") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double))))
Show PointXYZM 
Instance details

Defined in Data.Geospatial.Internal.BasicTypes

NFData PointXYZM 
Instance details

Defined in Data.Geospatial.Internal.BasicTypes

Methods

rnf :: PointXYZM -> () #

Eq PointXYZM 
Instance details

Defined in Data.Geospatial.Internal.BasicTypes

HasPgType spatialType => PersistField (Postgis spatialType PointXYZM) Source # 
Instance details

Defined in Database.Esqueleto.Postgis

HasPgType spatialType => PersistFieldSql (Postgis spatialType PointXYZM) Source # 
Instance details

Defined in Database.Esqueleto.Postgis

Methods

sqlType :: Proxy (Postgis spatialType PointXYZM) -> SqlType #

type Rep PointXYZM 
Instance details

Defined in Data.Geospatial.Internal.BasicTypes

type Rep PointXYZM = D1 ('MetaData "PointXYZM" "Data.Geospatial.Internal.BasicTypes" "geojson-4.1.3-CvRMTkCmXKrLRGaX0qKQVX" 'False) (C1 ('MetaCons "PointXYZM" 'PrefixI 'True) ((S1 ('MetaSel ('Just "_xyzmX") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double) :*: S1 ('MetaSel ('Just "_xyzmY") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double)) :*: (S1 ('MetaSel ('Just "_xyzmZ") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double) :*: S1 ('MetaSel ('Just "_xyzmM") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double))))