SpatiaLite GIS in Haskell

October 22, 2019 - Haskell, GIS, Architecture, Monads, mtl, Tooling

This has been instructional: - Wanting to wrap up a SQLite database I stacked ReaderT on top of IO for fun and profit using the mtl library and am approaching application specific DSL nirvana. - I’m not so impressed with Haskell’s tooling infrastructure as I once was, its good, but it ain’t perfect. - Keep it simple is etched into my bench now that I’ve seen an accvio in ghci. Beware the FFI!

The Problem

I have been loading event data (GPS and accelerometer data) from flat files and using geodetics to transform these into x,y coordinates for plotting on a transverse Mercator projection using gloss for the drawing. All good. POC in the bag. So now we are growing up the project.

Three issues arise from the prototype.

  • I need to select sections of the ever growing event log based on time and position (and maybe other criteria) for analysis and display.
  • I’m spending a lot of CPU time turning beautiful strongly typed scientific data into a pair of floats for plotting.
  • There will be multiple concurrent writes to the log and I don’t want to multiplex the IO in the visualisation app, this is meant to be an interactive GUI not middleware.

It makes sense to have other processes do the inserts to a database so that we can form queries based on interesting criteria, e.g. “find me all events contained in this spatial geometry in a given time frame”. This sounds like an application for GIS. It has to embed on aarch64 so SQLite3 was a natural choice for a database.

So the initial task was to provide a GIS on top of SQLite3 and SpatiaLite seemed to fit the bill.

Solution 1 - make spatialite-simple

  • Wrapping sqlite-simple connection.
  • Providing mod_spatialite and schema initialisation

Solution 2 - just do it using what we know works

Well yeah. Sometimes is just too easy to get lost in some work precisely because it’s challenging to make it robust and elegant.