2

I have an URL to a TIFF file:

url = "https://copernicus-dem-30m.s3.amazonaws.com/Copernicus_DSM_COG_10_N59_00_E010_00_DEM/Copernicus_DSM_COG_10_N59_00_E010_00_DEM.tif"

I can get the dimensions of this file via:

src = rasterio.open(url)
r = src.read(1)
r.shape

which returns (3600, 2400).

Is there a way or getting these two numbers without the src.read(1) line?

It seems like a waste to read all the raster in if I only want to get the dimensions of it.

3

You don't need to read the file in:

import rasterio as rio
# Remote file as an example:
url="/vsicurl/https://copernicus-dem-30m.s3.amazonaws.com/Copernicus_DSM_COG_10_N59_00_E010_00_DEM/Copernicus_DSM_COG_10_N59_00_E010_00_DEM.tif"
s=rio.open(url)
print(s.width, s.height)

or using the plain GDAL bindings:

from osgeo import gdal 
url="/vsicurl/https://copernicus-dem-30m.s3.amazonaws.com/Copernicus_DSM_COG_10_N59_00_E010_00_DEM/Copernicus_DSM_COG_10_N59_00_E010_00_DEM.tif"
g = gdal.OpenEx(url)
print(g.RasterXSize, g.RasterYSize)

Both of these incantations will return 2400 x 3600 (not difference in order to numpy array).

3
import rasterio
src = rasterio.open(url)
print(src.height)
3600
print(src.width)
2400

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.