Fix some bugs in the new terrain variance code. Bugs in the handling
of sparse data, and getting -ve numbers into the database.