hgeos-0.1.0.0: Haskell bindings to GEOS C API

Copyright(C) Richard Cook, 2016
LicenseMIT
Maintainerrcook@rcook.org
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Data.Geolocation.GEOS

Description

A high-level API for interoperating with GEOS C API which includes automatic management of lifetimes of objects such as readers, writers and geometries.

For the low-level FFI bindings, see Data.Geolocation.GEOS.Imports.

Synopsis

Documentation

data Context Source

Represents a GEOS context

data Geometry Source

Represents a GEOS geometry

data Reader Source

Represents a WKT reader

data Writer Source

Represents a WKT writer

intersection :: Geometry -> Geometry -> IO Geometry Source

Returns the Geometry instance representing the intersection of the two supplied Geometry instances:

   withContext $ ctx -> do
       reader <- mkReader ctx
       g0 <- readGeometry reader "POLYGON (( 10 10, 10 20, 20 20, 20 10, 10 10 ))"
       g1 <- readGeometry reader "POLYGON (( 11 11, 11 12, 12 12, 12 11, 11 11 ))"

       g2 <- intersection g0 g1

       -- Use geometry

       putStrLn str

The geometry is associated with the Context and released when the Context is released.

mkReader :: Context -> IO Reader Source

Creates a reader used to deserialize Geometry instances from WKT-format text:

   withContext $ ctx -> do
       reader <- mkReader ctx

       -- Use reader

       return ()

The reader is associated with the Context and released when the Context is released.

mkWriter :: Context -> IO Writer Source

Creates a writer used to serialize Geometry instances to WKT-format text:

   withContext $ ctx -> do
       writer <- mkWriter ctx

       -- Use writer

       return ()

The writer is associated with the Context and released when the Context is released.

readGeometry :: Reader -> String -> IO Geometry Source

Deserializes a Geometry instance from the given String using the supplied Reader:

   withContext $ ctx -> do
       reader <- mkReader ctx
       geometry <- readGeometry read "POLYGON (( 10 10, 10 20, 20 20, 20 10, 10 10 ))"

       -- Use geometry

       return ()

The geometry is associated with the Context and released when the Context is released.

withContext :: (Context -> IO a) -> IO a Source

Creates a GEOS context, passes it to a block and releases the context and all associated objects such as readers, writers and geometries at the end:

   withContext $ ctx -> do

       -- Use context

       return ()

writeGeometry :: Writer -> Geometry -> IO String Source

Serializes a Geometry instance to a String using the supplied Writer:

   withContext $ ctx -> do
       reader <- mkReader ctx
       geometry <- readGeometry read "POLYGON (( 10 10, 10 20, 20 20, 20 10, 10 10 ))"

       writer <- mkWriter ctx
       str <- writeGeometry writer geometry

       -- Use string

       return ()

The geometry is associated with the Context and released when the Context is released.