For the past few months, I’ve been working on a Ruby/Rails gem called Spatial Stats. The goal of this project is to bring an optimized spatial statistics library to the Ruby community and I’m happy to say that the gem is ready for use.
📸: SK53 OSM
While it is not fully featured, the package is performant and includes a lot of commonly used measurements for both distance-based and contiguous geometries. Additionally, it includes helpful utilities and ActiveRecord
extensions to increase useability.
Feature List
- Global Measurements
Moran
’s IBivariateMoran
’s I
- Local Measurements
Moran
’s IBivariateMoran
’s IGeary
’s CMultivariateGeary
’s CGetisOrd
G and G*
- Utilities
WeightsMatrix
class built from a dictionary of keys (DOK)CSRMatrix
, a slim implementation of a compressed sparse row matrix (aka Yale Matrix)SpatialLag
, computations for different weight layouts
- ActiveRecord Extensions
Rook
weight calculation for contiguous geometriesQueen
weight calculation for contiguous geometriesInverseDistanceWeight
weight calculations for distance-based geometriesKNN
weight calculations for distance-based geometries
- Extensions
standardize
method on enumerable classesrow_standardize
andwindow
methods onNumo::NArray
Path Forward
I’m happy that the project has come together nicely so far, but there is definitely still work that needs to be done on it. A variety of improvements could be made from adding features, adding utilities to increase usability, splitting it up into different gems to reduce dependencies, and other smaller things. I’m going to list some of the things that come to mind below, but I intend on making this a living document that will be updated as the gem progresses. If you want to make a feature suggestion or contribution feel free to open up an issue/pull request on the Github page.
- Global Measurements
Geary
’s CGetisOrd
- Local Measurements
Join Count
- Utilities
- Add support for .gal/.swm file imports
- Add support for Rate variables
- Add support for Bayes smoothing
- Add an additional gem
spatial_stats-geojson
that will depend onRGeo
, but can produce weights matrices from geojson inputs.
- ActiveRecord Extensions
- Break queries into a seperate
spatial_stats-activerecord
gem that will contain the queries to interface with PostGIS. Will remove core dependency onRails
.
- Break queries into a seperate
- General
- Add point pattern analysis module
- Add regression module