How to write a resized GeoTiff in Matlab R2022a

2 次查看(过去 30 天)
I'm trying to write a resized geotiff using geotiffwrite in Matlab R2022a using the code below, which is partly taken from the documentation of geotiffwrite (it's in a loop as I will process more files in the future so i = 1 for now):
for i=1
[SE,Rse] = geotiffread(fullfile(DemFolder,Dem_Names{i})); % I'm using geotiffread instead of rea
SEinfo = geotiffinfo(fullfile(DemFolder,Dem_Names{i}));
[BE,Rbe] = geotiffread(file2);
BEinfo = geotiffinfo(file2);
[TempSE,TempRse] = mapresize(SE,Rse,2/BEinfo.PixelScale(1)
filename = 'OutputFile.tif';
key = SEinfo.GeoTIFFTags.GeoKeyDirectoryTag;
geotiffwrite(filename, TempSE,TempRse,'GeoKeyDirectoryTag',key);
end
This results in the following error:
Error in Tiff (line 660)
obj.FileID = tifflib('open',filename,mode);
Error in geotiffwrite>writeGeoTiffFile (line 1490)
tiffObj = Tiff(filename, writeMode);
Error in geotiffwrite (line 259)
writeGeoTiffFile(filename, A, TiffTags, GeoTiffTags, rpcTag,
isClassicTIFF);
I've tried to just read in and write a geotiff without resizing it, but that results in the same error. It does work without any issues in R2019a so I really don't know what the problem is.
Any help is greatly appreciated.

回答(1 个)

Vidip
Vidip 2023-12-27
I understand that the error you're encountering seems to be related to the Tiff function, which is used internally by geotiffwrite to create a TIFF file. The error message indicates that there's a problem opening the file, which could be due to various reasons such as file permissions, an invalid file path, or issues with the TIFF library.
Check File Permissions: Ensure that MATLAB has write permissions to the directory where you're trying to save the output TIFF file. Lack of permissions can prevent the file from being created.
Validate File Path: Verify that the filename variable contains a valid file path. You may want to use an absolute path to ensure that MATLAB is not trying to write to a location that doesn't exist or is not accessible.
Check for Open Files: Ensure that the file you're trying to write is not already open in another application, as this could lock the file and prevent MATLAB from writing to it.
For further information, refer to the documentation link below:

类别

Help CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by