3

I want to resample a georeferend raster .tif file with Python using rasterio.

I found this: example

and here is a description of the resampling methods

I have to use the max method which is available in GDAL version 2.0.0 and higher. I have installed GDAL version 2.4.4 via brew on my Mac OS system.

When I run the following code (i.e. almost the example code):

raster = Path('dsm_EPSG_4839_cropped.tif')

import rasterio
from rasterio.enums import Resampling

upscale_factor = 1/(2**5)

with rasterio.open(raster) as dataset:

    # resample data to target shape
    data = dataset.read(
        out_shape=(
            dataset.count,
            int(dataset.height * upscale_factor),
            int(dataset.width * upscale_factor)
        ),
        resampling=Resampling.max
    )

    # scale image transform
    transform = dataset.transform * dataset.transform.scale(
        (dataset.width / data.shape[-1]),
        (dataset.height / data.shape[-2])
    )

I am getting the following error:

Segmentation fault: 11

Is there a way to determine the GDAL version the rasterio package uses? Is there a way to change that GDAL version rasterio is using?

1
  • 1
    You've got three questions here and I've answered the first, and its the one in the title. If you want to ask more than one question, make them as new questions.
    – Spacedman
    Commented May 17, 2020 at 11:16

1 Answer 1

8

Import rasterio and see what it provides...

>>> import rasterio
>>> dir(rasterio)
['Affine', 'Band', 'DatasetReader', 'DriverCapabilityError', 'Env', 'MemoryFile', 'NullHandler', 'Path', 'RasterioIOError', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__gdal_version__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', '_base', '_crs', '_env', '_err', '_features', '_io', '_shim', '_transform', '_warp', 'absolute_import', 'band', 'bool_', 'check_dtype', 'compat', 'complex_', 'contextmanager', 'control', 'coords', 'crs', 'default_gtiff_profile', 'drivers', 'dtypes', 'ensure_env_with_credentials', 'enums', 'env', 'errors', 'float32', 'float64', 'gdal_version', 'get_writer_for_driver', 'get_writer_for_path', 'guard_transform', 'int16', 'int32', 'int8', 'io', 'is_blacklisted', 'log', 'logging', 'namedtuple', 'open', 'pad', 'parse_path', 'path', 'profiles', 'rasterio', 'sample', 'sbyte', 'session', 'string_types', 'transform', 'ubyte', 'uint16', 'uint32', 'uint8', 'vrt', 'windows']

Hello hello this looks like it:

>>> rasterio.__gdal_version__
'2.4.4'

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.