读写栅格
利用geotiffread或读栅格imread读取,区别在于geotiffread能同时读取栅格的数值和地理参考坐标,而imread需要分两步,首先利用地理参考信息,再读取图像。
geotiffread


运行[X,cmap,refmat,bbox]=geotiffread('E:/code/data/stationRaster.tif');

其中,X是数据网格,cmap是颜色映射,bbox是边界,refmat是referencing matrix,用于相互转换栅格行列索引和地理坐标。

简单例子
stationfile='E:/code/data/stationRaster.tif';
%利用geotiffread读取
[staionsRaster,Rstation] = geotiffread(stationfile);
imread

个人理解,和geotiffread的区别在于geotiffread能直接读出数据值和地理参考信息,而imread只是将tiff文件当成图片处理。后期如果要用到地理参考信息,可用georasterref(投影坐标)和worldfileread(地理坐标)函数来获取。
Rstation = georasterref('RasterSize',size(staionsRaster), 'Latlim',[30 34], 'Lonlim', [118 120]);
stationfile='E:/code/data/stationRaster.tif';
staionsRaster=imread(stationfile);
对应栅格写法
geotiffwrite和imwrite


stationfile='E:/code/data/stationRaster.tif';
[staionsRaster,Rstation] = geotiffread(stationfile);
info=geotiffinfo(stationfile);
savepath='E:\code\result\';
geotiffwrite([savepath,'新保存的图像.tif'], staionsRaster, Rstation, 'GeoKeyDirectoryTag', info.GeoTIFFTags.GeoKeyDirectoryTag);
可视化展示
geoshow或mapshow。区别在于geoshow中的R是georasterref获得的对象,绘制的可视化图是经纬度坐标,而mapshow是geotiffread获得的地理参考信息(下图中的Rstation),实际是投影信息,绘制的可视化图以长度为单位。

stationfile='E:/code/data/stationRaster.tif'; %加油站点
[staionsRaster,Rstation] = geotiffread(stationfile);
R= georasterref('RasterSize',size(staionsRaster), 'Latlim',[30 34], 'Lonlim', [118 120]);
%geoshow,设置DisplayType显示颜色
figure
geoshow(staionsRaster,R,'DisplayType', 'texturemap');
%mapshow
figure
mapshow(staionsRaster,Rstation,'DisplayType', 'texturemap');


网友评论