Skip to content

Commit

Permalink
Merge pull request #1235 from GenericMappingTools/read-bi
Browse files Browse the repository at this point in the history
Let -bi mean that input is a dataset.
  • Loading branch information
joa-quim authored Aug 26, 2023
2 parents a3ecb48 + ad5aca0 commit f5b16f8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
16 changes: 15 additions & 1 deletion src/GMT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,24 @@ include("get_enums.jl")
GMT.cat_2_arg2(mat2ds(rand(3,2)), mat2ds(rand(3,2)));
GMT.cat_3_arg2(rand(3),rand(3),rand(3));
plot(rand(5,2), marker=:point, lc=:red, ls=:dot, lw=1, C=:jet, colorbar=true, Vd=2)
plot(rand(5,2))
makecpt(T=(0,10))
t = joinpath(tempdir(), "lixo.dat");
gmtwrite(t,[0.0 0; 1 1]);
gmtread(t);
rm(t)
grdimage(rand(Float32,32,32), Vd=2);
grdview(rand(Float32,32,32), Vd=2);
grdinfo(mat2grid(rand(Float32,4,4)));
G=gmt("grdmath", "-R0/10/0/10 -I2 X");
grdcontour(G);
grd2cpt(G);
grd2xyz(G);
grdlandmask(R="-10/4/37/45", res=:c, inc=0.1);
grdmask([10 20; 40 40; 70 20; 10 20], R="0/100/0/100", out_edge_in=[100 0 0], I=2);
grdsample(G, inc=0.5);
grdtrend(G, model=3);
grdtrack(G, [1 1]);
mat2img(rand(UInt8, 32, 32, 3));
coast(R=:g, proj=:guess, W=(level=1,pen=(2,:green)), Vd=2);
gridit(rand(10,3), preproc=true, I=0.1);
earthregions("PT", Vd=2);
Expand Down
2 changes: 1 addition & 1 deletion src/common_options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ function parse_b(d::Dict, cmd::String, symbs::Array{Symbol}=[:b :binary], io::St
(ncols=("", arg2str, 1), type=("", data_type, 2), swapp_bytes="_w", little_endian="_+l", big_endian="+b"))
return cmd * cmd_, cmd_
end
parse_bi(d::Dict, cmd::String) = parse_b(d, cmd, [:b :bi :binary_in], "i")
parse_bi(d::Dict, cmd::String) = parse_b(d, cmd, [:b :bi :binary :binary_in], "i")
parse_bo(d::Dict, cmd::String) = parse_b(d, cmd, [:b :bo :binary_out], "o")
# ---------------------------------------------------------------------------------------------------

Expand Down
2 changes: 2 additions & 0 deletions src/gmtreadwrite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ function gmtread(_fname::String; kwargs...)
end
end

(opt_T == "" && opt_bi != "") && (opt_T = " -Td") # If asked to read binary, must be a 'data' file.

if (opt_T == "")
((opt_T = guess_T_from_ext(fname)) == "") && error("Must select one input data type (grid, image, dataset, cmap or ps)")
(opt_T == " -Tg" && haskey(d, :ignore_grd)) && return nothing # contourf uses this
Expand Down
13 changes: 9 additions & 4 deletions src/gmtspatial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ Parameters
- $(GMT.opt_o)
- $(GMT.opt_swap_xy)
"""
function gmtspatial(cmd0::String="", arg1=nothing; kwargs...)
function gmtspatial(cmd0::String="", arg1=nothing, arg2 = nothing; kwargs...)

d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
arg2 = nothing; arg3 = nothing; arg4 = nothing
arg3 = nothing; arg4 = nothing

cmd, = parse_common_opts(d, "", [:R :V_params :b :d :e :f :g :h :i :o :yx])
cmd = parse_these_opts(cmd, d, [[:A :nn :nearest_neighbor], [:C :clip], [:E :handedness], [:F :force_polygons],
Expand All @@ -75,7 +75,7 @@ function gmtspatial(cmd0::String="", arg1=nothing; kwargs...)
arg1, arg2 = args[:]; cmd *= "+f"
end

cmd, args, n, = add_opt(d, cmd, "N", [:N :in_polyg], :data, Array{Any,1}([arg1, arg2, arg3]), (all="_+a", start="+p", has_feature="_+r", add_IDs="_+z"))
cmd, args, n, = add_opt(d, cmd, "N", [:N :in_polyg], :data, Array{Any,1}([arg1, arg2, arg3]), (all="_+a", start="+p", has_feature="_+r", add_IDs="_+z", individual="_+i"))
if (n > 0) arg1, arg2, arg3 = args[:] end

cmd, args, n, = add_opt(d, cmd, "T", [:T :truncate], :data, Array{Any,1}([arg1, arg2, arg3, arg4]), (x="",))
Expand All @@ -84,16 +84,21 @@ function gmtspatial(cmd0::String="", arg1=nothing; kwargs...)
do_sort = (find_in_dict(d, [:sort])[1] !== nothing)
if (isa(arg1,Tuple))
D = common_grd(d, cmd0, cmd, "gmtspatial ", arg1..., arg2, arg3, arg4) # Finish build cmd and run it
arg = arg1[end]
else
D = common_grd(d, cmd0, cmd, "gmtspatial ", arg1, arg2, arg3, arg4)
arg = arg2
end
hasID = (isa(arg, GMTdataset) && (contains(arg.header, "-Z") || contains(arg.header, "-L"))) || # To know if add +1 to start at 1
(isa(arg, Vector{<:GMTdataset}) && (contains(arg[1].header, "-Z") || contains(arg[1].header, "-L")))
if (do_sort && !isempty(D))
ind = sortperm(view(D, :, 3))
D.data = D.data[ind, :]
!isempty(D.text) && (D.text = D.text[ind])
end
contains(cmd, "-N+i") && (D.colnames = ["x","y","polID"]; (!hasID && [D[k,3] += 1 for k = 1:size(D,1)]))
D
end

# ---------------------------------------------------------------------------------------------------
gmtspatial(arg1; kw...) = gmtspatial("", arg1; kw...)
gmtspatial(arg1, arg2=nothing; kw...) = gmtspatial("", arg1, arg2; kw...)

0 comments on commit f5b16f8

Please sign in to comment.