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

25 vues (au cours des 30 derniers jours)
Mohammad Gohardoust
Mohammad Gohardoust le 19 Juil 2017
Réponse apportée : Pat Canny le 2 Fév 2026 à 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 commentaire
Mohammad Gohardoust
Mohammad Gohardoust le 21 Juil 2017
The above maps are from Landsat, I tested this method on Modis maps with much lower resolution which seems to work.

Connectez-vous pour commenter.

Réponses (1)

Pat Canny
Pat Canny le 2 Fév 2026 à 13:48
I recommend contacting MathWorks Technical Support. This question requires more information.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by