Extracting Maximum pixel value from a raster (Canopy Height Model) for multiple polygons in a shapefile

3 vues (au cours des 30 derniers jours)
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.

Réponses (1)

Paras Gupta
Paras Gupta le 14 Sep 2023
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.

Catégories

En savoir plus sur Elementary Polygons dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by