module Data.Geolocation.GEOS.Trans
( areaM
, createCoordSeqM
, createLinearRingM
, createPolygonM
, envelopeM
, geomTypeIdM
, getCoordSeqM
, getExteriorRingM
, getGeometryM
, getNumGeometriesM
, getOrdinateM
, getSizeM
, getXM
, getYM
, getZM
, intersectionM
, isEmptyM
, mkReaderM
, mkWriterM
, readGeometryM
, runGEOS
, runGEOSEither
, setOrdinateM
, setXM
, setYM
, setZM
, writeGeometryM
) where
import Control.Monad.Trans.Maybe
import Data.Geolocation.GEOS
unaryGEOSFunc :: (a -> IO (Maybe b)) -> a -> MaybeT IO b
unaryGEOSFunc = (MaybeT .)
binaryGEOSFunc :: (a -> b -> IO (Maybe c)) -> a -> b -> MaybeT IO c
binaryGEOSFunc f a b = MaybeT (f a b)
ternaryGEOSFunc :: (a -> b -> c -> IO (Maybe d)) -> a -> b -> c -> MaybeT IO d
ternaryGEOSFunc f a b c = MaybeT (f a b c)
quaternaryGEOSFunc :: (a -> b -> c -> d -> IO (Maybe e)) -> a -> b -> c -> d -> MaybeT IO e
quaternaryGEOSFunc f a b c d = MaybeT (f a b c d)
areaM :: Geometry -> MaybeT IO Double
areaM = unaryGEOSFunc area
createCoordSeqM :: Context -> Word -> Word -> MaybeT IO CoordinateSequence
createCoordSeqM = ternaryGEOSFunc createCoordSeq
createLinearRingM :: CoordinateSequence -> MaybeT IO Geometry
createLinearRingM = unaryGEOSFunc createLinearRing
createPolygonM :: Geometry -> [Geometry] -> MaybeT IO Geometry
createPolygonM = binaryGEOSFunc createPolygon
envelopeM :: Geometry -> MaybeT IO Geometry
envelopeM = unaryGEOSFunc envelope
geomTypeIdM :: Geometry -> MaybeT IO GeometryType
geomTypeIdM = unaryGEOSFunc geomTypeId
getCoordSeqM :: Geometry -> MaybeT IO CoordinateSequence
getCoordSeqM = unaryGEOSFunc getCoordSeq
getExteriorRingM :: Geometry -> MaybeT IO Geometry
getExteriorRingM = unaryGEOSFunc getExteriorRing
getGeometryM :: Geometry -> Int -> MaybeT IO Geometry
getGeometryM = binaryGEOSFunc getGeometry
getNumGeometriesM :: Geometry -> MaybeT IO Int
getNumGeometriesM = unaryGEOSFunc getNumGeometries
getOrdinateM :: CoordinateSequence -> Word -> Word -> MaybeT IO Double
getOrdinateM = ternaryGEOSFunc getOrdinate
getSizeM :: CoordinateSequence -> MaybeT IO Word
getSizeM = unaryGEOSFunc getSize
getXM :: CoordinateSequence -> Word -> MaybeT IO Double
getXM = binaryGEOSFunc getX
getYM :: CoordinateSequence -> Word -> MaybeT IO Double
getYM = binaryGEOSFunc getY
getZM :: CoordinateSequence -> Word -> MaybeT IO Double
getZM = binaryGEOSFunc getZ
intersectionM :: Geometry -> Geometry -> MaybeT IO Geometry
intersectionM = binaryGEOSFunc intersection
isEmptyM :: Geometry -> MaybeT IO Bool
isEmptyM = unaryGEOSFunc isEmpty
mkReaderM :: Context -> MaybeT IO Reader
mkReaderM = unaryGEOSFunc mkReader
mkWriterM :: Context -> MaybeT IO Writer
mkWriterM = unaryGEOSFunc mkWriter
readGeometryM :: Reader -> String -> MaybeT IO Geometry
readGeometryM = binaryGEOSFunc readGeometry
runGEOS :: (Context -> MaybeT IO a) -> IO (Maybe a)
runGEOS = withGEOS . (runMaybeT .)
runGEOSEither :: (Context -> MaybeT IO a) -> IO (Either String a)
runGEOSEither action = do
result <- runGEOS action
case result of
Nothing -> Left <$> getErrorMessage
Just r -> return $ Right r
setOrdinateM = quaternaryGEOSFunc setOrdinate
setXM = ternaryGEOSFunc setX
setYM = ternaryGEOSFunc setY
setZM = ternaryGEOSFunc setZ
writeGeometryM :: Writer -> Geometry -> MaybeT IO String
writeGeometryM = binaryGEOSFunc writeGeometry