Hi, I wanted,
to give Julia a chance because it said to be rather fast. And some parts of my Python code needs hours (like 3 to 5) and that just to much, to be productively useful. Especial when you still have to debug the code.
I want to do some calculation on some masked Sentinel2 tiles and use ArchGDAL.jl for that.
The main code: is opening two raster files and (one with real data, the other as indicies of the reagions. And than I want to compute the mode of each region and than save the data of the mode into an new file.
The code that is currently running (but I wouldn’t mind, when it be faster) is:
using StatsBase
using ArchGDAL; const AG = ArchGDAL
class_raster = Array{Int64}(ArchGDAL.read(AG.read(prediction_path), 1))
class_raster[class_raster .== 55537] .= 0
class_raster[class_raster .== -9999] .= 0
Array{UInt8}(class_raster)
indices = Array{Int64}(ArchGDAL.read(AG.read(atkis_area_path), 1))
unique_indices = unique(indices)
for _index in unique_indices
coordinates = findall(indices .== _index)
mode_val = mode(class_raster[findall(index_raster .== _index)])
for x in coordinates
local_classes[x] = mode_val
end
end
But when I want to save the file for instance with:
dataset = AG.read(prediction_path)
ref = AG.getproj(dataset)
geotransform = AG.getgeotransform(dataset)
raster = AG.unsafe_create(
"test.tif",
AG.getdriver("GTiff"),
width = ArchGDAL.width(dataset),
height = ArchGDAL.height(dataset),
nbands = 1,
dtype = UInt8
)
AG.setgeotransform!(raster, geotransform)
AG.setproj!(raster, ref)
AG.write!(
raster,
local_classes, # image to "burn" into the raster
1, # update band 1
)
I still get an error when calling unsave_create:
MethodError: no method matching unsafe_create(::String, ::ArchGDAL.Driver; width=7328, height=5860, nbands=1, dtype=UInt8)
Closest candidates are:
unsafe_create(::AbstractString; driver, width, height, nbands, dtype, options) at C:\Users\TITAN.julia\packages\ArchGDAL\s5Bwr\src\dataset.jl:191Stacktrace:
[1] top-level scope at In[28]:1
[2] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1091
I don’t know why! Didn’t I add every parameter needed? Is it a problem with the types? Additionally I totally puzzled when to use AG and when ArchGDAL.
I hope you could help me out. Thanks alot!