How can I load a portion of a .tif file using readgeoraster?

6 ビュー (過去 30 日間)
Alessio
Alessio 2024 年 11 月 29 日
回答済み: prabhat kumar sharma 2025 年 1 月 10 日
I need to work with a .tif file containing elevation data relative to a region of the world. This file I got is too big to be loaded in MatLab and it saturates the memory, so I wanted to extract only a portion of it. I already know how to do it using imread, but since I want to collect all the information stored in the file I would prefer to use readgeoraster.
Do you know about a way to select a range of the picture to load using this function?
I can't load the .tif file because it's huge, but I can give you its info:
FileFormat: "GeoTIFF"
RasterSize: [85809 119862]
NumBands: 1
NativeFormat: "int16"
MissingDataIndicator: 32767
Categories: []
ColorType: "grayscale"
Colormap: []
RasterReference: []
CoordinateReferenceSystem: [1×1 geocrs]
Metadata: [1×1 struct]
Thanks in advance!

採用された回答

prabhat kumar sharma
prabhat kumar sharma 2025 年 1 月 10 日
Hello Alessio,
When dealing with large GeoTIFF files, readgeoraster in MATLAB is a suitable function because it allows you to work with geospatial data and extract specific portions without loading the entire file into memory. However, readgeoraster does not directly support reading a subset of the data by specifying row and column limits. Instead, you can use georasterinfo to get metadata and then readgeoraster to read specific regions using spatial referencing.
Here's a step-by-step guide on how to extract a specific portion of a GeoTIFF file using readgeoraster:
Step 1: Get GeoTIFF Information
First, obtain the metadata from the GeoTIFF file to understand its spatial referencing and coordinate system.
info = georasterinfo('your_large_file.tif');
Step 2: Define the Region of Interest
Based on the spatial referencing, define the geographic coordinates or pixel indices of the area you want to extract. Suppose you know the geographic bounds (latitude and longitude) of the region you are interested in.
Step 3: Read the Desired Region
Use the spatial referencing to read only the desired region. You can specify a bounding box in geographic coordinates or pixel indices.
% Define geographic limits (example values)
latlim = [minLatitude, maxLatitude];
lonlim = [minLongitude, maxLongitude];
% Read the specified region
[A, R] = readgeoraster('your_large_file.tif', 'LatitudeLimits', latlim, 'LongitudeLimits', lonlim);
  • atitudeLimits and LongitudeLimits: These options allow you to specify the geographic bounding box of the region you want to extract. Replace minLatitude, maxLatitude, minLongitude, and maxLongitude with the actual coordinates of your region of interest.
  • A: The output matrix containing the elevation data for the specified region.
  • R: The spatial referencing object for the extracted data.
I hope it helps!

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by