0

I am trying to color a GeoTIFF file and convert it to PNG. Several thread (1, 2) have pointed the gdaldem function. Here I am now porting the function to Python. Using the documentation, I can pass DEMProcessingOptions to DEMProcessing.

How do I pass the DEMProcessingOptions object to DEMProcessing correctly? I have this on my code:

from osgeo import gdal

src_ds = gdal.Open('./example.tif')
options = gdal.DEMProcessingOptions(colorFilename='./color_ramp.txt', format='PNG')
ds = gdal.DEMProcessing('./example_converted.png', src_ds, processing='color-relief', options)

I get the error:

Cell In [7], line 3 ds = gdal.DEMProcessing('./example_converted.png', src_ds, processing='color-relief', options) ^ SyntaxError: positional argument follows keyword argument

If I remove the variable names in the function:

ds = gdal.DEMProcessing('./example_converted.png', src_ds, 'color-relief', options)

It would error:

TypeError: DEMProcessing() takes 3 positional arguments but 4 were given

5
  • 1
    the error says to pass the keyword to a positional argument, try pass something like options=options Commented Feb 9, 2023 at 10:30
  • Thank you @MarcoReliquias.
    – Nikko
    Commented Feb 9, 2023 at 10:42
  • 1
    it works? if works tell me to write a answer to you flag as correct Commented Feb 9, 2023 at 10:43
  • Yes, it worked @MarcoReliquias.
    – Nikko
    Commented Feb 9, 2023 at 10:46
  • please flag as correted answer, thanks :) Commented Feb 9, 2023 at 13:13

1 Answer 1

1

The error thrown, indicates that you need to name the parameters with the correct keywords. try passing the options with this keyword:

from osgeo import gdal

src_ds = gdal.Open('./example.tif')
options = gdal.DEMProcessingOptions(colorFilename='./color_ramp.txt', format='PNG')
ds = gdal.DEMProcessing('./example_converted.png', src_ds, processing='color-relief', options=options)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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