Skip to content

Commit 2ed97c6

Browse files
authored
Add a new method getsize(fname::String) (#1913)
1 parent faeb505 commit 2ed97c6

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/utils.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,18 @@ function getsize(GI::GItype)
12701270
(GI.layout != "" && GI.layout[2] == 'C') ? (size(GI,2), size(GI,1)) : (length(GI.x), length(GI.y)) .- GI.registration
12711271
end
12721272

1273+
# ------------------------------------------------------------------------------------------------------
1274+
"""
1275+
width, height = getsize(fname::String) -> Tuple(Int, Int)
1276+
1277+
Return the width and height of the grid or image from the file `fname`.
1278+
"""
1279+
function getsize(fname::String)
1280+
!isfile(fname) && error("File $GI does not exist")
1281+
ds = Gdal.read(fname)
1282+
return Gdal.width(ds), Gdal.height(ds)
1283+
end
1284+
12731285
# ------------------------------------------------------------------------------------------------------
12741286
"""
12751287
nrows, ncols, nseg = getsize(D::GDtype) -> Tuple(Int, Int, Int)

0 commit comments

Comments
 (0)