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

Invalid value for ContourMethod #37

Closed Saijin-Naib closed 2 years ago

Saijin-Naib commented 4 years ago

Problem Description The Generate Contours plugin fails with a value error, seemingly related to ContourMethod.

QGIS Version Information

QGIS version 3.10.2-A Coruña QGIS code revision d4cd3cfe5a
Compiled against Qt 5.11.2 Running against Qt 5.11.2
Compiled against GDAL/OGR 3.0.3 Running against GDAL/OGR 3.0.3
Compiled against GEOS 3.8.0-CAPI-1.13.1 Running against GEOS 3.8.0-CAPI-1.13.1
Compiled against SQLite 3.29.0 Running against SQLite 3.29.0
PostgreSQL Client Version 11.5 SpatiaLite Version 4.3.0
QWT Version 6.1.3 QScintilla2 Version 2.10.8
Compiled against PROJ 6.3.0 Running against PROJ Rel. 6.3.0, January 1st, 2020
OS Version Windows 10 (10.0)
Active python plugins CalculateGeometry; guided_offline_editing; MemoryLayerSaver; networks; openlayers_plugin; ORStools; PeliasGeocoding; PluginLoadTimes; realcentroid; snail; SpreadsheetLayers; zoom_level; db_manager; MetaSearch; processing; contour

Generate Controus - Log

Algorithm 'Generate Contours' starting…
Input parameters:
{ 'ContourInterval' : None, 'ContourLevels' : '', 'ContourMethod' : None, 'ContourType' : 0, 'DuplicatePointTolerance' : None, 'ExtendOption' : None, 'InputField' : '\"ELEVATION\"', 'InputLayer' : 'C:\\Users\\username\\Desktop\\survey_points.gpkg|layername=Simplified', 'LabelDecimalPlaces' : None, 'LabelTrimZeros' : False, 'LabelUnits' : '', 'MaxContourValue' : None, 'MinContourValue' : None, 'NContour' : None, 'OutputLayer' : 'TEMPORARY_OUTPUT' }

Traceback (most recent call last):
File "C:/Users/username/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\contour\ContourGeneratorAlgorithm.py", line 116, in _getEnumValue
id=values[int(id)]
ValueError: invalid literal for int() with base 10: ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/username/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\contour\ContourGeneratorAlgorithm.py", line 277, in processAlgorithm
method = self._getEnumValue( parameters, self.PrmContourMethod, context )
File "C:/Users/username/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\contour\ContourGeneratorAlgorithm.py", line 119, in _getEnumValue
tr('Invalid value {0} for {1}').format(id,name))
contour.ContourGeneratorAlgorithm.ContourGeneratorAlgorithmError: Invalid value for ContourMethod

Execution failed after 0.01 seconds

Loading resulting layers
Algorithm 'Generate Contours' finished

Processing History - Generate Contours Entry processing.run("contourplugin:generatecontours", {'InputLayer':'C:\\Users\\username\\Desktop\\survey_points.gpkg|layername=Simplified','InputField':'\"ELEVATION\"','DuplicatePointTolerance':None,'ContourType':0,'ExtendOption':None,'ContourMethod':None,'NContour':None,'MinContourValue':None,'MaxContourValue':None,'ContourInterval':None,'ContourLevels':'','LabelDecimalPlaces':None,'LabelTrimZeros':False,'LabelUnits':'','OutputLayer':'TEMPORARY_OUTPUT'})

Sample Data survey_points.zip

ccrook commented 4 years ago

Hi @Saijin-Naib Thanks for this excellent issue reporting :-) I'll hopefully look at it over the next couple of days. Looks like it is trying to interpret an empty string as an integer. It looks like the issue is coming from the input parameters, none of which are set. In particular Invalid value for ContourMethod is None, which doesn't look like a valid option. However main thing is that it hasn't handled the error very cleanly :-(

Saijin-Naib commented 4 years ago

@ccrook , Not a problem.

For the input parameters, I purposefully unset all of them so that I could test them against changing the Contour Method value by value. I'll include a similar test below, where all tool defaults are left as-is except the Contour Method, which is changed value by value.

Contour Lines image processing.run("contourplugin:generatecontours", {'InputLayer':'file:///Q:/User/username/Washington_points.txt?type=csv&useHeader=No&trimFields=Yes&detectTypes=yes&xField=field_2&yField=field_3&zField=field_4&crs=EPSG:6541&spatialIndex=yes&subsetIndex=yes&watchFile=yes','InputField':'\"field_4\"','DuplicatePointTolerance':0,'ContourType':0,'ExtendOption':None,'ContourMethod':None,'NContour':20,'MinContourValue':None,'MaxContourValue':None,'ContourInterval':1,'ContourLevels':'','LabelDecimalPlaces':-1,'LabelTrimZeros':False,'LabelUnits':'','OutputLayer':'TEMPORARY_OUTPUT'})

QGIS version: 3.10.2-A Coruña
QGIS code revision: d4cd3cfe5a
Qt version: 5.11.2
GDAL version: 3.0.3
GEOS version: 3.8.0-CAPI-1.13.1 
PROJ version: Rel. 6.3.0, January 1st, 2020
Processing algorithm…
Algorithm 'Generate Contours' starting…
Input parameters:
{ 'ContourInterval' : 1, 'ContourLevels' : '', 'ContourMethod' : None, 'ContourType' : 0, 'DuplicatePointTolerance' : 0, 'ExtendOption' : None, 'InputField' : '\"field_4\"', 'InputLayer' : 'file:///Q:/User/username/Washington_points.txt?type=csv&useHeader=No&trimFields=Yes&detectTypes=yes&xField=field_2&yField=field_3&zField=field_4&crs=EPSG:6541&spatialIndex=yes&subsetIndex=yes&watchFile=yes', 'LabelDecimalPlaces' : -1, 'LabelTrimZeros' : False, 'LabelUnits' : '', 'MaxContourValue' : None, 'MinContourValue' : None, 'NContour' : 20, 'OutputLayer' : 'TEMPORARY_OUTPUT' }

Traceback (most recent call last):
File "C:/Users/username/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\contour\ContourGeneratorAlgorithm.py", line 116, in _getEnumValue
id=values[int(id)]
ValueError: invalid literal for int() with base 10: ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/username/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\contour\ContourGeneratorAlgorithm.py", line 277, in processAlgorithm
method = self._getEnumValue( parameters, self.PrmContourMethod, context )
File "C:/Users/username/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\contour\ContourGeneratorAlgorithm.py", line 119, in _getEnumValue
tr('Invalid value {0} for {1}').format(id,name))
contour.ContourGeneratorAlgorithm.ContourGeneratorAlgorithmError: Invalid value for ContourMethod

Execution failed after 0.11 seconds

Loading resulting layers
Algorithm 'Generate Contours' finished

Filled Contour Polygons image

processing.run("contourplugin:generatecontours", {'InputLayer':'file:///Q:/User/username/Washington_points.txt?type=csv&useHeader=No&trimFields=Yes&detectTypes=yes&xField=field_2&yField=field_3&zField=field_4&crs=EPSG:6541&spatialIndex=yes&subsetIndex=yes&watchFile=yes','InputField':'\"field_4\"','DuplicatePointTolerance':0,'ContourType':1,'ExtendOption':None,'ContourMethod':None,'NContour':20,'MinContourValue':None,'MaxContourValue':None,'ContourInterval':1,'ContourLevels':'','LabelDecimalPlaces':-1,'LabelTrimZeros':False,'LabelUnits':'','OutputLayer':'TEMPORARY_OUTPUT'})

QGIS version: 3.10.2-A Coruña
QGIS code revision: d4cd3cfe5a
Qt version: 5.11.2
GDAL version: 3.0.3
GEOS version: 3.8.0-CAPI-1.13.1 
PROJ version: Rel. 6.3.0, January 1st, 2020
Processing algorithm…
Algorithm 'Generate Contours' starting…
Input parameters:
{ 'ContourInterval' : 1, 'ContourLevels' : '', 'ContourMethod' : None, 'ContourType' : 1, 'DuplicatePointTolerance' : 0, 'ExtendOption' : None, 'InputField' : '\"field_4\"', 'InputLayer' : 'file:///Q:/User/username/Washington_points.txt?type=csv&useHeader=No&trimFields=Yes&detectTypes=yes&xField=field_2&yField=field_3&zField=field_4&crs=EPSG:6541&spatialIndex=yes&subsetIndex=yes&watchFile=yes', 'LabelDecimalPlaces' : -1, 'LabelTrimZeros' : False, 'LabelUnits' : '', 'MaxContourValue' : None, 'MinContourValue' : None, 'NContour' : 20, 'OutputLayer' : 'TEMPORARY_OUTPUT' }

Traceback (most recent call last):
File "C:/Users/username/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\contour\ContourGeneratorAlgorithm.py", line 116, in _getEnumValue
id=values[int(id)]
ValueError: invalid literal for int() with base 10: ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/username/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\contour\ContourGeneratorAlgorithm.py", line 277, in processAlgorithm
method = self._getEnumValue( parameters, self.PrmContourMethod, context )
File "C:/Users/username/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\contour\ContourGeneratorAlgorithm.py", line 119, in _getEnumValue
tr('Invalid value {0} for {1}').format(id,name))
contour.ContourGeneratorAlgorithm.ContourGeneratorAlgorithmError: Invalid value for ContourMethod

Execution failed after 0.01 seconds

Loading resulting layers
Algorithm 'Generate Contours' finished

Layer Contour Polygons image

processing.run("contourplugin:generatecontours", {'InputLayer':'file:///Q:/User/username/Washington_points.txt?type=csv&useHeader=No&trimFields=Yes&detectTypes=yes&xField=field_2&yField=field_3&zField=field_4&crs=EPSG:6541&spatialIndex=yes&subsetIndex=yes&watchFile=yes','InputField':'\"field_4\"','DuplicatePointTolerance':0,'ContourType':2,'ExtendOption':None,'ContourMethod':None,'NContour':20,'MinContourValue':None,'MaxContourValue':None,'ContourInterval':1,'ContourLevels':'','LabelDecimalPlaces':-1,'LabelTrimZeros':False,'LabelUnits':'','OutputLayer':'TEMPORARY_OUTPUT'})

QGIS version: 3.10.2-A Coruña
QGIS code revision: d4cd3cfe5a
Qt version: 5.11.2
GDAL version: 3.0.3
GEOS version: 3.8.0-CAPI-1.13.1 
PROJ version: Rel. 6.3.0, January 1st, 2020
Processing algorithm…
Algorithm 'Generate Contours' starting…
Input parameters:
{ 'ContourInterval' : 1, 'ContourLevels' : '', 'ContourMethod' : None, 'ContourType' : 2, 'DuplicatePointTolerance' : 0, 'ExtendOption' : None, 'InputField' : '\"field_4\"', 'InputLayer' : 'file:///Q:/User/username/Washington_points.txt?type=csv&useHeader=No&trimFields=Yes&detectTypes=yes&xField=field_2&yField=field_3&zField=field_4&crs=EPSG:6541&spatialIndex=yes&subsetIndex=yes&watchFile=yes', 'LabelDecimalPlaces' : -1, 'LabelTrimZeros' : False, 'LabelUnits' : '', 'MaxContourValue' : None, 'MinContourValue' : None, 'NContour' : 20, 'OutputLayer' : 'TEMPORARY_OUTPUT' }

Traceback (most recent call last):
File "C:/Users/username/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\contour\ContourGeneratorAlgorithm.py", line 116, in _getEnumValue
id=values[int(id)]
ValueError: invalid literal for int() with base 10: ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/username/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\contour\ContourGeneratorAlgorithm.py", line 277, in processAlgorithm
method = self._getEnumValue( parameters, self.PrmContourMethod, context )
File "C:/Users/username/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\contour\ContourGeneratorAlgorithm.py", line 119, in _getEnumValue
tr('Invalid value {0} for {1}').format(id,name))
contour.ContourGeneratorAlgorithm.ContourGeneratorAlgorithmError: Invalid value for ContourMethod

Execution failed after 0.01 seconds

Loading resulting layers
Algorithm 'Generate Contours' finished
QGIS version 3.10.2-A Coruña QGIS code revision d4cd3cfe5a
Compiled against Qt 5.11.2 Running against Qt 5.11.2
Compiled against GDAL/OGR 3.0.3 Running against GDAL/OGR 3.0.3
Compiled against GEOS 3.8.0-CAPI-1.13.1 Running against GEOS 3.8.0-CAPI-1.13.1
Compiled against SQLite 3.29.0 Running against SQLite 3.29.0
PostgreSQL Client Version 11.5 SpatiaLite Version 4.3.0
QWT Version 6.1.3 QScintilla2 Version 2.10.8
Compiled against PROJ 6.3.0 Running against PROJ Rel. 6.3.0, January 1st, 2020
OS Version Windows 10 (10.0)
Active python plugins CalculateGeometry; contour; guided_offline_editing; MemoryLayerSaver; openlayers_plugin; ORStools; PeliasGeocoding; PluginLoadTimes; realcentroid; SpreadsheetLayers; zoom_level; db_manager; MetaSearch; processing
chaoscommander commented 3 years ago

I just ran into the same problem. If you're currently unable to fix it, can you give me a hint for a workaround if I need to create contour lines from manually-added points?

For me, the field creating the "invalid literal for int()" error is "id" which in my dataset is a qlonglong int64 and is not empty for any of the points (there are three with id = 1, 2 and 3).

ccrook commented 3 years ago

@Saijin-Naib Hi ... sorry - I totally dropped the ball on this one :-( Probably way too late to still be of interest to you...

I have just tried contouring the data you supplied in survey_points.zip. The only odd thing was that the data points were defined as MULTIPOINT objects in the geopackage and so not processed at all by the contour plugin (though each just has one point). I run the vector "Extract Vertices" tool in it and then contoured the vertices it created. This worked just fine for me.

I saw this as the contour tool gave an error letting me know it couldn't handle multipoint data. I am running QGIS 3.16.5 on ubuntu 20.04.

@chaoscommander. Please could you attach the data set you are loading so I can see if I can reproduce the problem.

chaoscommander commented 3 years ago

Sorry for the superficial report yesterday, I was in a bit of a hurry.

Hang on. I just discovered that the GUI changed when I tried again. Clicking the Contour button on the toolbar above the main window opens a dialog which then successfully creates the Contours layer! Yesterday I opened the plugin from the toolbox (that is accessible via the gearwheel button on the toolbar), that's where it failed. Trying that again now... and it fails! Are the two "entry points" using different defaults or different functions?

Anyway, here's my tiny shapefile and my setup:

QGIS-Version 3.16.2-Hannover QGIS-Codezweig Release 3.16
Kompiliert gegen Qt 5.15.2 Laufendes Qt 5.15.2
Kompiliert mit GDAL/OGR 3.2.1 Läuft mit GDAL/OGR 3.2.1
Kompiliert mit GEOS 3.9.0-CAPI-1.16.2 Läuft mit GEOS 3.9.0-CAPI-1.16.2
Kompiliert mit SQLite 3.33.0 Läuft mit SQLite 3.33.0
PostgreSQL-Client-Version Keine Unterstützung SpatiaLite-Version 4.3.0a
QWT-Version 6.1.5 QScintilla2-Version 2.11.5
Kompiliert mit PROJ 7.2.1 Läuft mit PROJ Rel. 7.2.1, January 1st, 2021
BS-Version Gentoo/Linux
Aktive Python-Erweiterungen contour; MetaSearch; processing; db_manager

Altaufschlüsse.zip

ccrook commented 3 years ago

Hi @chaoscommander Yes, the two entry points are different. The processing toolbox function does not have the same default options, it is a "raw" function which you can supply options to. It is intended mainly for incorporating into a processing script or the like. The dialog box is designed to help configure contouring so it is much more interactive. It is more "user friendly". It shows what contour levels are calculated, and generally provides more user interaction in configuring and creating a contour layer. In the end it uses the same functions though. I wasn't able to load your example data set, possibly because it only has the .shp file and not the other files that support it. I'm not sure, but QGIS just reported invalid data set.

chaoscommander commented 3 years ago

I see. Thanks for clearing that up. If you're still interested in looking at the data set, let me know which file types I need to include. My GIS experience is limited and I thought the shapefile would do it.

ccrook commented 3 years ago

@chaoscommander I'd be interested to try your data set to see if I can replicate the error if it's not too much trouble. Possibly the plugin could be enhanced to give a more useful message when that happens. Also would be good to know what setting you used to run the Generate Contours algorithm

chaoscommander commented 3 years ago

Sorry about the delay. Here you go: Altaufschlüsse_allthefiles.zip

And here's the parameters for Generate Contours: { 'ContourInterval' : 1, 'ContourLevels' : '', 'ContourMethod' : None, 'ContourType' : None, 'DuplicatePointTolerance' : 0, 'ExtendOption' : None, 'InputField' : '\"OKSand\"', 'InputLayer' : '/home/martin/Altaufschlüsse.shp', 'LabelDecimalPlaces' : -1, 'LabelTrimZeros' : False, 'LabelUnits' : '', 'MaxContourValue' : None, 'MinContourValue' : None, 'NContour' : 20, 'OutputLayer' : 'TEMPORARY_OUTPUT' }

For completeness, the error trace (which for some reason won't accept being formatted as code):

Traceback (most recent call last): File "/home/martin/.local/share/QGIS/QGIS3/profiles/default/python/plugins/contour/ContourGeneratorAlgorithm.py", line 116, in _getEnumValue id=values[int(id)] ValueError: invalid literal for int() with base 10: ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/martin/.local/share/QGIS/QGIS3/profiles/default/python/plugins/contour/ContourGeneratorAlgorithm.py", line 277, in processAlgorithm method = self._getEnumValue( parameters, self.PrmContourMethod, context ) File "/home/martin/.local/share/QGIS/QGIS3/profiles/default/python/plugins/contour/ContourGeneratorAlgorithm.py", line 118, in _getEnumValue raise ContourGeneratorAlgorithmError( contour.ContourGeneratorAlgorithm.ContourGeneratorAlgorithmError: Invalid value for ContourMethod

Ausführung nach 0.09 Sekunden gescheitert

andrew-demerchant commented 2 years ago

I just ran into this same problem - I couldn't get the contours to be create, no matter what I did, when using the Processing Toolbox. As soon as I read here that the other way may work, I tried it, and it did. The toolbar method worked no problem.

ccrook commented 2 years ago

Hi @andrew-demerchant @chaoscommander @Saijin-Naib Sorry I lost track of this when @chaoscommander posted this issue.

The quick answer is that the Contour type, Extend options, and Method are listed as optional but not treated as optional (ie there is not a default value). I will amend this in the plugin in the near future, but the quick answer to avoiding this issue is to set these values in the processing toolbox Generate Contours dialog box.

The (somewhat cryptic) clue is in the final line of the error message "Invalid value for ContourMethod"