@@ -334,17 +334,19 @@ function gdalvectortranslate(indata, opts=String[]; dest="/vsimem/tmp", kwargs..
334334 helper_run_GDAL_fun (gdalvectortranslate, indata, dest, opts, " " , KW (kwargs))
335335end
336336
337- function helper_run_GDAL_fun (f:: Function , indata, dest:: String , opts, method:: String , d:: Dict{Symbol, Any} ):: Union{GItype, GDtype, Gdal.AbstractDataset, Nothing}
337+ function helper_run_GDAL_fun (f:: Function , indata, dest:: String , opts, method:: String , d:: Dict{Symbol, Any} )
338338 ressurectGDAL () # Another black-hole plug attempt.
339339 opts = gdal_opts2vec (opts) # Guarantied to return a Vector{String}
340- # d = KW(kwargs)
340+ opts_vs = gdal_opts2vec (opts) # Guarantied to return a Vector{String}
341341 opts_vs, got_GMT_opts = GMT_opts_to_GDAL (f, opts, d)
342- _helper_run_GDAL_fun (f, indata, dest, opts_vs, method, got_GMT_opts, d)
342+ d_fun = Dict {Symbol, Function} (:fun => f) # To avoid fck compilation for each different fuction
343+ _helper_run_GDAL_fun (d_fun, indata, dest, opts_vs, method, got_GMT_opts, d)
343344end
344345
345346# ---------------------------------------------------------------------------------------------------
346- function _helper_run_GDAL_fun (f:: Function , indata, dest:: String , opts:: Union{String, Vector{String}} , method, got_GMT_opts:: Bool , d:: Dict{Symbol, Any} ):: Union{GItype, GDtype, Gdal.AbstractDataset, Nothing}
347- # This second level helper function reduces the number of multiple compiles. Here, only 'indata' may have different types.
347+ function _helper_run_GDAL_fun (d_fun:: Dict{Symbol, Function} , @nospecialize (indata), dest:: String , opts:: Vector{String} , method:: String , got_GMT_opts:: Bool , d:: Dict{Symbol, Any} )
348+ # This second level helper function reduces the number of multiple compiles.
349+ f = d_fun[:fun ] # Get back the function name
348350
349351 Vd:: Int = ((val = find_in_dict (d, [:Vd ])[1 ]) != = nothing ) ? val : 0 # More gymns to avoid Anys
350352 (Vd > 0 ) && println (opts)
@@ -459,7 +461,6 @@ function GMT_opts_to_GDAL(f::Function, opts::Vector{String}, d::Dict{Symbol, Any
459461 end
460462 end
461463 f == gdalgrid ? append! (opts, [" -txe" , s[1 ], s[2 ], " -tye" , s[3 ], s[4 ]]) : append! (opts, op)
462- # f == gdalgrid ? append!(opts, ["-txe", s[1], s[2], "-tye", s[3], s[4]]) : append!(opts, ["-projwin", split(opt_R[4:end], '/')[[1,4,2,3]]...]) # Ugly
463464 end
464465
465466 x_srs = (f == gdaltranslate) ? " -a_srs" : " -t_srs" # But don't know if there are others that take -a_srs instead of -t_srs
@@ -527,7 +528,7 @@ function default_gdopts!(f::Function, ds, opts::Vector{String}, dest::String)
527528end
528529
529530# ---------------------------------------------------------------------------------------------------
530- function get_gdaldataset (data, opts, isVec:: Bool = false ):: Tuple{Gdal.AbstractDataset, Bool}
531+ function get_gdaldataset (data, opts:: Vector{String} , isVec:: Bool = false ):: Tuple{Gdal.AbstractDataset, Bool}
531532 # Get a GDAL dataset from either a file name, a GMT grid or image, or a dataset itself
532533 # In case of a file name we must be careful and deal with possible "+b" band requests from GMT.
533534 # isVec tells us if the filename 'data' is to be opened as a Vector or a Raster.
@@ -540,11 +541,7 @@ function get_gdaldataset(data, opts, isVec::Bool=false)::Tuple{Gdal.AbstractData
540541 o = split (ext[ind[1 ]+ 2 : end ], " ," ) # But we must add 1 because GDAL band count is 1-based and GMT 0-based
541542 p = parse .(Int, o) .+ 1
542543 o = [string (c) for c in p]
543- if (isa (opts, Vector{String}))
544- for k = 1 : lastindex (o) append! (opts, [" -b" , o[k]]) end
545- else
546- opts *= " -b" * join (o, " -b " )
547- end
544+ for k = 1 : lastindex (o) append! (opts, [" -b" , o[k]]) end
548545 end
549546 flags = isVec ? GDAL_OF_VECTOR | GDAL_OF_VERBOSE_ERROR : GDAL_OF_READONLY | GDAL_OF_VERBOSE_ERROR
550547 _ext = lowercase (ext[2 : end ]) # Drop the leading dot too
@@ -578,7 +575,7 @@ Convert a 24bit RGB image to 8bit paletted.
578575"""
579576function dither (indata, opts= String[]; n_colors:: Integer = 256 , save:: String = " " , gdataset:: Bool = false )
580577 # ...
581- src_ds, needclose = get_gdaldataset (indata, " " , false )
578+ src_ds, needclose = get_gdaldataset (indata, String[] , false )
582579 (nraster (src_ds) < 3 ) && error (" Input image must have at least 3 bands" )
583580 (isa (indata, GMTimage) && ! startswith (indata. layout, " TRB" )) &&
584581 error (" Image memory layout must be `TRB` and not $(indata. layout) . Load image with gdaltranslate()" )
0 commit comments