Skip to content

Commit 4286f3d

Browse files
authored
Call grdinfo -C, when possible, via the gmt_grdinfo_C() function. (#1869)
1 parent 58e76f0 commit 4286f3d

File tree

11 files changed

+18
-19
lines changed

11 files changed

+18
-19
lines changed

src/GMT.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export
163163
ogr2ogr, gdalrasterize, gdalbuildvrt, readgeom, readraster, setgeotransform!, setnodata!, setproj!, destroy,
164164
delaunay, dither, buffer, centroid, intersection, intersects, polyunion, overlaps, fromWKT, fillnodata!, fillnodata,
165165
concavehull, convexhull, difference, symdifference, distance, geodesicarea, geomarea, pointalongline, polygonize, simplify,
166+
boundary, crosses, disjoint, envelope, envelope3d, equals, touches, uniqueind, within,
166167

167168
wkbUnknown, wkbPoint, wkbPointZ, wkbLineString, wkbLineStringZ, wkbPolygon, wkbPolygonZM, wkbMultiPoint, wkbMultiPointZ,
168169
wkbMultiLineString, wkbMultiPolygon, wkbGeometryCollection, wkbPoint25D, wkbLineString25D, wkbPolygon25D, wkbMultiPoint25D,
@@ -197,8 +198,7 @@ export
197198
gunique, sortslicesperm,
198199
hampel, hampel!, lowess, whittaker,
199200

200-
Ginnerjoin, Gouterjoin, Gleftjoin, Grightjoin, Gcrossjoin, Gsemijoin, Gantijoin, spatialjoin,
201-
groupby, stats,
201+
Ginnerjoin, Gouterjoin, Gleftjoin, Grightjoin, Gcrossjoin, Gsemijoin, Gantijoin, spatialjoin, groupby, stats,
202202

203203
anaglyph,
204204
lazinfo, lazread, lazwrite, lasread, laswrite,
@@ -424,6 +424,7 @@ using .Laszip
424424
grdview(rand(Float32,32,32), Vd=2);
425425
grdinfo(mat2grid(rand(Float32,4,4)));
426426
Glix=gmt("grdmath", "-R0/10/0/10 -I2 X");
427+
gmt_grdinfo_C(Glix);
427428
grdcontour(Glix);
428429
grd2cpt(Glix);
429430
grd2xyz(Glix);

src/common_options.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function parse_R(d::Dict, cmd::String; O::Bool=false, del::Bool=true, RIr::Bool=
176176
opt_r = parse_r(d, "")[2]
177177
(opt_r == "") && (cmd *= " -r" * ((val.registration == 0) ? "g" : "p"))
178178
elseif (!isempty(val_str) && ((t = guess_T_from_ext(val_str)) == " -Tg" || t == " -Ti")) # A file name
179-
info::Matrix{Float64} = gmt("grdinfo -C " * val_str).data # Get the grid info
179+
info::Matrix{Float64} = gmt_grdinfo_C(val_str).data # Get the grid info
180180
opt_R = @sprintf(" -R%.12g/%.12g/%.12g/%.12g", info[1,1], info[1,2], info[1,3], info[1,4])
181181
(opt_I = parse_I(d, "", [:I :inc :increment :spacing], "I", true)) == "" &&
182182
(opt_I = @sprintf(" -I%.8g/%.8g", info[7], info[8])) # The grid increment
@@ -388,8 +388,8 @@ function opt_R2num(opt_R::String)::Vector{Float64}
388388
CTRL.pocket_R[2] = "$inc"
389389
elseif (opt_R != " -R" && opt_R != " -Rtight") # One of those complicated -R forms. Ask GMT the limits (but slow. It takes 0.2 s)
390390
# If opt_R is not a grid's name, we are f.
391-
((ind = findfirst("-R@", opt_R)) !== nothing) && return gmt("grdinfo " * opt_R[ind[3]:end] * " -C")[1:4] # should be a cache file
392-
(((f = guess_T_from_ext(opt_R)) == " -Tg") || f == " -Ti") && return gmt("grdinfo " * opt_R * " -C")[1:4] # any local file
391+
((ind = findfirst("-R@", opt_R)) !== nothing) && return gmt_grdinfo_C(opt_R[ind[3]:end])[1:4] # should be a cache file
392+
(((f = guess_T_from_ext(opt_R)) == " -Tg") || f == " -Ti") && return gmt_grdinfo_C(opt_R)[1:4] # any local file
393393

394394
(opt_R == " -R=WD") && return [-180.0, 180., -90., 90.] # World map. Shit is if [0 360] is wanted.
395395
kml::GMTdataset{Float64, 2} = gmt("gmt2kml " * opt_R, [0 0]) # for example, opt_R = " -RPT"
@@ -2740,7 +2740,7 @@ function get_cpt_set_R(d::Dict, cmd0::String, cmd::String, opt_R::String, got_fn
27402740
if (isa(arg1, GItype)) # GMT bug, -R will not be stored in gmt.history
27412741
range::Vector{Float64} = isa(arg1.range, Float64) ? vec(arg1.range) : vec(arg1.range[1:6]) # Beyond 6 can be a Time
27422742
elseif (cmd0 != "" && cmd0[1] != '@')
2743-
info = grdinfo(cmd0 * " -C"); range = vec(info.data)
2743+
info = gmt_grdinfo_C(cmd0); range = vec(info.data)
27442744
end
27452745

27462746
cpt_opt_T = ""
@@ -4637,8 +4637,7 @@ function regiongeog(GI::GItype)::Tuple
46374637
end
46384638
function regiongeog(fname::String)::Tuple
46394639
((prj = getproj(fname, wkt=true)) == "") && (@warn("Input grid/image has no projection info"); return ())
4640-
#info = grdinfo(fname, C=true); # It should also report the
4641-
info = gmt("grdinfo -C " * fname);
4640+
info = gmt_grdinfo_C(fname)
46424641
c = xy2lonlat([info.data[1] info.data[3]; info.data[2] info.data[4]]; s_srs=prj)
46434642
tuple(c...)
46444643
end

src/contourf.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ function contourf(cmd0::String, arg1, arg2, first::Bool, d::Dict{Symbol,Any})
151151
#isa(arg2, GMTcpt) ? d[:N] = arg2 : (isa(arg1, GMTcpt) ? d[:N] = arg1 : d[:N] = true)
152152
if (isempty(CPT) && isempty(CPT_arg))
153153
if (cmd0 != "")
154-
info = grdinfo(cmd0 * " -C")
154+
info = gmt_grdinfo_C(cmd0)
155155
C_inc, min, max = gen_contour_vals(info.data[5:6], C_int)
156156
else
157157
C_inc, min, max = gen_contour_vals(arg1, C_int)

src/gdal/gdal_tools.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ function gdaldem(indata, method::String, opts::Vector{String}=String[]; dest="/v
253253
append!(opts, ["-compute_edges", "-b", band])
254254
if ((val = find_in_dict(d, [:scale])[1]) === nothing)
255255
if (isa(indata, GMTgrid) && (occursin("longlat", indata.proj4) || occursin("latlong", indata.proj4)) ||
256-
gmt("grdinfo -Cn", indata).data[end] == 1)
256+
GMT.gmt_grdinfo_C(indata).data[end] == 1)
257257
append!(opts, ["-s", "111120"])
258258
end
259259
else

src/gdal_utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ by `grdinfo`. An unfortunate consequence of using either GMT or GDAL to inquire
488488
`x_inc, y_inc` when reading with GDAL, and `z_min, z_max` when reading with GMT.
489489
"""
490490
function getregion(input; pad=0, xSize=0, ySize=0, gridreg::Bool=false, sds::Int=0, GMT=false)::NTuple{6, Float64}
491-
(GMT == 1 && isa(input, String)) && return vec(grdinfo(input, C=:n).data)
491+
(GMT == 1 && isa(input, String)) && return vec(gmt_grdinfo_C(input).data)
492492
dataset = gd2gmt_helper(input, sds; short=true)[1]
493493
(xSize == 0) && (xSize = Gdal.width(dataset))
494494
(ySize == 0) && (ySize = Gdal.height(dataset))

src/gmt_main.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ end
236236
gmt_GMTcpt(cmd::String, args...)::Union{GMTcpt, Nothing} = gmt(cmd, args...)::Union{GMTcpt, Nothing}
237237
gmt_GMTdataset(cmd::String, args...)::Union{GMTdataset{Float64,2}, Vector{<:GMTdataset{Float64,2}}} = gmt(cmd, args...)
238238
gmt_GMTgrid(cmd::String, args...)::GMTgrid{Float32,2} = gmt(cmd, args...)::GMTgrid{Float32,2}
239+
gmt_grdinfo_C(name::String)::GMTdataset{Float64, 2} = gmt("grdinfo -C " * name)::GMTdataset{Float64, 2}
240+
gmt_grdinfo_C(GI::GItype)::GMTdataset{Float64, 2} = gmt("grdinfo -C ", GI)::GMTdataset{Float64, 2}
239241

240242
# -----------------------------------------------------------------------------------------------
241243
function gmt_restart(restart::Bool=true)

src/grdinfo.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,3 @@ function grdinfo_helper(cmd0::String, arg1; kwargs...)::Union{GMTdataset, String
8080
end
8181
return R
8282
end
83-
84-
# ---------------------------------------------------------------------------------------------------
85-
#grdinfo(arg1; kw...) = grdinfo("", arg1; kw...)

src/grdinterpolate.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function grdinterp_helper(cmd0::String, arg1; allcols::Bool=false, gdal=false, k
122122
common_grd(d, "grdinterpolate " * cmd, arg1..., arg2)
123123
else
124124
if (cmd0 != "" && !contains(cmd, " -R") && val !== nothing) # Since GMT will read layer-by-layer, better to limit to the region framing the points
125-
D = grdinfo(cmd0, C=true)
125+
D = gmt_grdinfo_C(cmd0)
126126
x_min = max(D[1], pts.ds_bbox[1]-D[9]*3); x_max = min(D[2], pts.ds_bbox[2]+D[9]*3)
127127
y_min = max(D[3], pts.ds_bbox[3]-D[10]*3); y_max = min(D[4], pts.ds_bbox[4]+D[10]*3)
128128
cmd *= " -R$x_min/$x_max/$y_min/$y_max"

src/grdvector.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ function parse_Q_grdvec(d::Dict, symbs::Array{<:Symbol}, len::String="", stop::S
178178
end
179179

180180
# ---------------------------------------------------------------------------------------------------
181-
get_grdinfo(grd::String, opt_R::String) = gmt("grdinfo -C" * opt_R * " " * grd).data
182-
get_grdinfo(grd::GMTgrid, opt_R::String) = gmt("grdinfo -C" * opt_R, grd).data
181+
get_grdinfo(grd::String, opt_R::String) = gmt_grdinfo_C(opt_R * " " * grd).data
182+
get_grdinfo(grd::GMTgrid, opt_R::String)::Matrix{Float64} = gmt("grdinfo -C" * opt_R, grd).data
183183

184184
# ---------------------------------------------------------------------------------------------------
185185
grdvector!(arg1, arg2; kw...) = grdvector(arg1, arg2; first=false, kw...)

src/imshow.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ function snif_GI_set_CTRLlimits(G_I)::Bool
251251
(isa(G_I, String) && (G_I[1] == '@' || startswith(G_I, "http"))) && return false # Remotes are very dangerous to sniff in
252252

253253
# Do not call grdinfo over grid/images already in memory
254-
range::Vector{Float64} = isa(G_I, String) ? vec(grdinfo(G_I, C=:n).data) : G_I.range[1:6]
254+
range::Vector{Float64} = isa(G_I, String) ? vec(gmt_grdinfo_C(G_I).data) : G_I.range[1:6]
255255
if ((isa(G_I, String) && range[2] != range[9] && range[4] != range[10]) ||
256256
(!isa(G_I, String) && range[2] != size(G_I, 2) && range[4] != size(G_I, 1)))
257257
CTRL.limits[1:4], CTRL.limits[7:10] = range[1:4], range[1:4]

0 commit comments

Comments
 (0)