esqueleto-postgis-4.1.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. You don't have to use Geography if you're only interested in topological functions such as st_intersects and st_union, these are indifferent to space distortions, see https://jappie.me/announcement-esqueleto-postgis-v4.html

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

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

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

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

Spatial relationships

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_within :: SqlExpr (Value (Postgis 'Geometry a)) -> SqlExpr (Value (Postgis 'Geometry a)) -> SqlExpr (Value Bool) Source #

Returns TRUE if geometry A is within geometry B. Tests if every point of A lies inside (interior or boundary of) B. The inverse of st_contains: st_within a b == st_contains b a. https://postgis.net/docs/ST_Within.html

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

Returns TRUE if geometry A touches geometry B. They have at least one boundary point in common, but no interior points. https://postgis.net/docs/ST_Touches.html

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

Returns TRUE if geometry A crosses geometry B. They have some but not all interior points in common. https://postgis.net/docs/ST_Crosses.html

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

Returns TRUE if geometry A is disjoint from geometry B. They do not share any space together, the inverse of st_intersects. https://postgis.net/docs/ST_Disjoint.html

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

Returns TRUE if geometry A is spatially equal to geometry B. The geometries represent the same region of space regardless of vertex order. https://postgis.net/docs/ST_Equals.html

st_covers :: forall (spatialType :: SpatialType) a. SqlExpr (Value (Postgis spatialType a)) -> SqlExpr (Value (Postgis spatialType a)) -> SqlExpr (Value Bool) Source #

Returns TRUE if geometrygeography A covers geometrygeography B. No point in B is outside A. Similar to st_contains but does not distinguish boundary and interior. https://postgis.net/docs/ST_Covers.html

st_coveredby :: forall (spatialType :: SpatialType) a. SqlExpr (Value (Postgis spatialType a)) -> SqlExpr (Value (Postgis spatialType a)) -> SqlExpr (Value Bool) Source #

Returns TRUE if geometrygeography A is covered by geometrygeography B. No point in A is outside B. The inverse of st_covers. https://postgis.net/docs/ST_CoveredBy.html

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

Returns TRUE if geometry A overlaps geometry B. They share some space but neither contains the other entirely. https://postgis.net/docs/ST_Overlaps.html

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

Returns TRUE if geometry A contains geometry B properly. B must lie entirely inside the interior of A (not touching the boundary). https://postgis.net/docs/ST_ContainsProperly.html

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

Returns the DE-9IM intersection matrix string for two geometries. https://postgis.net/docs/ST_Relate.html

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

Returns TRUE if two geometries are point-by-point equal in the same order. https://postgis.net/docs/ST_OrderingEquals.html

st_dfullywithin :: SqlExpr (Value (Postgis 'Geometry a)) -> SqlExpr (Value (Postgis 'Geometry a)) -> SqlExpr (Value Double) -> SqlExpr (Value Bool) Source #

Returns TRUE if all of the geometries are within the specified distance of one another. https://postgis.net/docs/ST_DFullyWithin.html

st_pointinsidecircle Source #

Arguments

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

center_x

-> SqlExpr (Value Double)

center_y

-> SqlExpr (Value Double)

radius

-> SqlExpr (Value Bool) 

Returns TRUE if the point geometry is inside the circle defined by center_x, center_y and radius. https://postgis.net/docs/ST_PointInsideCircle.html

Measurement functions

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

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_area :: forall (spatialType :: SpatialType) a. SqlExpr (Value (Postgis spatialType a)) -> SqlExpr (Value Double) Source #

Returns the area of a geometry or geography. For geometry, area is in SRID units squared. For geography, area is in square meters. https://postgis.net/docs/ST_Area.html

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

Returns the perimeter of a geometry or geography. For geometry, in SRID units. For geography, in meters. https://postgis.net/docs/ST_Perimeter.html

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

Returns the 2D length of a linear geometry or geography. For geometry, in SRID units. For geography, in meters. https://postgis.net/docs/ST_Length.html

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

Returns the azimuth in radians of the segment from point A to point B. The angle is measured clockwise from north (positive Y axis). https://postgis.net/docs/ST_Azimuth.html

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

Returns the maximum distance between two geometries. The distance of the furthest pair of points. https://postgis.net/docs/ST_MaxDistance.html

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

Returns the angle between two vectors defined by two 2-point linestrings. This is the 2-argument form of ST_Angle which expects linestring inputs. Passing point geometries will result in a NULL return value — use the 3 or 4 point overloads in PostGIS directly if you need point-based angles. https://postgis.net/docs/ST_Angle.html

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

Returns the 3D cartesian minimum distance between two geometries. https://postgis.net/docs/ST_3DDistance.html

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

Returns the minimum distance in meters between two lon/lat geometries using a spherical model. https://postgis.net/docs/ST_DistanceSphere.html

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

Returns the 3D maximum distance between two geometries. https://postgis.net/docs/ST_3DMaxDistance.html

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

Returns the minimum clearance of a geometry, the shortest distance between two distinct vertices. https://postgis.net/docs/ST_MinimumClearance.html

Geometry accessors

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

Returns the X coordinate of a point geometry. Only works on points; other geometry types will error. https://postgis.net/docs/ST_X.html

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

Returns the Y coordinate of a point geometry. Only works on points; other geometry types will error. https://postgis.net/docs/ST_Y.html

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

Returns the number of points (vertices) in a geometry. Works on any geometry type. https://postgis.net/docs/ST_NPoints.html

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

Returns the number of sub-geometries in a geometry collection or multi-type. Returns 1 for single geometries. https://postgis.net/docs/ST_NumGeometries.html

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

Returns the topological dimension of a geometry. 0 for points, 1 for lines, 2 for polygons. https://postgis.net/docs/ST_Dimension.html

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

Returns TRUE if the geometry has no self-intersections. Points and properly-formed polygons are always simple. https://postgis.net/docs/ST_IsSimple.html

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

Returns TRUE if the linestring's start and end points are coincident. For polyhedral surfaces, reports if the surface is areal (open) or volumetric (closed). https://postgis.net/docs/ST_IsClosed.html

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

Returns TRUE if the geometry is well-formed and valid per the OGC rules. Points and lines are always valid; polygons need correct ring structure. https://postgis.net/docs/ST_IsValid.html

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

Returns the spatial reference identifier (SRID) of the geometry. 0 means no SRID is set. https://postgis.net/docs/ST_SRID.html

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

Returns the coordinate dimension of a geometry (2, 3, or 4). https://postgis.net/docs/ST_CoordDim.html

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

Returns the Nth sub-geometry of a geometry collection (1-indexed). https://postgis.net/docs/ST_GeometryN.html

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

Returns the Nth interior ring of a polygon (1-indexed). https://postgis.net/docs/ST_InteriorRingN.html

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

Returns TRUE if the geometry is a geometry collection type. https://postgis.net/docs/ST_IsCollection.html

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

Returns TRUE if the geometry is an empty geometry. https://postgis.net/docs/ST_IsEmpty.html

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

Returns TRUE if all polygon rings are oriented counter-clockwise. https://postgis.net/docs/ST_IsPolygonCCW.html

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

Returns TRUE if all polygon rings are oriented clockwise. https://postgis.net/docs/ST_IsPolygonCW.html

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

Returns TRUE if the linestring is closed and simple (a ring). https://postgis.net/docs/ST_IsRing.html

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

Returns the M coordinate of a point. https://postgis.net/docs/ST_M.html

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

Returns the number of dimensions of a geometry's coordinates (2, 3, or 4). https://postgis.net/docs/ST_NDims.html

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

Returns the number of rings in a polygon (exterior + interior). https://postgis.net/docs/ST_NRings.html

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

Returns the number of points in a linestring. https://postgis.net/docs/ST_NumPoints.html

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

Returns the Nth point in a linestring (1-indexed). https://postgis.net/docs/ST_PointN.html

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

Returns the Z coordinate of a point. https://postgis.net/docs/ST_Z.html

Geometry constructors

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

Aggregate function that collects geometries into a geometry collection. https://postgis.net/docs/ST_Collect.html

st_makeenvelope Source #

Arguments

:: SqlExpr (Value Double)

xmin

-> SqlExpr (Value Double)

ymin

-> SqlExpr (Value Double)

xmax

-> SqlExpr (Value Double)

ymax

-> SqlExpr (Value Int)

srid

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

Creates a rectangular polygon from minimum and maximum coordinates. https://postgis.net/docs/ST_MakeEnvelope.html

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

Creates a polygon from a closed linestring shell. Named st_makepolygon_line to avoid collision with makePolygon. https://postgis.net/docs/ST_MakePolygon.html

Geometry editors

st_addpoint Source #

Arguments

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

linestring

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

point

-> SqlExpr (Value Int)

position

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

Adds a point to a linestring at a given position (0-indexed). https://postgis.net/docs/ST_AddPoint.html

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

Extracts sub-geometries of a specified type from a collection. Type: 1=POINT, 2=LINESTRING, 3=POLYGON. https://postgis.net/docs/ST_CollectionExtract.html

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

Forces polygon rings to counter-clockwise orientation. https://postgis.net/docs/ST_ForcePolygonCCW.html

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

Returns the geometry as a multi-type (e.g. POINT -> MULTIPOINT). https://postgis.net/docs/ST_Multi.html

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

Returns the geometry in its canonical (normalized) form. https://postgis.net/docs/ST_Normalize.html

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

Returns the geometry with vertex order reversed. https://postgis.net/docs/ST_Reverse.html

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

Segmentizes a geometry so no segment is longer than the given distance. https://postgis.net/docs/ST_Segmentize.html

st_setpoint Source #

Arguments

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

linestring

-> SqlExpr (Value Int)

0-based index

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

new point

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

Replaces a point of a linestring at a given 0-based index. https://postgis.net/docs/ST_SetPoint.html

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

Snaps all points of a geometry to a regular grid of the given size. https://postgis.net/docs/ST_SnapToGrid.html

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

Snaps vertices of one geometry to vertices and edges of another within a tolerance. https://postgis.net/docs/ST_Snap.html

Geometry validation

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

Attempts to make an invalid geometry valid without losing vertices. https://postgis.net/docs/ST_MakeValid.html

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

Returns text describing why a geometry is invalid, or "Valid Geometry". https://postgis.net/docs/ST_IsValidReason.html

SRS functions

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

Sets the SRID on a geometry to a particular integer value. https://postgis.net/docs/ST_SetSRID.html

Geometry output

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

Returns the Well-Known Text (WKT) representation of the geometry. https://postgis.net/docs/ST_AsText.html

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

Returns the GeoJSON representation of the geometry. https://postgis.net/docs/ST_AsGeoJSON.html

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

Returns the Extended Well-Known Text (EWKT) representation of the geometry. https://postgis.net/docs/ST_AsEWKT.html

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

Returns a GeoHash representation of the geometry. https://postgis.net/docs/ST_GeoHash.html

Geometry processing

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_centroid :: SqlExpr (Value (Postgis 'Geometry a)) -> SqlExpr (Value (Postgis 'Geometry a)) Source #

Returns the geometric center (centroid) of a geometry. For polygons this is the center of mass of the surface. https://postgis.net/docs/ST_Centroid.html

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

Returns a geometry that is the buffer of the input geometry at a given distance. The buffer is a polygon expanded (or shrunk if negative) from the input by the distance. https://postgis.net/docs/ST_Buffer.html

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

Returns the convex hull of a geometry. The smallest convex polygon that contains the input geometry. https://postgis.net/docs/ST_ConvexHull.html

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

Returns the bounding box of a geometry as a geometry (polygon or point). A minimal axis-aligned rectangle that fully contains the input. https://postgis.net/docs/ST_Envelope.html

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

Returns a point guaranteed to lie on the surface of the geometry. Unlike st_centroid, the result is always on or inside the geometry. https://postgis.net/docs/ST_PointOnSurface.html

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

Returns the shared portion of two geometries (their intersection). The result geometry contains only the area common to both inputs. https://postgis.net/docs/ST_Intersection.html

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

Returns the part of geometry A that does not intersect geometry B. Computes the geometric difference: A minus the shared area of A and B. https://postgis.net/docs/ST_Difference.html

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

Returns the portions of A and B that do not intersect (symmetric difference). https://postgis.net/docs/ST_SymDifference.html

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

Computes the union of a single geometry (dissolves internal boundaries). https://postgis.net/docs/ST_UnaryUnion.html

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

Splits a geometry by another geometry, returning a collection of geometries. https://postgis.net/docs/ST_Split.html

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

Nodes a set of linestrings, adding intersection points. https://postgis.net/docs/ST_Node.html

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

Creates an areal geometry formed by the constituent linework of the input geometry. https://postgis.net/docs/ST_BuildArea.html

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

Returns a smoothed version of the geometry using Chaikin's algorithm. https://postgis.net/docs/ST_ChaikinSmoothing.html

st_concavehull Source #

Arguments

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

target_percent

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

Returns a concave hull of a geometry with a target percent of area. https://postgis.net/docs/ST_ConcaveHull.html

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

Returns the Delaunay triangulation of a geometry's vertices. https://postgis.net/docs/ST_DelaunayTriangles.html

st_generatepoints Source #

Arguments

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

npoints

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

Generates pseudo-random points within a polygon. https://postgis.net/docs/ST_GeneratePoints.html

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

Merges a collection of linestrings into a single (or fewer) linestrings. https://postgis.net/docs/ST_LineMerge.html

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

Returns an offset line at a given distance from the input line. https://postgis.net/docs/ST_OffsetCurve.html

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

Reduces the precision of coordinates in a geometry to a given grid size. https://postgis.net/docs/ST_ReducePrecision.html

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

Returns a collection of shared paths between two linestring/multilinestring geometries. https://postgis.net/docs/ST_SharedPaths.html

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

Returns a simplified version of a geometry using the Douglas-Peucker algorithm. https://postgis.net/docs/ST_Simplify.html

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

Returns the Voronoi diagram edges for a set of points. https://postgis.net/docs/ST_VoronoiLines.html

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

Returns the Voronoi diagram polygons for a set of points. https://postgis.net/docs/ST_VoronoiPolygons.html

Affine transformations

st_translate Source #

Arguments

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

deltaX

-> SqlExpr (Value Double)

deltaY

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

Translates a geometry by given X and Y offsets. https://postgis.net/docs/ST_Translate.html

st_scale Source #

Arguments

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

scaleX

-> SqlExpr (Value Double)

scaleY

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

Scales a geometry by given X and Y factors. https://postgis.net/docs/ST_Scale.html

st_rotate Source #

Arguments

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

angle in radians

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

Rotates a geometry around the origin by an angle in radians. https://postgis.net/docs/ST_Rotate.html

st_rotatex Source #

Arguments

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

angle in radians

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

Rotates a geometry around the X axis by an angle in radians. https://postgis.net/docs/ST_RotateX.html

st_rotatez Source #

Arguments

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

angle in radians

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

Rotates a geometry around the Z axis by an angle in radians. https://postgis.net/docs/ST_RotateZ.html

Bounding box

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

Returns a bounding box expanded in all directions by a given distance. https://postgis.net/docs/ST_Expand.html

Linear referencing

st_lineinterpolatepoint Source #

Arguments

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

fraction (0.0 to 1.0)

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

Returns a point interpolated along a line at a fractional distance (0.0 to 1.0). https://postgis.net/docs/ST_LineInterpolatePoint.html

st_linelocatepoint Source #

Arguments

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

line

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

point

-> SqlExpr (Value Double) 

Returns a float between 0 and 1 representing the location of the closest point on a line to a given point. https://postgis.net/docs/ST_LineLocatePoint.html

st_linesubstring Source #

Arguments

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

start fraction

-> SqlExpr (Value Double)

end fraction

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

Returns the portion of a line between two fractional locations (0.0 to 1.0). https://postgis.net/docs/ST_LineSubstring.html

Points

point Source #

Arguments

:: forall (spatialType :: SpatialType). Double

x or longitude

-> Double

y or latitude

-> Postgis spatialType PointXY 

point_v Source #

Arguments

:: forall (spatialType :: SpatialType). HasPgType spatialType 
=> Double

x or longitude

-> Double

y or latitude

-> SqlExpr (Value (Postgis spatialType PointXY)) 

st_point Source #

Arguments

:: forall (spatialType :: SpatialType). HasPgType spatialType 
=> SqlExpr (Value Double)

x or longitude

-> SqlExpr (Value Double)

y or latitude

-> SqlExpr (Value (Postgis spatialType PointXY)) 

st_point_xyz Source #

Arguments

:: forall (spatialType :: SpatialType). HasPgType spatialType 
=> SqlExpr (Value Double)

x or longitude

-> SqlExpr (Value Double)

y or latitude

-> SqlExpr (Value Double)

z elevation/altitude

-> SqlExpr (Value (Postgis spatialType PointXYZ)) 

st_point_xyzm Source #

Arguments

:: forall (spatialType :: SpatialType). HasPgType spatialType 
=> SqlExpr (Value Double)

x or longitude

-> SqlExpr (Value Double)

y or latitude

-> SqlExpr (Value Double)

z elevation/altitude

-> SqlExpr (Value Double)

m measure, user defined dimension

-> SqlExpr (Value (Postgis spatialType PointXYZM)) 

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

Methods

pgType :: proxy 'Geography -> Text

HasPgType 'Geometry Source # 
Instance details

Defined in Database.Esqueleto.Postgis.Geometry

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

Orphan instances

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

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

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

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

Methods

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

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

Methods

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

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

Methods

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