Skip to content

Commit 13295cf

Browse files
authored
Merge pull request #1997 from GenericMappingTools/dgt-check-bb
In dgt_lidar, check if lon/lat is swapped and if it falls in Portugal
2 parents fdb71fe + 20279ac commit 13295cf

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

ext/GMTDGTLidarExt/GMTDGTLidarExt.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,25 @@ module GMTDGTLidarExt
185185
Float64(delay), collection, dry, mosaic, Float64(inc), method, latest, Int(verbose), 0, zoom, compress, proj)
186186
end
187187

188+
# --------------------------------------------------------------------------------------------------------------------------
189+
function _pt_overlaps(b::NTuple{4,Float64})
190+
pt_bbox = (-9.6, -6.1, 36.9, 42.2) # Portugal bounding box: [min_lon, max_lon, min_lat, max_lat]
191+
b[1] <= pt_bbox[2] && b[2] >= pt_bbox[1] && b[3] <= pt_bbox[4] && b[4] >= pt_bbox[3]
192+
end
193+
194+
function _validate_pt_bbox(b::NTuple{4,Float64})::NTuple{4,Float64}
195+
_pt_overlaps(b) && return b
196+
bs = (b[3], b[4], b[1], b[2])
197+
_pt_overlaps(bs) && @warn("Coordinates probably given as lat/lon INSTEAD of lon/lat.") && return bs
198+
error("Coordinates $b do not intersect Portugal (-9.6, -6.1, 36.9, 42.2)")
199+
end
200+
188201
# --------------------------------------------------------------------------------------------------------------------------
189202
function _dgt_lidar(bbox, user::String, password::String, save::Bool, output_dir::String, delay::Float64, collection::String,
190203
dry::Bool, mosaic::String, inc::Float64, method::String, latest::Bool, verbose::Int,
191204
_neighbors, _zoom::Int, compress::String, proj::String)
192205

206+
bbox = _validate_pt_bbox(NTuple{4,Float64}(bbox))
193207
_valid = ("LAZ", "MDT-50cm", "MDS-50cm", "MDT-2m", "MDS-2m")
194208
_coll = uppercase(collection) # Because of Core.Boxes
195209
_canonical = findfirst(c -> uppercase(c) == _coll, _valid)

test/test_dgt.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ const INTEGRATION_BBOX = [-9.11, -9.0877, 38.728, 38.735]
392392

393393
if isfile(joinpath(homedir(), ".dgt"))
394394
@testset "DGT LIDAR Integration" begin
395-
#mktempdir() do tmpdir
396395
tmpdir = mktempdir()
397396

398397
# --- dgt_lidar: auth + search, no download (primary bbox form) ---
@@ -499,6 +498,6 @@ if isfile(joinpath(homedir(), ".dgt"))
499498
GMT.dgt_lidar(INTEGRATION_BBOX; output_dir=tmpdir, verbose=3)
500499
@test length(readdir(coll_dir)) == n_before
501500
end
502-
#end
503501
end
502+
@test_throws ErrorException("Coordinates (10.1, 10.1, 10.0, 10.1) do not intersect Portugal (-9.6, -6.1, 36.9, 42.2)") GMT.dgt_lidar([10.1,10.1],[10., 10.1])
504503
end

test/test_misc.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227
image_alpha!(I, alpha_ind=5);
228228
image_alpha!(I, alpha_vec=round.(UInt32,rand(6).*255));
229229
@info "before 3"
230-
image_alpha!(I, alpha_band=round.(UInt8,rand(27,27).*255))
230+
@test_nowarn image_alpha!(I, alpha_band=round.(UInt8,rand(27,27).*255))
231231
img = mat2img(rand(UInt8, 6, 6, 3));
232232
mask = fill(UInt8(0), 6, 6);
233233
mask[3:4,3:4] .= 255;
@@ -243,7 +243,7 @@
243243

244244
GMT.resetGMT()
245245
try
246-
upGMT()
246+
@test_nowarn upGMT()
247247
catch
248248
end
249249
image_cpt!(I, C)

0 commit comments

Comments
 (0)