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

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

Open
Rapsodia86 opened this issue Jun 6, 2024 · 2 comments
Open

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

Rapsodia86 opened this issue Jun 6, 2024 · 2 comments

Comments

@Rapsodia86
Copy link

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
Copy link
Collaborator

evetion commented Jun 7, 2024

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
Copy link
Author

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

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