# ArchGDAL.read error: GDALError (CE\_Failure, code 4):not recognized as a supported file format

**URL:** <https://discourse.julialang.org/t/archgdal-read-error-gdalerror-ce-failure-code-4-not-recognized-as-a-supported-file-format/95959>\
**Category:** Geo\
**Tags:** question, gdal, archgdal\
**Created:** [March 12, 2023, 8:30am UTC](https://discourse.julialang.org/t/archgdal-read-error-gdalerror-ce-failure-code-4-not-recognized-as-a-supported-file-format/95959 "2023-03-12T08:30:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunayana](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@sunayana](https://discourse.julialang.org/u/sunayana)\
**Post date:** [March 12, 2023, 8:30am UTC](https://discourse.julialang.org/t/archgdal-read-error-gdalerror-ce-failure-code-4-not-recognized-as-a-supported-file-format/95959/1 "2023-03-12T08:30:28Z")

</div>

Hi,  
I am currently stuck with a strange issue in GDAL and do not understand how to solve it. I have a method inside an IO module:

```julia
read_image_file(filename::AbstractPath) = AG.read(string(filename))

```

This method is being called from another method:

```julia
function write_cog(output_path::SystemPath, dataset_path::AbstractPath)
    dataset = read_image_file(dataset_path)
    AG.copy(dataset; filename = string(output_path), driver = AG.getdriver("COG"))
end

```

and here it fails giving me the error

```julia
Exception has occurred: GDAL.GDALError
GDALError (CE_Failure, code 4):
	`.../temp.tif' not recognized as a supported file format.

```

When I run the same code through the debugger, it works well. Not sure how to solve this issue. Any help is much appreciated.

---

<div class="post-metadata">

**Author:** ![sunayana](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@sunayana](https://discourse.julialang.org/u/sunayana)\
**Post date:** [March 12, 2023, 8:34am UTC](https://discourse.julialang.org/t/archgdal-read-error-gdalerror-ce-failure-code-4-not-recognized-as-a-supported-file-format/95959/2 "2023-03-12T08:34:56Z")

</div>

I find this solution in Stack Overflow:

> <https://gis.stackexchange.com/questions/285958/error4-file-not-supported-with-gdal>

but don’t see `gdal.AllRegister()` equivalent in ArchGDAL, could someone here point me in the right direction.

---

<div class="post-metadata">

**Author:** ![visr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/visr/32/17204_2.png) [@visr](https://discourse.julialang.org/u/visr)\
**Post date:** [March 12, 2023, 9:06am UTC](https://discourse.julialang.org/t/archgdal-read-error-gdalerror-ce-failure-code-4-not-recognized-as-a-supported-file-format/95959/3 "2023-03-12T09:06:07Z")

</div>

GDAL.jl has a `gdalallregister` function, but that is automatically called [during module initialization](https://github.com/JuliaGeo/GDAL.jl/blob/v1.5.1/src/GDAL.jl#L47-L48), so that’s not the problem here. It looks more like your TIFF file might not be a GeoTIFF? GDAL cannot read TIFF files without geospatial metadata. You could check by trying if the file linked in this example can be loaded: [Raster Data · ArchGDAL.jl](https://yeesian.com/ArchGDAL.jl/dev/rasters/#Raster-Data).

---

<div class="post-metadata">

**Author:** ![sunayana](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@sunayana](https://discourse.julialang.org/u/sunayana)\
**Post date:** [March 12, 2023, 9:46am UTC](https://discourse.julialang.org/t/archgdal-read-error-gdalerror-ce-failure-code-4-not-recognized-as-a-supported-file-format/95959/4 "2023-03-12T09:46:40Z")

</div>

I can confirm that the `temp.tif` file is created and I can read it fine using ArchGDAL.read from the REPL

---

<div class="post-metadata">

**Author:** ![sunayana](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@sunayana](https://discourse.julialang.org/u/sunayana)\
**Post date:** [March 12, 2023, 10:08am UTC](https://discourse.julialang.org/t/archgdal-read-error-gdalerror-ce-failure-code-4-not-recognized-as-a-supported-file-format/95959/5 "2023-03-12T10:08:44Z")

</div>

@visr thanks, I was able to resolve the issue, the problem was coming from this function I had:

```julia
function _save_array(
    input_dtm_path::AbstractPath,
    array2D::AbstractMatrix{T},
    temp_dir::AbstractPath,
) where {T<:Real}
    # Read the DTM geotiff and extract the geotransform and projection
    dataset = read_image_file(input_dtm_path)
    projection = AG.getproj(dataset)
    geotransform = AG.getgeotransform(dataset)
    (m, n) = size(array2D)

    # Create a temporary dataset and write array2D to it
    # gds_out = AG.create(
    # string(temp_dir),
    # driver = AG.getdriver("GTiff"),
    # width = m,
    # height = n,
    # nbands = 1,
    # options = [
    # "COMPRESS=DEFLATE",
    # "COPY_SRC_OVERVIEWS=YES",
    # "OVERVIEW_COMPRESS=DEFLATE",
    # ],
    # dtype = T,
    # )
    # AG.setgeotransform!(gds_out, geotransform)
    # AG.setproj!(gds_out, projection)
    # AG.write!(gds_out, array2D[:, :], 1)
    opts = ["COMPRESS=DEFLATE", "COPY_SRC_OVERVIEWS=YES", "OVERVIEW_COMPRESS=DEFLATE"]
    AG.create(
        string(temp_dir),
        driver = AG.getdriver("GTiff"),
        width = m,
        height = n,
        nbands = 1,
        dtype = T,
        options = opts,
    ) do ds
        band = AG.getband(ds, 1)
        AG.write!(band, array2D[:, :])
        AG.setgeotransform!(ds, geotransform)
        AG.setproj!(ds, projection)
        AG.destroy(
            AG.copy(
                dataset,
                filename = string(temp_dir),
                driver = AG.getdriver("GTiff"),
                options = opts,
            ),
        )

    end
    return nothing

end

```

I made updates to it as per your advice on [GitHub](https://github.com/yeesian/ArchGDAL.jl/issues/123)
