matlab - 将经纬度坐标投影到栅格以获得这些坐标处的像素值
问题描述
我们有一个地理参考的栅格文件和一个纬度-经度坐标列表,我们希望在该栅格文件的顶部绘制这些坐标以获得这些坐标处的栅格值。
这是坐标列表:
mapshow(lon,lat,'DisplayType','point') %x,y
当然,经度介于 -180 和 +180 之间,纬度介于 -90 和 +90 之间。
这是光栅文件:
proj = geotiffinfo('global2001.tif');
[raster_tiff,cmap_tiff,reference_tiff] = geotiffread('global2001.tif');
figure
mapshow(raster_tiff,cmap_tiff,reference_tiff)
proj = FileModDate: '20-nov-2018 14:15:52'
FileSize: 121625752
Format: 'tif'
FormatVersion: []
Height: 40032
Width: 80062
BitDepth: 8
ColorType: 'indexed'
ModelType: 'ModelTypeProjected'
PCS: ''
Projection: ''
MapSys: ''
Zone: []
CTProjection: 'CT_Sinusoidal'
ProjParm: [7×1 double]
ProjParmId: {7×1 cell}
GCS: 'WGS 84'
Datum: 'World Geodetic System 1984'
Ellipsoid: 'WGS 84'
SemiMajor: 6378137
SemiMinor: 6.3568e+06
PM: 'Greenwich'
PMLongToGreenwich: 0
UOMLength: 'metre'
UOMLengthInMeters: 1
UOMAngle: 'degree'
UOMAngleInDegrees: 1
TiePoints: [1×1 struct]
PixelScale: [3×1 double]
SpatialRef: [1×1 map.rasterref.MapCellsReference]
RefMatrix: [3×2 double]
BoundingBox: [2×2 double]
CornerCoords: [1×1 struct]
GeoTIFFCodes: [1×1 struct]
GeoTIFFTags: [1×1 struct]
现在我们使用与栅格文件相同的投影来投影坐标:
mstruct = geotiff2mstruct(proj);
% get current axis
axesm('MapProjection',mstruct.mapprojection,'Frame','on')
h=get(gcf,'CurrentAxes');
assert(ismap(h)==1,'Current axes must be map axes.')
mstruct=gcm;
[x,y] = mfwdtran(mstruct,lat,lon,h,'none');
figure
mapshow(x,y,'DisplayType','point') %x,y
问题是投影坐标从-3到+3,从-1到+1,光栅文件中的轴从-2到+2但是是7的幂,所以如果我们把这些点画在上面在该栅格中,我们将所有内容视为大西洋某处的一个点。
最终,我们想使用函数 latlon2pix 来获取每个坐标点的像素值,但首先,我们需要能够将这两个东西放在一起。有任何想法吗?
geoshow 功能不起作用。我们有足够的内存...
解决方案
我建议这样做:
% assigning reference for tif file
proj = geotiffinfo('global2001.tif');
% reading the tif into raster_tiff, storing the colormap, save the meta data
[raster_tiff,cmap_tiff,reference_tiff] = geotiffread('global2001.tif');
投影可以使用projfwd完成,投影矩阵存储在变量 proj 中。然后,数据点将以栅格文件的(此处为正弦)地图坐标表示。
% using the projection matrix (proj.RefMatrix) and computing the raster coordinates in meters
[x,y] = projfwd(proj,lat,lon);
使用mapshow one 可以在顶部绘制两个数据集。
mapshow(raster_tiff,cmap_tiff,reference_tiff);
mapshow(x,y,'DisplayType', 'point', 'Color', 'm',...
'MarkerEdgeColor', 'auto');
推荐阅读
- android - 无法从 api 获取数据,Future 总是返回 null - 颤振
- ios - 运行 React-Native 时,运行时尚未准备好进行调试
- python - 只获取最后的数字(正则表达式)
- python - 如何在python中使用break结束while循环?
- flutter - 更新到 Android Studio 4.2 后,查找和替换都不起作用
- flutter - 使用 Flutter 交换 GridItens 和计数移动
- html - 用 vh 固定的位置在 chrome 上无法正常工作,有什么帮助吗?
- javascript - 为什么更新前的mongo db响应值
- unity3d - 在没有 Bolt 的情况下使用统一
- css - Why can't I margin the div, why do I have to margin the child to margin the div?