File tree Expand file tree Collapse file tree 5 files changed +81
-0
lines changed Expand file tree Collapse file tree 5 files changed +81
-0
lines changed Original file line number Diff line number Diff line change 138
138
139
139
copyfiles (drvname:: AbstractString , new:: AbstractString , old:: AbstractString ) =
140
140
copyfiles (getdriver (drvname), new, old)
141
+
142
+ """
143
+ extensions()
144
+
145
+ Returns a `Dict{String,String}` of all of the file extensions that can be read by GDAL,
146
+ with their respective drivers shortname.
147
+ """
148
+ function extensions ()
149
+ extdict = Dict {String,String} ()
150
+ for i in 1 : ndriver ()
151
+ driver = getdriver (i)
152
+ if ! (driver. ptr == C_NULL )
153
+ # exts is a space-delimited list in a String, so split it
154
+ for ext in split (metadataitem (driver, " DMD_EXTENSIONS" ))
155
+ extdict[" .$ext " ] = shortname (driver)
156
+ end
157
+ end
158
+ end
159
+ return extdict
160
+ end
161
+
162
+ """
163
+ extensiondriver(filename::AbstractString)
164
+
165
+ Returns a driver shortname that matches the filename extension.
166
+
167
+ So `extensiondriver("/my/file.tif") == "GTiff"`.
168
+ """
169
+ function extensiondriver (filename:: AbstractString )
170
+ split = splitext (filename)
171
+ extensiondict = extensions ()
172
+ ext = split[2 ] == " " ? split[1 ] : split[2 ]
173
+ if ! haskey (extensiondict, ext)
174
+ throw (ArgumentError (" There are no GDAL drivers for the $ext extension" ))
175
+ end
176
+ return extensiondict[ext]
177
+ end
Original file line number Diff line number Diff line change @@ -70,6 +70,23 @@ Fetch metadata. Note that relatively few formats return any metadata.
70
70
metadata (obj; domain:: AbstractString = " " ) =
71
71
GDAL. gdalgetmetadata (obj. ptr, domain)
72
72
73
+ """
74
+ metadataitem(obj, name::AbstractString, domain::AbstractString)
75
+
76
+ Fetch single metadata item.
77
+
78
+ ### Parameters
79
+ * `name` the name of the metadata item to fetch.
80
+ * `domain` (optional) the domain to fetch for.
81
+
82
+ ### Returns
83
+ The metadata item on success, or an empty string on failure.
84
+ """
85
+ function metadataitem (obj, name:: AbstractString ; domain:: AbstractString = " " )
86
+ item = GDAL. gdalgetmetadataitem (obj. ptr, name, domain)
87
+ return item === nothing ? " " : item
88
+ end
89
+
73
90
"""
74
91
setconfigoption(option::AbstractString, value)
75
92
Original file line number Diff line number Diff line change @@ -31,5 +31,6 @@ include("remotefiles.jl")
31
31
include (" test_geos_operations.jl" )
32
32
include (" test_cookbook_geometry.jl" )
33
33
include (" test_cookbook_projection.jl" )
34
+ include (" test_utils.jl" )
34
35
end
35
36
end
Original file line number Diff line number Diff line change 72
72
)
73
73
end
74
74
end
75
+
76
+ @testset " Test extensions list" begin
77
+ exts = AG. extensions ()
78
+ @test exts[" .tif" ] == " GTiff"
79
+ @test exts[" .grb" ] == " GRIB"
80
+ @test exts[" .geojson" ] == " GeoJSON"
81
+ end
82
+
83
+ @testset " Test getting extensiondriver" begin
84
+ @test AG. extensiondriver (" filename.tif" ) == " GTiff"
85
+ @test AG. extensiondriver (" .tif" ) == " GTiff"
86
+ @test AG. extensiondriver (" filename.asc" ) == " AAIGrid"
87
+ @test AG. extensiondriver (" .asc" ) == " AAIGrid"
88
+ @test_throws ArgumentError AG. extensiondriver (" .not_an_extension" )
89
+ end
90
+
Original file line number Diff line number Diff line change
1
+ using Test
2
+ import GDAL
3
+ import ArchGDAL; const AG = ArchGDAL
4
+
5
+ @testset " metadataitem" begin
6
+ driver = AG. getdriver (" DERIVED" )
7
+ @test AG. metadataitem (driver, " DMD_EXTENSIONS" ) == " "
8
+ driver = AG. getdriver (" GTiff" )
9
+ @test AG. metadataitem (driver, " DMD_EXTENSIONS" ) == " tif tiff"
10
+ end
You can’t perform that action at this time.
0 commit comments