yeesian / ArchGDAL.jl

A high level API for GDAL - Geospatial Data Abstraction Library
https://yeesian.github.io/ArchGDAL.jl/stable/
Other
137 stars 25 forks source link

Set band name when writing a raster to the GeoTiff file? #429

Open Rapsodia86 opened 2 weeks ago

Rapsodia86 commented 2 weeks ago

Hello! I want to ask about setting a band name while creating a GeoTIFF. In Python, I would use setdescription(). However, this function does not exist on the list of methods. But there is setcategorynames!. Is it a proper one?

dataset = ArchGDAL.create(dst_ds, driver=ArchGDAL.getdriver("GTiff"), width=nCol,
            height=nRow, nbands=1, dtype=Float32, options=["COMPRESS=LZW"])
band = ArchGDAL.getband(dataset, 1)
ArchGDAL.write!(band, final_array)
ArchGDAL.setnodatavalue!(band, -9999)
ArchGDAL.setproj!(dataset, pj)
ArchGDAL.setgeotransform!(dataset, gt)
ArchGDAL.setcategorynames!(band, "Red123")
ArchGDAL.destroy(dataset)

gives me an error:

ERROR: MethodError: no method matching setcategorynames!(::ArchGDAL.IRasterBand{Float32}, ::String)

Closest candidates are:
  setcategorynames!(::T, ::Vector{String}) where T<:ArchGDAL.AbstractRasterBand
   @ ArchGDAL C:\Users\monikat\.julia\packages\ArchGDAL\xZUPv\src\raster\rasterband.jl:474

And the error says that my "band" is ArchGDAL.IRasterBand{Float32}, while in setnodatavalue! that has the same input type requirement, there is no problem? Unless setcategorynames! is the wrong function for it?

What do I miss here? Sorry if this is trivial! Thanks:)

evetion commented 2 weeks ago

Looking through my own code, it seems I had to call GDAL directly, as ArchGDAL doesn't wrap it (yet): https://github.com/evetion/GeoArrays.jl/blob/master/src/io.jl#L159

So that would be ArchGDAL.GDAL.gdalsetdescription(band, bandnames)

Rapsodia86 commented 2 weeks ago

Worked! I should have thought about it! Thank you very much!:)