- https://www.mathworks.com/help/map/ref/shaperead.html
- https://www.mathworks.com/help/map/ref/readgeoraster.html
- https://www.mathworks.com/help/matlab/ref/inpolygon.html
Extracting Maximum pixel value from a raster (Canopy Height Model) for multiple polygons in a shapefile
3 次查看(过去 30 天)
显示 更早的评论
I have a shape file with approx 600 polygon representing each tree and i have generated canopy height model using DSM-DTM. Now I have to extract maximum pixel value in each polygon of the shape file.
0 个评论
回答(1 个)
Paras Gupta
2023-9-14
Hello,
I understand that you want to extract the maximum pixel value for each polygon in a shape file using a Canopy Height Model (CHM) raster. Please refer to the code below to achieve the same.
% Load the shapefile (shp file) and the CHM (tif file) into MATLAB
shapefile = shaperead('your_shapefile.shp');
CHM = readgeoraster('your_CHM.tif');
numPolygons = numel(shapefile);
% Iterates over each polygon
for i = 1:numPolygons
polygon = shapefile(i).Geometry;
% Create a mask to identify the pixels within the polygon
mask = inpolygon(CHM.X, CHM.Y, polygon(:,1), polygon(:,2));
% Extract the corresponding pixel values from the CHM
values = CHM.Z(mask);
% Calculate the maximum value using the max function
maxPixelValue = max(values);
disp(['Maximum pixel value for polygon ', num2str(i), ': ', num2str(maxPixelValue)]);
end
The above code assumes that coordinate systems of the shapefile and CHM are the same, and that the CHM is in the GeoTIFF format. Please refer to the following documentations for more information on the functions used in the code:
Hope this helps.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Elementary Polygons 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!