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

Key Error: 4604 #6

Closed nagellette closed 9 years ago

nagellette commented 10 years ago

I get the with the following lines:

An error has occured while executing Python code:

Traceback (most recent call last): File "D:\Documents and Settings\tr32014/.qgis2/python/plugins\contour\contour.py", line 373, in accept self.makeFilledContours() File "D:\Documents and Settings\tr32014/.qgis2/python/plugins\contour\contour.py", line 584, in makeFilledContours polygons = self.computeFilledContours( asLayers ) File "D:\Documents and Settings\tr32014/.qgis2/python/plugins\contour\contour.py", line 651, in computeFilledContours self._computeFilledContoursForLevel(levels,extend,polygons) File "D:\Documents and Settings\tr32014/.qgis2/python/plugins\contour\contour.py", line 658, in _computeFilledContoursForLevel cs = plt.tricontourf(x, y, z, levels, extend=extend) File "C:\PROGRA~1\QGISDU~1\apps\Python27\lib\site-packages\matplotlib\pyplot.py", line 3108, in tricontourf ret = ax.tricontourf(_args, _kwargs) File "C:\PROGRA~1\QGISDU~1\apps\Python27\lib\site-packages\matplotlib\axes.py", line 8926, in tricontourf return mtri.tricontourf(self, _args, _kwargs) File "C:\PROGRA~1\QGISDU~1\apps\Python27\lib\site-packages\matplotlib\tri\tricontour.py", line 287, in tricontourf return TriContourSet(ax, _args, _kwargs) File "C:\PROGRA~1\QGISDU~1\apps\Python27\lib\site-packages\matplotlib\tri\tricontour.py", line 36, in init ContourSet.init(self, ax, _args, _kwargs) File "C:\PROGRA~1\QGISDU~1\apps\Python27\lib\site-packages\matplotlib\contour.py", line 780, in init self._process_args(_args, _kwargs) File "C:\PROGRA~1\QGISDU~1\apps\Python27\lib\site-packages\matplotlib\tri\tricontour.py", line 47, in _process_args tri, z = self._contour_args(args, kwargs) File "C:\PROGRA~1\QGISDU~1\apps\Python27\lib\site-packages\matplotlib\tri\tricontour.py", line 82, in _contour_args Triangulation.get_from_args_and_kwargs(_args, _kwargs) File "C:\PROGRA~1\QGISDU~1\apps\Python27\lib\site-packages\matplotlib\tri\triangulation.py", line 172, in get_from_args_and_kwargs triangulation = Triangulation(x, y, triangles, mask) File "C:\PROGRA~1\QGISDU~1\apps\Python27\lib\site-packages\matplotlib\tri\triangulation.py", line 72, in init dt = delaunay.Triangulation(self.x, self.y) File "C:\PROGRA~1\QGISDU~1\apps\Python27\lib\site-packages\matplotlib\delaunay\triangulate.py", line 123, in init self.hull = self._compute_convex_hull() File "C:\PROGRA~1\QGISDU~1\apps\Python27\lib\site-packages\matplotlib\delaunay\triangulate.py", line 158, in _compute_convex_hull hull.append(edges.pop(hull[-1])) KeyError: 4604

Python version: 2.7.4 (default, Apr 6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)]

QGIS version: 2.0.1-Dufour Dufour, ebebdf3

Python path: ['C:/PROGRA~1/QGISDU~1/apps/qgis/./python/plugins\processing', 'C:/PROGRA~1/QGISDU~1/apps/qgis/./python', 'D:\Documents and Settings\tr32014/.qgis2/python', 'D:\Documents and Settings\tr32014/.qgis2/python/plugins', 'C:/PROGRA~1/QGISDU~1/apps/qgis/./python/plugins', 'C:\PROGRA~1\QGISDU~1\bin\python27.zip', 'C:\PROGRA~1\QGISDU~1\apps\Python27\DLLs', 'C:\PROGRA~1\QGISDU~1\apps\Python27\lib', 'C:\PROGRA~1\QGISDU~1\apps\Python27\lib\plat-win', 'C:\PROGRA~1\QGISDU~1\apps\Python27\lib\lib-tk', 'C:\PROGRA~1\QGISDU~1\bin', 'C:\PROGRA~1\QGISDU~1\apps\Python27', 'C:\PROGRA~1\QGISDU~1\apps\Python27\lib\site-packages', 'C:\PROGRA~1\QGISDU~1\apps\Python27\lib\site-packages\PIL', 'C:\PROGRA~1\QGISDU~1\apps\Python27\lib\site-packages\win32', 'C:\PROGRA~1\QGISDU~1\apps\Python27\lib\site-packages\win32\lib', 'C:\PROGRA~1\QGISDU~1\apps\Python27\lib\site-packages\Pythonwin', 'C:\PROGRA~1\QGISDU~1\apps\Python27\lib\site-packages\wx-2.8-msw-unicode', 'D:\Documents and Settings\tr32014.qgis2\python\plugins\mmqgis/forms', 'C:\PROGRA~1\QGISDU~1\apps\qgis\python\plugins\fTools\tools']

ccrook commented 10 years ago

Hi

Are you able to provide a data set that demonstrates this problem that I can use to help debug it?

Thanks Chris

nagellette commented 10 years ago

Hi Chris,

Below is the one of the files that I've been working on. I was trying to plot contours according to cost field. After opening the ticket I removed some of the points, only the error number changed.

https://www.dropbox.com/s/z2syweez73alsca/contour_sample.tar.gz

Thanks, Necip

ccrook commented 10 years ago

Hi Necip

Thanks for the test data. I have been able to replicate your problem.

This does clearly come from the underlying python matplotlib library, so it may not be easy to deal with. The data set is quite complex for contouring, it looks like problem occurs in the routine creating the delauney triangulation on which the contouring is based. (However using the vector/geometry tools/delauney triangulation does work, so it should be possible).

So I may not have a quick answer to this unfortunately .,..

Cheers Chris

nagellette commented 10 years ago

Hi Chris,

I came across with such problem before with the large set of data but I did not have time to submit a ticket. As you sad, I tried to triangulate myself with another tool in qgis (I dont remember what it was) and it worked too. I am really looking forward for your solutions about this in advance, It is a very nice tool and one and only for the point to contour generation. I can also try to contribute for solution but I dont know where to start.

Necip.

erwanC commented 9 years ago

Hello there,

Tanks for this useful contour plugin.

I think I'm facing the same problem here in QGIS while trying to define the contour (line or polygon) :

When I try the delauney triangulation as you suggest, its take a long very time, and eventually success.

If i'm correct, the contour plugin use matplotlib v1.3. I saw that v1.4 is out, do you plan an update of Contour? I'm not familiar with Python and can't easily try that myself.

Thanks for your help, Erwan

Note : I use Qgis 2.4 on Windows

ccrook commented 9 years ago

Hello Erwan

Firstly, the version of matplotlib. The answer is that the contour plugin uses whatever version of matplotlib is installed on your system. I'm not sure how you installed QGIS on windows - maybe OSGEO4W - but that installation will probably have provided the version of matplotlib that you are using. You could contact the packagers of your installation to request an upgrade to the newer version.

I doubt that upgrading matplotlib will make much difference to the contouring though.

It may be that your data set is too complex for the plugin. It can certainly handle large data sets of regular data, but randomly or irregularly located data can cause problems as the triangulation algorithm can become very inefficient or fail altogether. So you may need to think about your data set and whether you can better organise it for contouring. That is what the point thinning attempts to do, albeit in a very simplistic way.

erwanC commented 9 years ago

Hi Chris,

Thanks for that answer. So know that I understand a little bit more, Do you think there a solution to improve the triangulation algorithm? I mean : my data set come from a sofware that easily compute contour but is unable to produce good analysis tools such as QGIS... Thinking of that : why the delaunay algorithm fail in coutour plugin while the one in Qgis can complete his task?

My data set have to represent complicated shape and behaviour, but i'll try to interpol it on a regular grid.

Erwan

ccrook commented 9 years ago

There isn't an easy solution for the contour plugin without rewriting it completely. The QGIS delauney triangulation code is completely different from that used in matplotlib, so will fail under different conditions (there are many different ways to implement delauney triangulation, and at various points will be tested against different thresholds to check for invalid triangulation).

If it is easy to make your data set available I'd be interested to have a look and see if I can see why it is failing (I just need the x,y coordinates of the points being contoured, and optionally the data value).

erwanC commented 9 years ago

Hi Chris,

I'll send u a sample at ccrook@linz.govt.nz if ok for you (a Shape of 6Mo). Let me know about your conclusions !

Thanks for help, Erwan

ccrook commented 9 years ago

Closing this issue. Possibly addressed by point thinning option in plugin?

erwanC commented 9 years ago

Indeed, but it's decrease the accuracy badly... For now, i use another software to export the contour.

thx.

ccrook commented 9 years ago

Hi Erwan

The point thinning certainly can decrease the accuracy, either if the radius is set too large, or if the data have points very close together (within the thinning radius) with values to be contoured that are very different. In this case the contouring algorithm may certainly not give results that are what you want to see. My point thinning algorithm is certainly a bit simplistic - it discards some values so if they carry significant information then you will lose accuracy as you say.

Glad you've found another way to do this.