I am attempting to contour a DEM raster using
This is my code:
in_data_set = gdal.Open(TEMP_CROP_DEM_PATH, gdal.GA_ReadOnly) in1 = in_data_set.GetRasterBand(1) ogr_ds = ogr.GetDriverByName("ESRI Shapefile").CreateDataSource(TEMP_CONTOURS_PATH) contour_shp = ogr_ds.CreateLayer('contour', dest_srs) field_defn = ogr.FieldDefn("ID", ogr.OFTInteger) contour_shp.CreateField(field_defn) field_defn = ogr.FieldDefn("elev", ogr.OFTReal) contour_shp.CreateField(field_defn) gdal.ContourGenerate(in1, contour_offset, 0, , 0, 0, contour_shp, 0, 1)
This code has worked for me on several tests, however it does not work when there is an area of
no data in the DEM. When contouring a DEM with
no data areas, QGIS freezes on the last line (
ContourGenerate) and crashes.
I have looked through the GDAL API and made sure all my arguments are correct. I have tried changing the 5th argument
useNoData to 1 and saw no change.
in1.GetNoDataValue() also causes QGIS to crash.
I am running out of ideas of where to look to solve my problem. Has anyone come across something similar? Are there other ways to achieve my goal, create vector contours from a DEM in Python?