Question: I'm looking for some advice on how I can simplify this very detailed shapefile to ultimately be used for the web (as topojson) as a interactive heatmap. It was originally created from a raster file (geotiff - <http://ecotope.org/anthromes/v2/data/>). I believe it's going to take a little more massaging before using a Douglas-Peucker or Visvalingam algorithm. *I believe* the best way to achieve this would be to *intelligently* merge features based on the attribute value each contains. I'm just not sure the best way to achieve this. I have a sneaking suspicion that "dissolve" is what I need, but QGIS just freezes anytime I try that.

I'm working with command-line gdal utils and QGIS.

I have attached some screenshots below to give you a better idea of what I'm dealing with.

![enter image description here](https://i.stack.imgur.com/d6LNN.png)

![enter image description here](https://i.stack.imgur.com/9ulXh.png)

![enter image description here](https://i.stack.imgur.com/XDoLL.png)

Answer: 
you can convert your aspects into the sine and cosine, compute the mean of the sine's and the mean of the cosine's, then turn it back to aspect using atan2(sine,cosine). For more details, see [Wikipedia](http://en.wikipedia.org/wiki/Directional_statistics)
Most textbooks suggest using atan2(Sigma(sin(x)), Sigma(cos(x))), however this is not always the right thing to do. For example, the average of 0, 0 and 90 degrees is atan( (sin(0)+sin(0)+sin(90)) / (cos(0)+cos(0)+cos(90)) ) = atan(1/2)= 26.56 deg, and not 30 deg as one may expect.

Take a look at my article on CodeProject "[*Circular Values Math and Statistics with C++11*](http://www.codeproject.com/Articles/190833/Circular-Values-Math-and-Statistics-with-Cplusplus)", especially section 26 - *Averaging n circular values*, and section 29 - *Circular parameter estimation based on noisy measurements*, were I suggest a method that is consistent with the general definition on an average, and also more accurate when the data has a wrapped normal distribution.

An equivalent method is suggested in Edwin Olson's paper "[*On computing the average orientation of vectors and lines*](http://april.eecs.umich.edu/pdfs/olson2011orientation.pdf)" (Algorithm 1).