rethinkdb-2.1.0.0: A driver for RethinkDB 2.0

Safe HaskellNone
LanguageHaskell98

Database.RethinkDB.Geospatial

Synopsis

Documentation

Get the doctests ready

>>> :set -XOverloadedStrings
>>> :load Database.RethinkDB.NoClash
>>> import qualified Database.RethinkDB as R
>>> import Control.Exception
>>> let try' x = (try x `asTypeOf` return (Left (undefined :: SomeException))) >> return ()
>>> h <- fmap (use "doctests") $ connect "localhost" 28015 def
>>> try' $ run' h $ dbCreate "doctests"
>>> try' $ run' h $ tableCreate "places"
>>> try' $ run' h $ table "places" # insert ["location" := point (-120) 60]
>>> try' $ run' h $ table "places" # insert ["location" := point (-122) 43]
>>> try' $ run' h $ table "places" # insert ["location" := point (-91) 44, "area" := polygon [[-124,30],[-113,54],[-80,44]]]
>>> try' $ run' h $ table "places" # ex indexCreate ["geo":=True] "location" (!"location")
>>> try' $ run' h $ table "places" # ex indexCreate ["geo":=True] "geo" (!"area")

fill :: Expr line => line -> ReQL Source

Convert a line object into a polygon

>>> run' h $ fill $ line [[-122,37], [-120,39], [-121,38]]
Polygon<[[-122,37],[-120,39],[-121,38],[-122,37]]>

geoJSON :: Expr geojson => geojson -> ReQL Source

Convert a GeoJSON object into a RethinkDB geometry object

>>> run' h $ geoJSON ["type" := "Point", "coordinates" := [-45,80]]
Point<-45,80>

toGeoJSON :: Expr geo => geo -> ReQL Source

Convert a RethinkDB geometry object into a GeoJSON object

>>> run' h $ toGeoJSON $ point (-122.423246) 37.779388
{"coordinates":[-122.423246,37.779388],"type":"Point"}

getIntersecting :: (Expr geo, Expr table) => geo -> Index -> table -> ReQL Source

Search a geospatial index for intersecting objects

>>> run' h $ table "places" # getIntersecting (point (-122) 37) (Index "geo")
[]

getNearest :: (Expr point, Expr table) => point -> Index -> table -> ReQL Source

Query a geospatial index for the nearest matches

>>> run' h $ table "places" # getNearest (point (-122) 37) (Index "location")
[]
>>> run' h $ table "places" # ex getNearest [maxResults 5, maxDist 10, unit Kilometer] (point (-122) 37) (Index "location")
[]

includes :: (Expr area, Expr geo) => geo -> area -> ReQL Source

Test whether a geometry object includes another

>>> run' h $ circle (point (-122) 37) 5000 # includes (point (-120) 48)
false

intersects :: (Expr a, Expr b) => a -> b -> ReQL Source

Test if two geometry objects intersects

>>> run' h $ intersects (line [[-122,37],[-120,48]]) (line [[-120,49],[-122,48]])
false

line :: Expr points => points -> ReQL Source

Create a line object

>>> run' h $ line [[-73,45],[-122,37]]
Line<[-73,45],[-122,37]>

point :: (Expr longitude, Expr latitude) => longitude -> latitude -> ReQL Source

Create a point objects

>>> run' h $ point (-73) 40
Point<-73,40>

polygon :: Expr points => points -> ReQL Source

Create a polygon object

>>> run' h $ polygon [[-73,45],[-122,37],[-73,40]]
Polygon<[[-73,45],[-122,37],[-73,40],[-73,45]]>

polygonSub :: (Expr polygon, Expr hole) => hole -> polygon -> ReQL Source

Punch a hole in a polygon

>>> run' h $ (polygon [[-73,45],[-122,37],[-73,40]]) # polygonSub (polygon [[-73.2,40.1],[-73.2,40.2],[-73.3,40.1]])
Polygon<[[-73,45],[-122,37],[-73,40],[-73,45]],[[-73.2,40.1],[-73.2,40.2],[-73.3,40.1],[-73.2,40.1]]>

circle :: (Expr point, Expr radius) => point -> radius -> ReQL Source

Create a polygon approximating a circle

>>> run' h $ ex circle [numVertices 6, unit Kilometer] (point (-73) 40) 100
Polygon<[[-73,39.099310036015424],[-74.00751390838496,39.54527799206398],[-74.02083610406069,40.445812561599965],[-73,40.900549591978255],[-71.97916389593931,40.445812561599965],[-71.99248609161504,39.54527799206398],[-73,39.099310036015424]]>

distance :: (Expr a, Expr b) => a -> b -> ReQL Source

Distance between a point and another geometry object

run' h $ distance (point (-73) 40) (point (-122) 37)
  1. 467303546 > run' h $ ex distance [unit Mile] (point (-73) 40) (point (-122) 37)
  2. 5460282596796

maxResults :: ReQL -> Attribute a Source

Optional argument for getNearest

maxDist :: ReQL -> Attribute a Source

Optional argument for getNearest

unit :: Unit -> Attribute a Source

Optional argument for getNearest, circle and distance

numVertices :: ReQL -> Attribute a Source

Optional argument for circle

data Unit Source

Instances