(help request) using ArchGDAL.gdalwarp() for resampling a raster dataset

Hi all, I’m struggling to figure out how to use ArchGDAL.gdalwarp (currently only unsafe_gdalwarp is documented). ArchGDAL.gdalwarp’s first parameter being a function is a bit confusing as well.

Here’s the GDAL CLI version of what I’m trying to implement in ArchGDAL (params I already have in Julia are represented by the all caps strings):

gdalwarp -t_srs WKT_STRING -te LEFT_EXTENT LOWER_EXTENT RIGHT_EXTENT \
    UPPER_EXTENT -te_srs WKT_STRING -tr X_RES Y_RES -r cubic \
    GDAL_DATASET output_dataset

I’m also hoping to return an ArchGDAL.Dataset if possible (without writing anything to disk).

Thanks for any help!

Okay! I think I figured it out…?

ds = ArchGDAL.read(path) do source
    ArchGDAL.gdalwarp([source], ["-t_srs", "$(wkt)",
                               "-te", "$(west_bound)", "$(south_bound)",
                               "$(east_bound)", "$(north_bound)",
                               "-te_srs", "$(wkt)",
                               "-tr", "$(step(x_dim))", "$(step(y_dim))",
                               "-r", "cubic"]) do warped
        band = ArchGDAL.getband(warped, 1)

        ArchGDAL.read(band)
    end
end
1 Like

We may as well wrap this in GeoData.jl, that could be a one liner

I can do a PR if you’d like. Feel free to create an issue in GeoData.jl and tag me! Can probably get to that next week. Also feel free to copy/paste the above if you want to implement it.

Done: https://github.com/rafaqz/GeoData.jl/issues/68

2 Likes