1

The contour algorithm in QGIS doesn't create all of the contour lines. I've attached a screenshot of my raster layer below and the parameters I used. The raster ranges from 40-90 in value, spreading out from the center. So my expected output is a series of concentric circles.

Edit: The lines in the image is the output when I run the process.

This is the updated link to the test file: test_LPr1.tif

enter image description here

  • That is really odd, I've not seen this problem with GDAL_Contour before. I assume you're running on Windows by the path. Can you try running it in CMD but shorten the paths (move your raster to D:\Test and output there too), don't use dots, dashes or underscores.. it shouldn't make a difference but has historically been responsible for unreliable behavior. – Michael Stimson Dec 11 '18 at 6:57
  • 1
    Link to "test_LPr1.tif" would be useful. – user30184 Dec 11 '18 at 10:13
  • I just tried to reproduce the problem and contour worked fine for me, so it is not a general error and probably something quite specific to your raster. As @user30184 says, a link to your raster would be helpful and without it we probably can't offer any further help. – MappaGnosis Dec 11 '18 at 14:09
  • I've added a link to the file on my post above. I'm running this within QGIS and not on a command line. The raster file is an output from a series of raster processes in modeler and I'm trying to add another step in my model which is the contour. The last process in my model which produced this output is a gdal raster calculator. – strythe Dec 11 '18 at 23:14
  • I was too slow for getting sample image Sorry, this link has been automatically turned off for now. Learn more about traffic limits. – user30184 Dec 12 '18 at 20:37
2

The log tab of the Contour tool gives a hint about what happens

GDAL command output:
0...10...20...30...40...50ERROR 6: Range of levels [90,inf] not supported

Gdalinfo shows that your test image has nodata set to positive infinitive

Band 1 Block=2000x1 Type=Float32, ColorInterp=Gray
  Min=29.008 Max=70.435
  Minimum=29.008, Maximum=70.435, Mean=35.163, StdDev=4.438
  NoData Value=3.4028234663852886e+38

I am not sure about what values there really are in the test raster. If I unset the nodata value by making a copy with gdal_translate -a_nodata none the statistics show odd results

Band 1 Block=2000x1 Type=Float32, ColorInterp=Gray
  Min=29.008 Max=inf
  Minimum=29.008, Maximum=inf, Mean=-nan(ind), StdDev=-nan(ind)

Anyway because you did not set the nodata value through the user interface the gdal_contour starts to create a contour for interval [90,inf] and fails. I do not know why it fails because "inf" should be understood by GDAL as we will see later. But it seems also to be impossible to set the nodata value into either "inf" or to "3.4028234663852886e+38" through the user interface because QGIS is changing the input in both cases automatically into number "999999999.0".

What does work is to capture the gdal_contour command, edit it is run it from the command line.

gdal_contour -b 1 -a ELEV -i 1.0 -snodata inf  -f "ESRI Shapefile" test_LPr1.tif demtest.shp

Result looks good

enter image description here

For GDAL 2.4.0dev "inf" is the right way to give the source nodata. I had a try also with the nodata value reported by gdalinfo 3.4028234663852886e+38 but GDAL did not understand that it means the same as inf and it started to create contours for each meter which made the memory usage to skyrocket and finally Windows crashed with blue screen.

enter image description here

As a conclusion you made a mistake when you did not give the nodata value and QGIS has a bug because it is impossible to give "inf" as a nodata value. There may also be an issue in gdal_contour because it does not consider numeric 3.4028234663852886e+38 as infinite float32 value.

  • Thanks for this @user30184. I'll try to look into it. With regards to the raster, it is a result of a series of raster operations in a process model I'm making. It is essentially a raster calculator performed on a proximity distance raster. I've checked, and the contour works on the proximity raster, so I'm guessing the problem is with the raster calculator step. – strythe Dec 14 '18 at 0:21
  • Also, I found out that the contour works on my test raster when using QGIS 2.18, but not on version 3.4, which is where I'm making the model. Does this mean that the problem is with the later version of gdal? – strythe Dec 14 '18 at 0:25
  • You could probably help QGIS and GDAL by creating your raster to have an easier number for nodata, like -9999 if it is outside your valid data range. – user30184 Dec 14 '18 at 7:09

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.