This works, but I have a feeling that this could be easier (and more Julian). Is it possible to do the band maths directly on the GeoArray? Can I extract bands (slice) from the array as an GeoArray?
Sorry, not answering to your question, but how do we get those small GeoTIFF Sentinel-2 data sets? All I find in the Copernicus site are those big (large areas) .jp2 with sizes > 10000 x 10000 pixels.
The easiest way is to use EO Browser, zoom to area and download analytical data as GeoTIFF. You have to be registered and logged in to use the download feature.
The division converts it to a Float64 already, and we can use the constructor to set the f and crs fields directly.
This drops the GeoArray type, and makes a copy of the data:
julia> geoarray[:,:,7]
900×900 Matrix{UInt16}
It makes some sense that the AffineMap (f) is lost here, since if a subset of rows or columns are taken, it would be invalid. Probably it’s worth raising an issue about adding a method to ArchGDAL.getband, that would preserve the GeoArray, perhaps as a view.
As you said, division converts to Float64. Since both bands are UInt16, the subtraction (can be negative) causes problems, and thus I have made both bands Float64.
Reading only a band to GeoArray would be an excellent option. As I understand, ArchGDAL.getband should be extended to GeoArray.readband(fn, band)?
I was thinking perhaps it may be nice if GeoArrays would export ArchGDAL’s getband, and add a method getband(::GeoArray, i::Int)::GeoArray to it. If you’d like something like that, it’s best to raise an issue on the GeoArrays repository.