diff --git a/src/gmtreadwrite.jl b/src/gmtreadwrite.jl index d28e0d452..c6e4847b9 100644 --- a/src/gmtreadwrite.jl +++ b/src/gmtreadwrite.jl @@ -194,18 +194,18 @@ function gmtread(_fname::String; kwargs...) end if (opt_T == " -Ti" || opt_T == " -Tg") # See if we have a mem layout request - if ((val = find_in_dict(d, [:layout :mem_layout])[1]) !== nothing) - (opt_T == " -Ti" && startswith(string(val)::String, "TRB")) && return gdaltranslate(fname) + if ((lay = hlp_desnany_str(d, [:layout, :mem_layout])) != "") + (opt_T == " -Ti" && startswith(lay, "TRB")) && return gdaltranslate(fname) # MUST TAKE SOME ACTION HERE. FOR IMAGES I THINK ONLY THE "I" FOR IMAGES.JL IS REALLY POSSIBLE - cmd = (opt_T == " -Ti") ? cmd * " -%" * arg2str(val) : cmd * " -&" * arg2str(val) + cmd = (opt_T == " -Ti") ? cmd * " -%" * lay : cmd * " -&" * lay end end if (opt_T != " -To") # All others but OGR if (proggy == "read ") - ((val = find_in_dict(d, [:stride])[1]) !== nothing) && (cmd *= " -Em" * arg2str(val)::String; proggy = "gmtconvert ") - ((val = find_in_dict(d, [:q :inrows :inrow])[1]) !== nothing) && (cmd *= " -q" * arg2str(val)::String; proggy = "gmtconvert ") - ((val = find_in_dict(d, [:d :nodata])[1]) !== nothing) && (cmd *= " -di" * arg2str(val)::String; proggy = "gmtconvert ") + ((val2 = hlp_desnany_str(d, [:stride])) != "") && (cmd *= " -Em" * val2; proggy = "gmtconvert ") + ((val2 = hlp_desnany_str(d, [:q, :inrows, :inrow])) != "") && (cmd *= " -q" * val2; proggy = "gmtconvert ") + ((val2 = hlp_desnany_str(d, [:d, :nodata])) != "") && (cmd *= " -di" * val2; proggy = "gmtconvert ") cmd *= opt_T end @@ -606,8 +606,8 @@ function gmtwrite(fname::AbstractString, data; kwargs...) cmd = cmd * opt_T if (opt_T == " -Ti" || opt_T == " -Tg") # See if we have a mem layout request - if ((val = find_in_dict(d, [:layout :mem_layout])[1]) !== nothing) - cmd = (opt_T == " -Ti") ? cmd * " -%" * arg2str(val) : cmd * " -&" * arg2str(val) + if ((lay = hlp_desnany_str(d, [:layout, :mem_layout])) != "") + cmd = (opt_T == " -Ti") ? cmd * " -%" * lay : cmd * " -&" * lay end end @@ -642,14 +642,13 @@ function parse_grd_format(d::Dict)::String break end end - if ((val = find_in_dict(d, [:scale])[1]) !== nothing) out *= "+s" * arg2str(val) end - if ((val = find_in_dict(d, [:offset])[1]) !== nothing) out *= "+o" * arg2str(val) end - if ((val = find_in_dict(d, [:nan :novalue :invalid :missing])[1]) !== nothing) - out *= "+n" * arg2str(val) - end - if ((val = find_in_dict(d, [:driver])[1]) !== nothing) - out *= ":" * arg2str(val) - ((val = find_in_dict(d, [:datatype])[1]) !== nothing) && (out *= "/" * arg2str(val)) + + ((val = hlp_desnany_str(d, [:scale])) != "") && (out *= "+s" * val) + ((val = hlp_desnany_str(d, [:offset])) != "") && (out *= "+o" * val) + ((val = hlp_desnany_str(d, [:nan, :novalue, :invalid, :missing])) != "") && (out *= "+n" * val) + if ((val = hlp_desnany_str(d, [:driver])) != "") + out *= ":" * val + ((val = hlp_desnany_str(d, [:datatype])) != "") && (out *= "/" * val) end delete!(d, [:id, :gdal]) return out diff --git a/src/utils_project.jl b/src/utils_project.jl index d9694c66b..49ca0f74c 100644 --- a/src/utils_project.jl +++ b/src/utils_project.jl @@ -185,7 +185,7 @@ A Vector of GMTdataset containing the projected world GSHHG coastlines at resolu function worldrectcoast(; proj::StrSymb="", res="crude", coastlines::Vector{<:GMTdataset}=GMTdataset{Float64,2}[], limits=Float64[], round=false) # Project also the coastlines to go along with the grid created by worldrectangular _proj = isa(proj, Symbol) ? string(proj) : proj # Make it a string - cl = (isempty(coastlines)) ? coast(dump=:true, res=res, region=:global) : coastlines + cl = (isempty(coastlines)) ? coast(dump=:true, res=res, region=length(limits)==4 ? limits : :global) : coastlines (_proj == "" && isempty(limits)) && return cl # No proj required nor extending the coastlines (round || isempty(limits)) && return lonlat2xy(cl, t_srs=_proj) # No extensiom so we are donne. (_proj != "" && !contains(_proj, " +over")) && (_proj *= " +over") @@ -282,7 +282,8 @@ function worldrectgrid(D::GDtype; width=(30,20), grid=Vector{Vector{Real}}[], an prj = getproj(D, proj4=true) worldrectgrid(proj=prj, width=width, grid=grid, annot_x=annot_x) end -function worldrectgrid(; proj::StrSymb="", width=(30,20), grid=Vector{Vector{Real}}[], annot_x::Union{Vector{Int},Vector{Float64}}=Int[], pm=0, worldrect=true, pad=60) +function worldrectgrid(; proj::StrSymb="", width=(30,20), grid=Vector{Vector{Real}}[], + annot_x::Union{Vector{Int},Vector{Float64}}=Int[], pm=0.0, worldrect=true, pad=60) # Create a grid of lines in 'proj' coordinates. Input are meridians and parallels at steps # determined by 'width' and centered at 'pm'. 'pm' can be transmitted via argument or contained in 'proj' # 'worldrect=false' means we don't extend beyound the [-180 180]+pm as we do for worldrectangular. diff --git a/src/utils_types.jl b/src/utils_types.jl index 5a5c0a0ae..e7b1e8524 100644 --- a/src/utils_types.jl +++ b/src/utils_types.jl @@ -179,10 +179,10 @@ function helper_set_crs(d) end ref_attrib, ref_coln = Dict(), String[] - prj::String = ((proj = find_in_dict(d, [:proj :proj4])[1]) !== nothing) ? proj : "" + prj = hlp_desnany_str(d, [:proj, :proj4]) (prj == "geo" || prj == "geog") && (prj = prj4WGS84) (prj != "" && !startswith(prj, "+proj=")) && (prj = "+proj=" * prj) - wkt::String = ((wk = find_in_dict(d, [:wkt])[1]) !== nothing) ? wk : "" + wkt = hlp_desnany_str(d, [:wkt]) (prj == "" && wkt != "") && (prj = wkt2proj(wkt)) epsg::Int = ((ep = find_in_dict(d, [:epsg])[1]) !== nothing) ? ep : 0 (prj == "" && wkt == "" && epsg != 0) && (prj = epsg2proj(epsg)) @@ -2514,7 +2514,7 @@ end function mksymbol(f::Function, cmd0::String="", arg1=nothing; kwargs...) # Make a fig and convert it to EPS so it can be used as a custom symbol in plot(3) d = KW(kwargs) - t::String = ((val = find_in_dict(d, [:symbname :symb_name :symbol])[1]) !== nothing) ? string(val) : "GMTsymbol" + t::String = ((val = hlp_desnany_str(d, [:symbname, :symb_name, :symbol])) !== "") ? val : "GMTsymbol" (t == "GMTsymbol" && (f == flower_minho || f == matchbox)) && (t = string(f)) !haskey(d, :name) && (d[:name] = t * ".eps") if (f == flower_minho || f == matchbox) # Special case for the Flower Minho symbol @@ -2532,7 +2532,7 @@ mksymbol(f::Function, arg1; kw...) = mksymbol(f, "", arg1; kw...) # --------------------------------------------------------------------------------------------------- function hlp_desnany_str(d, s, del=true)::String - ((val = find_in_dict(d, s)[1]) === nothing) ? "" : string(val) + ((val = find_in_dict(d, s, del)[1]) === nothing) ? "" : string(val) end # ---------------------------------------------------------------------------------------------------