Issue when masking a raster map by a shape file using 'vec2mtx'

25 Ansichten (letzte 30 Tage)
Mohammad Gohardoust
Mohammad Gohardoust am 19 Jul. 2017
Beantwortet: Pat Canny am 2 Feb. 2026 um 13:48
Hi, I'm trying to mask a raster map by a shape file. The problem is at the end the masked region is shifted. I think it should be something wrong with 'vec2mtx'. Does anyone have a suggestion on this? The code is simply:
roi = shaperead(shape_name);
info = geotiffinfo(map_name);
[A, R] = geotiffread(map_name);
zone = '38S';
[Latlim, Lonlim] = projinv(info, R.XWorldLimits, R.YWorldLimits);
refmat = makerefmat('RasterSize', R.RasterSize, 'Latlim', Latlim, ...
'Lonlim', Lonlim, 'ColumnsStartFrom', R.ColumnsStartFrom, ...
'RowsStartFrom', R.RowsStartFrom);
rx = roi.X(1:end-1);
ry = roi.Y(1:end-1);
[shape_lat, shape_lon] = projinv(info, rx, ry);
[A1, R2] = vec2mtx(shape_lat, shape_lon, A, refmat, 'filled');
fin_idx = (A1 ~= 2);
A2 = A;
A2(fin_idx) = NaN;
geotiffwrite(out_map_name, A2, R,...
'GeoKeyDirectoryTag', info.GeoTIFFTags.GeoKeyDirectoryTag);
  1 Kommentar
Mohammad Gohardoust
Mohammad Gohardoust am 21 Jul. 2017
The above maps are from Landsat, I tested this method on Modis maps with much lower resolution which seems to work.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Pat Canny
Pat Canny am 2 Feb. 2026 um 13:48
I recommend contacting MathWorks Technical Support. This question requires more information.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by