How can I set the NoData value using Geotiffwrite

42 ビュー (過去 30 日間)
Matthew Cooper
Matthew Cooper 2015 年 10 月 13 日
回答済み: Zhou Zhiling 2024 年 10 月 5 日
I have MATLAB matrices that contain NaN values. These are raster data that contain NaN values (the NaN values are an ocean mask). I use geotiffwrite to write them to .tif files, but when I load the .tif files into ArcMap to create a map, it seems that the NaN values have been replaced with -Inf and +Inf (which ArcMap displays as something like -1.38e-38 and 1.38e38). Arc has tools for setting NoData, but they are in the Spatial Analyst toolbox that I do not have authorized.
In general, it is not clear from the documentation how geotiffwrite handles NaN values. There should be a tag in the GeoKeyDirectory to set the value of NoData, but there doesn't appear to be one.
How can I set the NoData value in the R spatial referencing object (or otherwise) so that when I export a .tif file from MATLAB using geotiffwrite, any and all other spatial software will recognize the NoData value (e.g. R, Arc, QGis, GRass, etc).
  1 件のコメント
Qian
Qian 2024 年 3 月 3 日
I made it using GDAL, following the tutorial: https://lixuworld.blogspot.com/2016/06/matlabgdal-add-nodata-tag-to.html

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

回答 (3 件)

Chad Greene
Chad Greene 2015 年 10 月 13 日
編集済み: Chad Greene 2015 年 10 月 13 日
For most of the GeoTIFFs I've used, NaNs have been set to the value -32767. If you're saving matrix Z that has NaN values in it, try
Z(isnan(Z)) = -32767;
before saving as a GeoTIFF. I'm not sure, but Arc may automatically interpret this correctly.
  1 件のコメント
Matthew Cooper
Matthew Cooper 2015 年 10 月 14 日
編集済み: Matthew Cooper 2016 年 5 月 24 日
Thanks for the suggestion, but unfortunately it doesn't work.
My temporary solution is to write out the geotiff files using MATLAB, and then I have to run a secondary script in R where I simply read in the geotiff files written by Matlab and then I re-write them in R using "writeRaster" which is in the "raster" package. The "writeRaster" function sets the NoData tag directly, and when I open up the file in Arc, click on Properties, there is a value (-1.7e+308) for the "NoData" property.
UPDATE: One can choose any number they wish when writing the raster in Matlab, and then use the Set Null tool in Arc. Just keep in mind that when you enter the conditional statement, you don't use double equals i.e. ==, use single. For example, use "VALUE" = -32767 not "VALUE == -32767.

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


Maddie Harasyn
Maddie Harasyn 2017 年 11 月 27 日
Hey!
I know this question was asked two years ago, however I thought I would provide an update for others who may be in the same situation.
Arc uses the value -9999 for NaN values in rasters, so you could use the same formula as Chad suggested above, just replace the value. I found that in certain circumstances, Arc doesn't recognize this as the NaN value. To fix this, before adding the GeoTiff as a layer in your map, right-click the layer in the Catalog, click properties, and then look for 'NoData Value' under 'Raster Information'. Click the 'Edit...' button, and then change the NoData Value to -9999.
No tool use required! Hopefully this can help out others processing Arc rasters in MATLAB.

Zhou Zhiling
Zhou Zhiling 2024 年 10 月 5 日
Supplementary from 2024, we can set the value -9999 (or any other value) to Nodata using the raster properties tool in the gis toolbox. So we can set the NAN value to -9999 (or any other value) when exporting from matlab.

カテゴリ

Help Center および File ExchangeData Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by