ccrook / QGIS-Contour-Plugin

Contour plugin for QGIS - uses python matplotlib to generate contours of data on vector point data.
43 stars 13 forks source link

Filled Contour Polygons could fail for certain data value maximum #41

Closed bebbit closed 1 year ago

bebbit commented 4 years ago

When calling the contour plugin from the qgis toolbox there are issues trying to create filled polygons for certain attributes in a shapefile. The created Output will have holes where no class/polygon is created. grafik

Certain classes couldn't be generated and the log shows that Features could not get written to the output. grafik

It happens no matter how many classes are chosen or what method for the contour level calculation is chosen. Also it has no effect to change whether contours are extended up or below max and min.

It might also not be related to amount of points since it does work for certain attributes while it does not work for others in the same shapefile. It also does not matter if the attributes data type is real or integer.

It does work though if instead of filled contour polygons only contour lines are created.

If the creation fails as mentioned above the workaround is to set the MaxContourValue by hand. If you do set the value to the data maximum it still fails, but if you set it slightly above or below the data maximum then all classes are generated (of course classes are then slightly off maximum as well).

My test data set has a data maximum of 6.5 which made the algorithm to fail when MinimumContourValue and MaximumContourValue are omitted so that min and max are calculated from the attribute. When manually set MaxContourValue to 6.5 it also fails (it also fails for 6.7/6.9). Setting MaxContourValue to 6.4/6.6/6.8 or 6.500001 made the algorithm to work as expected. Interestingly, directly changing the data value of one of the data points to a specific value (that works if chosen for MaxContourValue for example 6.6) does seem to work without the need to adjust MaxContourValue manually to be slighty off the data maximum. However, changing one former maximum data point value from 6.5 to 6.6 makes the algorithm to work but changing a lot of the points to 6.6 made the algorithm to fail again. I suspect that not one value leads to problems here but the mixture of values and that it might be related to some problems during classification or min/max/range calculation maybe due to some rounding or trimming of values.

Since I'm not able to investigate further into the plugins code I can only provide my test data set

I've tested on two different Win10 machines with QGIS 3.6.2-Noosa, 3.10.2-A Coruña and 3.10.3-A Coruña with the recent version of the plugin. test_data_set.zip

ccrook commented 4 years ago

Hi @bebbit Thanks for you very detailed reporting and for providing the test data set. The issue is not new, and comes from the matplotlib library that the contour module is using to generated the contours, which in some circumstances can lead to invalid polygons being constructed where the polygons intersect the boundary of the countour data set. This generally happens when it is using a triangulation to do contouring - generally it tries to use the data as a grid by choice is the issue doesn't usually happen with gridded data. I'll have a look at this data set to see if it sheds any more light on the issue, or on a work around.

ccrook commented 1 year ago

Duplicate of #38