Read/write georeferenced image

37 ビュー (過去 30 日間)
Massimo Zanetti
Massimo Zanetti 2022 年 9 月 28 日
回答済み: Yan Tong 2023 年 8 月 16 日
Hi, here I am wondering why this simple operation of reading a georeferenced .tif image and writing some results in the same georeferenced framework is so difficult. Here is my example:
[A,R] = readgeoraster("input_image.tif");
O = f(A) %any operation you like
geotiffwrite("output_image.tif",O,R);
This gives the error:
Error using geotiffwrite
The input, R, is a map.rasterref.MapCellsReference object indicating that you are working in a projected coordinate system. If so, then specify a projected coordinate system by setting the appropriate values for the 'CoordRefSysCode' or 'GeoKeyDirectoryTag' optional parameters.
But the input image includes the Coordinate Reference System Code (which is EPSG:32632), and the geotiffinfo function confirms that, as I have among other values: PCS: WGS 84 / UTM Zone 32N, which is the same as EPSG:32632.
So, do we have two Matlab functions incompatible each other? How am I supposed to automatically save the result without manually input 'CoordRefSysCode',32632 to the geotiffwrite function?
Thanks

採用された回答

Kevin Holly
Kevin Holly 2022 年 9 月 28 日
Can you try this below?
[A,R] = readgeoraster('input_image.tif');
O = A*2; %any operation you like
info = geotiffinfo('input_image.tif');
key = info.GeoTIFFTags.GeoKeyDirectoryTag;
geotiffwrite("output_image.tif",O,R,'GeoKeyDirectoryTag',key);
  1 件のコメント
Massimo Zanetti
Massimo Zanetti 2022 年 9 月 29 日
Thank you Kevin, this works fine, of course. The same would be using 'CoordRefSysCode',info.GeoTIFFCodes.PCS
I find it strange that readgeoraster function is not able to handle it on its own. It is indeed supposed to read georeferenced data but it cannot resolve projections. Working with georeferenced images, having them projected is the most common situation. This probably requires a fix.
Thanks again,
Massimo

サインインしてコメントする。

その他の回答 (1 件)

Yan Tong
Yan Tong 2023 年 8 月 16 日
You can try this!
[A,R] = readgeoraster(infilename);
info = geotiffinfo('input_image.tif');
geoTags = info.GeoTIFFTags.GeoKeyDirectoryTag;
tiffTags = struct('TileLength',1024,'TileWidth',1024);
geotiffwrite(outfilename,your_outputtiff,R,'TiffType','bigtiff', ...
'GeoKeyDirectoryTag',geoTags, ...
'TiffTags',tiffTags)

カテゴリ

Help Center および File ExchangeImport, Export, and Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by