I new to GIS.

I have two layers in a PostgreSQL database.
The first layer contains points where events happened in Europe. The second contains a shapefile of Europe.

I have been able to map the points on the map of Europe using QGIS. I would now like to implement Spatial Autocorrealation (Moran i).

I have seen a few demos of this being done using GeoDA but it appears that it only handles a single shapefile.

Can anyone point me in the right direction on how to implement this using QGIS or PostgreSQL or any other free application?


4 Answers 4


Learning by doing is my preferred way. And when it comes to spatial statistics, R is getting seriously powerful tool. So if this is an option browse through some course materials, download the data and try it yourself.

Few starting points covering spatial autocorrelation (SA) (and generally speaking handling spatial stuff in R):

  1. Center for Studies in Demography and Ecology (CSDE) at University of Washington provides materials from Spatial R workshop.

  2. Institute for Quantitative Social Science at Harvard University has materials from the Applied Spatial Statistics in R workshop covering SA.

  3. Geography Department at the University of Colorado offers materials on SA as part of its Introduction to Quantitative Methods course.

Once you get some familiarity with R you can couple it with PostgreSQL using PL/R - R Procedural Language for PostgreSQL, but I cannot comment on it since I'm not knowledgeable on the topic.

Python might be another alternative. PySAL is an actively developed and well documented library that will let you implement all of GeoDa functionality, including SA (and most likely, even more). Python and Postgres are usually good friends so investing some time you could most likely marry those two as well.


Art Lembo has a simple example of a pseudo-Moran's I for PostGIS:

SELECT corr(a.pctwhite, b.pctwhite)
FROM cleveland AS a, cleveland AS b
WHERE st_touches(a.geometry, b.geometry)
AND a."OID" <> b."OID"

The key here is that - as he puts it . . .

[Moran's I] is really nothing more than Pearsons Correlation Coefficient tricked into a spatial context

. . . meaning that a basic contiguity test can produce a credible matrix and evaluation. I've tested this on my own data and found it to produce really-similar results to other Moran's I implementations.


I have no idea how to perform your QGIS/PostgreSQL idea but the following software can calculate measures for autocorrelation

GeoDa can only handle vector, Passage2 and SAGA only raster, PAST only XYZ.txt and SAM (I think) both.


Apologies for the double answer here, but since posting my first suggestion I came across a more-comprehensive toolkit for doing all sorts of analyses like this (including both global and local Moran's I):

Crankshaft, a Python/PostGIS module by Carto.

I've been using it for production analyses similar to your use case for a few months now and it works flawlessly. It looks like CDB_AreasOfInterestGlobal() is the function that you'd want to use.

Not the answer you're looking for? Browse other questions tagged or ask your own question.