masking geotiff Landsat data using shapefile
조회 수: 11 (최근 30일)
이전 댓글 표시
I have Landsat Image and shape file , I want to masking this data using a shape file but getting error because my (data model type projected not geographic) So the mask hallways contain zeros... I will write my code and Images of references.
File_Name = 'LC08_L1TP_01_T1_B4.TIF';
[I,R1]=geotiffread(File_Name);
R2 = geotiffinfo(File_Name);
[x,y] = pixcenters(R2);
[X,Y] = meshgrid(x,y);
roi = shaperead('shapefile.shp');
rx = roi.X(1:end-1);
ry = roi.Y(1:end-1);
mask = inpolygon(X,Y,rx,ry);
I2 = bsxfun(@times, I, cast(mask,class(I)));
댓글 수: 2
답변 (1개)
Junxue Zhang
2019년 8월 1일
I think your input tif file and shapefile do not share the same map projection, so that their boundary boxes do not match. First you should reproject your shapefile to the new map projection that your raster uses. And then you codes will take effect. Also, you can't ignore the last values in roi.X and roi.Y, because these values make polygon closed.
BTW, if your shapefile contains multiple polygons, I recommend you to do a for loop for the variable roi, like:
mask = zeros(5000,5000,'logical');
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
댓글 수: 1
Emanuele Ferrentino
2020년 5월 28일
Hi,
In this way I can generate a binary image from a shapefile with the same projection of my geotiff.
I need to do another step. I'm looking for a way to associate a value (damage_idx) on the binary image previously obtained. I have the following shapefile:
roi =
64×1 struct array with fields:
Geometry
BoundingBox
X
Y
DN
Prov
Com
Localita
Lat1
Lon1
damage_idx
Anyone knows how to do?
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!