美文网首页
Matlab 读写栅格及可视化

Matlab 读写栅格及可视化

作者: 吵吵人 | 来源:发表于2019-11-19 21:42 被阅读0次

读写栅格

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

geotiffread

其中,A是记录栅格数值的矩阵,R是空间参考对象。

运行[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);

可视化展示

geoshowmapshow。区别在于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');
geoshow mapshow

相关文章

网友评论

      本文标题:Matlab 读写栅格及可视化

      本文链接:https://www.haomeiwen.com/subject/lebgictx.html