How to generate an image from a shapefile with the same projection of a GeoTIFF?

13 views (last 30 days)
Hi,
I'm looking for a way to generate an image with the same projection of a GeoTIFF that it is independent of the shapefile (they only share the same world area).
I found a code that can generate a binary mask with the same GeoTIFF projection:
R = geotiffinfo('r_cd_geocod.tif']);
[x,y] = pixcenters(R);
[X,Y] = meshgrid(x,y);
roi = shaperead('GUF_shape_subset_fixed_repaired_wDAMAGE.shp']);
for i = 1:length(roi)
rx = roi(i).X;
ry = roi(i).Y;
mask_temp = inpolygon(X,Y,rx,ry);
mask = mask | mask_temp;
end
obtaining that:
However, I would like to associate on every polygon the corresponding damage_idx attribute:
in order to obtain something like that:
I hope that someone can solve my problem. Thank you very much for the help.

Accepted Answer

Emanuele Ferrentino
Emanuele Ferrentino on 1 Jun 2020
Edited: Emanuele Ferrentino on 1 Jun 2020
Hi all,
I solved in this way
GT = zeros(size(r_cd,1),size(r_cd,2),'logical');
for i = 1:length(roi)
rx = roi(i).X;
ry = roi(i).Y;
GT_temp = inpolygon(X,Y,rx,ry).*roi(i).damage_idx;
GT = GT + GT_temp;
end

More Answers (0)

Community Treasure Hunt

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

Start Hunting!