Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've looked through the PostGIS raster documentation, but can't find an indication of how to apply a convolution filter to raster data. Does this capability even exist (yet?) There only appears to be preset operators such as min, max and std deviation.

share|improve this question
What about…? This is more general than a convolution (with both good and bad implications: the good is that you can in principle do lots of neighborhood analyses; the bad is that (a) the convolution kernel apparently needs to be hard-coded and (b) actual convolutions can be extremely slow because they won't exploit FFT methods). – whuber Mar 26 '12 at 18:49
heh. And it has great parameter names! "onerastngbuserfunc" makes my eyes roll backwards. @whuber Feel free to make this an answer and I'll add to your heap; ST_MapAlgebraFctNgb isn't entirely what I was expecting but you're right it is a very flexible method. – WolfOdrade Mar 26 '12 at 20:09
up vote 1 down vote accepted

A discussion carried out in comments to the question has established that indeed PostGIS can perform convolutions by means of the ST_MapAlgebraFctNgb procedure. This provides a way to apply a user-supplied function systematically to all neighborhoods within a raster. Any function that is a weighted linear combination of the inputs (with constant weights across the raster) is a convolution, by definition.

This approach is remarkably flexible: it should be able to accommodate any kind of neighborhood statistic (mean, median, range, variance, variety, etc.) in addition to actual convolutions. The flip side is that it can be slow: there will be one neighborhood for each grid cell, so the processing time will usually be proportional to the grid size times the neighborhood size. For medium to large neighborhoods that can be onerous. Methods based on the Fast Fourier Transform can compute any convolution you want and take effort proportional to the grid size times its logarithm. For medium to large neighborhoods (typically the crossover is around 5 by 5 to 10 by 10 in size), that can be a big difference. In such cases one would seek alternative software solutions.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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