Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue in gdal.Grid called from python bindings #10317

Closed
hanshooyberghs opened this issue Jun 26, 2024 · 1 comment
Closed

Issue in gdal.Grid called from python bindings #10317

hanshooyberghs opened this issue Jun 26, 2024 · 1 comment

Comments

@hanshooyberghs
Copy link

What is the bug?

I have a python code using gda.Grid, in which some options are passed, The code used to work up to gdal 3.8.5, but since 3.9.0 there is a strange error:

File "/python/lib/python3.12/site-packages/osgeo/gdal.py", line 1974, in Grid
return GridInternal(destName, srcDS, opts, callback, callback_data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/python/lib/python3.12/site-packages/osgeo/gdal.py", line 9075, in GridInternal
return _gdal.GridInternal(*args)
^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: in method 'GridInternal', argument 3 of type 'GDALGridOptions *'

The options are standard:
options = gdal.GridOptions(
algorithm='NEAREST',
radius1=range,
radius2=range,
nodata=-9999,
outputBounds=[xmin, ymax, xmax, ymin],
outputType=gdal.GDT_Byte,
width=x_diff,
height=y_diff,
zfield='clas_01',
creationOptions=['COMPRESS=DEFLATE', 'BIGTIFF=YES']
)
with all parameters correctly defined.

Steps to reproduce the issue

options = gdal.GridOptions(
    algorithm='NEAREST',
    radius1=50,
    radius2=50,
    nodata=-9999,
    outputBounds=[xmin, ymax, xmax, ymin],
    outputType=gdal.GDT_Byte,
    width=x_diff,
    height=y_diff,
    zfield='clas_01',
    creationOptions=['COMPRESS=DEFLATE', 'BIGTIFF=YES']
)
gridded = gdal.Grid(sc_nosc_grid, vrt_file, options=options)
return gridded

Versions and provenance

GDAL 3.9.0
installed in python version (via mamba install)

Additional context

No response

@rouault
Copy link
Member

rouault commented Jun 26, 2024

The code used to work up to gdal 3.8.5,

Weird. It should not. radius1, radius2 or nodata (lower case) are not accepted parameters. They should be put inside the algorithm string. Cf:

def GridOptions(options=None, format=None,
              outputType=gdalconst.GDT_Unknown,
              width=0, height=0,
              creationOptions=None,
              outputBounds=None,
              outputSRS=None,
              noData=None,
              algorithm=None,
              layers=None,
              SQLStatement=None,
              where=None,
              spatFilter=None,
              zfield=None,
              z_increase=None,
              z_multiply=None,
              callback=None, callback_data=None):
    """ Create a GridOptions() object that can be passed to gdal.Grid()

    Parameters
    ----------
    options:
        can be be an array of strings, a string or let empty and filled from other keywords.
    format:
        output format ("GTiff", etc...)
    outputType:
        output type (gdalconst.GDT_Byte, etc...)
    width:
        width of the output raster in pixel
    height:
        height of the output raster in pixel
    creationOptions:
        list or dict of creation options
    outputBounds:
        assigned output bounds:
        [ulx, uly, lrx, lry]
    outputSRS:
        assigned output SRS
    noData:
        nodata value
    algorithm:
        e.g "invdist:power=2.0:smoothing=0.0:radius1=0.0:radius2=0.0:angle=0.0:max_points=0:min_points=0:nodata=0.0"
    layers:
        list of layers to convert
    SQLStatement:
        SQL statement to apply to the source dataset
    where:
        WHERE clause to apply to source layer(s)
    spatFilter:
        spatial filter as (minX, minY, maxX, maxY) bounding box
    zfield:
        Identifies an attribute field on the features to be used to get a Z value from.
        This value overrides Z value read from feature geometry record.
    z_increase:
        Addition to the attribute field on the features to be used to get a Z value from.
        The addition should be the same unit as Z value. The result value will be
        Z value + Z increase value. The default value is 0.
    z_multiply:
        Multiplication ratio for Z field. This can be used for shift from e.g. foot to meters
        or from  elevation to deep. The result value will be
        (Z value + Z increase value) * Z multiply value. The default value is 1.
    callback:
        callback method
    callback_data:
        user data for callback
    """

There has been no change in the gdal.GridOptions() signature between 3.8.5 and 3.9.0

@rouault rouault closed this as completed Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants