Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let gmtread deal with ogr zipped files (like *.shp.zip) #1236

Merged
merged 1 commit into from
Aug 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/gmtreadwrite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,17 @@ function gmtread(_fname::String; kwargs...)
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
if (opt_T == " -To" && fname[1] == '@') # Because GMT ogrread does not know the '@' mechanism.
if (opt_T == " -To" && fname[1] == '@') # Because GMT ogrread does not know the '@' mechanism.
fname = joinpath(readlines(`gmt --show-userdir`)[1], "cache", fname[2:end])
!isfile(fname) && error("File $fname does not exist in cache.")
elseif (opt_T == " -Toz") # Means we got a zipped ogr file
fname, opt_T = "/vsizip/" * fname, " -To"
end
else
opt_T = opt_T[1:4] # Remove whatever was given as argument to type kwarg
opt_T = opt_T[1:4] # Remove whatever was given as argument to type kwarg
end

if (opt_T == " -Ti" || opt_T == " -Tg") # See if we have a mem layout request
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)
# MUST TAKE SOME ACTION HERE. FOR IMAGES I THINK ONLY THE "I" FOR IMAGES.JL IS REALLY POSSIBLE
Expand Down Expand Up @@ -270,7 +272,11 @@ end
# ---------------------------------------------------------------------------------
function guess_T_from_ext(fname::String)::String
# Guess the -T option from a couple of known extensions
ext = splitext(fname)[2]
fn, ext = splitext(fname)
if (ext == ".zip") # Accept ogr zipped files, e.g., *.shp.zip
((out = guess_T_from_ext(fn)) == " -To") && return " -Toz"
end

(length(ext) > 8 || occursin("?", ext)) && return (occursin("?", ext)) ? " -Tg" : "" # A SUBDATASET encoded fname?
ext = lowercase(ext[2:end])
((ext == "jp2" || ext == "tif" || ext == "tiff") && (!isfile(fname) && !startswith(fname, "/vsi") &&
Expand Down
Loading