Copyright | (c) Joe Canero 2017 |
---|---|
License | BSD3 |
Maintainer | jmc41493@gmail.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
This module provides support for reading, writing, and updating an mbtiles database, as well as reading metadata from the database.
There is also support for creating a pool of connections to an mbtiles database and streaming tiles.
See the associated README.md for basic usage examples.
- data MbtilesT m a
- type MbtilesIO a = MbtilesT IO a
- type MbtilesMeta = HashMap Text Text
- data MBTilesError
- newtype Z = Z Int
- newtype X = X Int
- newtype Y = Y Int
- data Tile a = Tile {}
- class ToTile a where
- class FromTile a where
- runMbtilesT :: MonadIO m => FilePath -> MbtilesT m a -> m (Either MBTilesError a)
- runMbtiles :: FilePath -> MbtilesIO a -> IO (Either MBTilesError a)
- type MbtilesPool = Pool MbtilesData
- getMbtilesPool :: MonadIO m => FilePath -> m (Either MBTilesError MbtilesPool)
- runMbtilesPoolT :: MonadBaseControl IO m => MbtilesPool -> MbtilesT m a -> m a
- getTile :: (MonadIO m, FromTile a) => Z -> X -> Y -> MbtilesT m (Maybe a)
- writeTile :: (MonadIO m, ToTile a) => Z -> X -> Y -> a -> MbtilesT m ()
- writeTiles :: (MonadIO m, ToTile a) => [(Z, X, Y, a)] -> MbtilesT m ()
- updateTile :: (MonadIO m, ToTile a) => Z -> X -> Y -> a -> MbtilesT m ()
- updateTiles :: (MonadIO m, ToTile a) => [(Z, X, Y, a)] -> MbtilesT m ()
- getMetadata :: MonadIO m => MbtilesT m MbtilesMeta
- getName :: MonadIO m => MbtilesT m Text
- getType :: MonadIO m => MbtilesT m Text
- getVersion :: MonadIO m => MbtilesT m Text
- getDescription :: MonadIO m => MbtilesT m Text
- getFormat :: MonadIO m => MbtilesT m Text
- data TileStream
- startTileStream :: MonadIO m => MbtilesT m TileStream
- endTileStream :: MonadIO m => TileStream -> MbtilesT m ()
- nextTile :: (MonadIO m, FromTile a) => TileStream -> MbtilesT m (Maybe (Tile a))
Types
MbtilesT monad that will run actions on an MBTiles file.
type MbtilesMeta = HashMap Text Text Source #
MBTiles files contain metadata in one of their tables. This is a type alias for a mapping between the metadata key and the metadata value.
data MBTilesError Source #
Data type representing various errors that could occur when opening and validating an MBTiles file.
DoesNotExist | The MBTiles file does not exist. |
InvalidSchema | The MBTiles schema is invalid according to the spec. |
InvalidMetadata | The MBTiles |
InvalidTiles | The MBTiles |
Data type that represents an entire row from an MBTiles database.
Typeclasses
Typeclass representing data types that can be turned into a lazy ByteString and stored as tile data.
toTile :: a -> ByteString Source #
class FromTile a where Source #
Typeclass representing data types into which raw tile data can be converted.
fromTile :: ByteString -> a Source #
The MbtilesT monad transformer
runMbtilesT :: MonadIO m => FilePath -> MbtilesT m a -> m (Either MBTilesError a) Source #
Given a path to an MBTiles file, run the MbtilesT
action.
This will open a connection to the MBTiles file, run the action,
and then close the connection.
Some validation will be performed first. Of course, we will check if the
MBTiles file actually exists. If it does, we need to validate its schema according
to the MBTiles spec.
runMbtiles :: FilePath -> MbtilesIO a -> IO (Either MBTilesError a) Source #
Specialized version of runMbtilesT
to run in the IO monad.
Pooling
type MbtilesPool = Pool MbtilesData Source #
A pool of connections to an MBTiles database.
getMbtilesPool :: MonadIO m => FilePath -> m (Either MBTilesError MbtilesPool) Source #
Given a path to an MBTiles file, create a connection pool
to an MBTiles database. This will perform the same validation as runMbtilesT
.
runMbtilesPoolT :: MonadBaseControl IO m => MbtilesPool -> MbtilesT m a -> m a Source #
Given access to an MbtilesPool
, run an action against that pool.
Mbtiles read/write functionality
Mbtiles metadata functionality
getMetadata :: MonadIO m => MbtilesT m MbtilesMeta Source #
Returns the MbtilesMeta
that was found in the MBTiles file.
This returns all of the currently available metadata for the MBTiles database.
getName :: MonadIO m => MbtilesT m Text Source #
Helper function for getting the specified name of the MBTiles from metadata.
getType :: MonadIO m => MbtilesT m Text Source #
Helper function for getting the type of the MBTiles from metadata.
getVersion :: MonadIO m => MbtilesT m Text Source #
Helper function for getting the version of the MBTiles from metadata.
getDescription :: MonadIO m => MbtilesT m Text Source #
Helper function for getting the description of the MBTiles from metadata.
getFormat :: MonadIO m => MbtilesT m Text Source #
Helper function for getting the format of the MBTiles from metadata.
Streaming tiles
data TileStream Source #
A TileStream
data type contains information about how to
stream tiles from the MBTiles database and is used in the same
manner as an SQLite prepared statement.
startTileStream :: MonadIO m => MbtilesT m TileStream Source #
Create a TileStream
data type that will be used to stream tiles
from the MBTiles database. When streaming is complete, you must
call endTileStream
to clean up the TileStream
resource. Tiles are streamed
from the database in an ordered fashion, where they are sorted by zoom level,
then tile column, then tile row, in ascending order.
endTileStream :: MonadIO m => TileStream -> MbtilesT m () Source #
Close a given TileStream
when streaming is complete.