필터 지우기
필터 지우기

Error in geotiff display

조회 수: 4 (최근 30일)
Ashrumochan Mohanty
Ashrumochan Mohanty 2022년 5월 14일
답변: Siraj 2023년 9월 29일
clc
clear all
filename='E:\Data\netCDF\rainfall\_Clim_Pred_LRF_New_RF25_IMD0p251990.nc';
%ncdisp(filename);
lat=ncread(filename,'LATITUDE');
Error using internal.matlab.imagesci.nc/openToRead
Could not open E:\Data\netCDF\rainfall\_Clim_Pred_LRF_New_RF25_IMD0p251990.nc for reading.

Error in internal.matlab.imagesci.nc (line 124)
this.openToRead();

Error in ncread (line 69)
ncObj = internal.matlab.imagesci.nc(ncFile);
lon=ncread(filename,'LONGITUDE');
transpose_lon=lon';
days=ncread(filename,'TIME');
pr=ncread(filename,'RAINFALL');
for count = 1: size(lat)
lon_array(count,:)=transpose_lon;
end
for count = 1: size(lon)
lat_array(:,count)=lat;
end
value_array=pr (:,:,2);
% load the value matrix and lat and lon arrays
value = value_array';
lat_referance = lat_array';
lon_referance = lon_array';
% Create the referencing matrix (R)
R = georasterref('RasterSize',size(value), ...
'LatitudeLimits',[min(lat) max(lat)],'LongitudeLimits',[min(lon) max(lon)]);
outfilename = 'India3.tif';
geotiffwrite(outfilename, value, R);
% [A,R] = readgeoraster(outfilename);
% mapshow(A,R);
figure
mapshow India3.tif
I want to create a geo referanced tiff file(geotiff) from a netCDF file. and i have created sucessfully as I have checked it in a GIS software. Now I want to display the geotiff file. But it is not showing. I am getting some error. I have attached the pic and code.

답변 (1개)

Siraj
Siraj 2023년 9월 29일
Hi!
I understand that you have created a geotiff file and saved it using the "geotiffwrite" function. The spatially referenced matrix "R" was created using the "georasterref" function. However, when you try to read the file and display its data using the "mapshow" function, an error occurs.
The error you are encountering indicates that there might be an issue with how the file was written or with the spatial reference matrix. To resolve this, you can try creating the reference matrix using either the "MapCellsReference" or "MapPostingsReference" type. For example.
R = georefpostings([0 1], [0 1], size(imageData));
You can refer to the following link to understand the expected format of the "R" matrix for the "mapshow" function and explore different functions available to create the "R" matrix:
As a workaround, you can try using the "geoshow" function instead of "mapshow" to display the data from the geotiff file. To understand how to use "geoshow" and its functionality, you can refer to the following link:
In the below provided code, the "geoshow" function is used to display the data from the geotiff file, and it does not produce any errors.
% Generate random image data
imageData = rand(100, 100);
% Define spatial reference information
R = georasterref('RasterSize', size(imageData), 'LatitudeLimits', [0 1], 'LongitudeLimits', [0 1]);
% Create GeoTIFF file
filename = 'random_image.tif';
geotiffwrite(filename, imageData, R);
% Display confirmation message
disp(['GeoTIFF file saved as: ' filename]);
GeoTIFF file saved as: random_image.tif
% Read the GeoTIFF file
[A, R] = readgeoraster(filename);
% Display the GeoTIFF image using geoshow
figure
geoshow(A, R, "DisplayType","mesh");
Hope this helps.

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by