Skip to content

GDAL Error in REMMaker.get_river_elev() #13

@phaehnel

Description

@phaehnel

Version: 1.1.2

When using the REMMaker.make_rem() function, I get the following error message:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 2
      1 rem_maker = REMMaker(dem = path_dgm1, out_dir = path_res, centerline_shp = path_streamdiss, workers=12)
----> 2 rem_maker.make_rem()
      3 rem_maker.make_rem_viz(cmap = 'winter')

File ~/miniforge3/envs/mfenv/lib/python3.13/site-packages/riverrem/REMMaker.py:432, in REMMaker.make_rem(self)
    430 else:
    431     self.read_centerline_input()
--> 432 self.get_river_elev()
    433 self.interp_river_elev()
    434 self.detrend_dem()

File ~/miniforge3/envs/mfenv/lib/python3.13/site-packages/riverrem/REMMaker.py:334, in REMMaker.get_river_elev(self)
    332 res = f"-tr {self.cell_w} {self.cell_h}"
    333 # res = f"-tr {self.cell_w} {self.cell_h *-1}"
--> 334 gdal.Rasterize(self.centerline_ras, self.river_shp, options=f"-a id {extent} {res}")
    335 # raster to numpy array same shape as DEM
    336 r = gdal.Open(self.centerline_ras, gdal.GA_ReadOnly)

File ~/miniforge3/envs/mfenv/lib/python3.13/site-packages/osgeo/gdal.py:2197, in Rasterize(destNameOrDestDS, srcDS, **kwargs)
   2194     srcDS = OpenEx(srcDS, gdalconst.OF_VECTOR)
   2196 if isinstance(destNameOrDestDS, (str, os.PathLike)):
-> 2197     return wrapper_GDALRasterizeDestName(destNameOrDestDS, srcDS, opts, callback, callback_data)
   2198 else:
   2199     return wrapper_GDALRasterizeDestDS(destNameOrDestDS, srcDS, opts, callback, callback_data)

File ~/miniforge3/envs/mfenv/lib/python3.13/site-packages/osgeo/gdal.py:9471, in wrapper_GDALRasterizeDestName(*args)
   9469 def wrapper_GDALRasterizeDestName(*args):
   9470     r"""wrapper_GDALRasterizeDestName(char const * dest, Dataset srcDS, GDALRasterizeOptions options, GDALProgressFunc callback=0, void * callback_data=None) -> Dataset"""
-> 9471     return _gdal.wrapper_GDALRasterizeDestName(*args)

TypeError: in method 'wrapper_GDALRasterizeDestName', argument 3 of type 'GDALRasterizeOptions *'

This seems to be related to the DEM metadata that is used to rasterize the centerline shape with gdal in get_river_elev() (line 334). According to the GDAL documentation the resolution provided with option -tr has to be all positive values. In my case my DEM provides a negative value for the pixel size for the cell height (y coordinate) because the y coordinate values decrease from top to bottom in the coordinate system the DEM uses.

When I changed self.cell_h to be positive everything worked fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions