How can i extract all the values inside shapefile feature overlaying a raster?

2 次查看(过去 30 天)
Hello all;
I have a shapefile with lots of polygon features in it. what i need is a way to extract each of the pixel values with in each feature and output a histogram for these values. The image is a Geotif.
So basically to put in perspective the code must do;
  1. select one polygon feature inside the shape file,
  2. Overlay it with the Raster Geotif,
  3. get the Geotif pixel values for the selected feature,
  4. write the pixel values in excel for the specific OBJECTID,
  5. iterate to the next feature in the shapefile and repeat steps through 1-4 until end of shapefile features.
Any help and guidance is much appreciated.
Kind Regards.
  1 个评论
ÖMER
ÖMER 2023-10-18
I know everyone is looking for this kind of iteration;
for i=1:numel(NDShapeFile)
OBJECTID = NDShapeFile(i).OBJECTID; % Extract OBJECTID of each feature in the shapefile
OBJECTIDSTR = num2str(OBJECTID);
%OBJECTID Testing OBJECTID Value Works
shapewrite(NDShapeFile(i),append(OBJECTIDSTR,'.shp')); % Write each feature in the shapefile as an external shape
%Raster Value Extraction is going to go here
%NDShapeFile(i);
delete(append(OBJECTIDSTR,'.dbf'),append(OBJECTIDSTR,'.shp'),append(OBJECTIDSTR,'.shx'));
end

请先登录,再进行评论。

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by