Loop through rasters and extract values using shapefile

4 visualizaciones (últimos 30 días)
Anwesha Sharma
Anwesha Sharma el 9 de Dic. de 2022
Respondida: Daksh el 20 de Dic. de 2022
Hi,
I wanted to know if it is possible to loop through 50 raster files (.tif) and extract values from the rasters using a point shapefile and saving in a .csv

Respuestas (1)

Daksh
Daksh el 20 de Dic. de 2022
It is my understanding that you wish to loop through .tif files in a folder, perform Raster to Point Shapefile conversion and save data in a .CSV or .XLS spreadsheet file. You can follow these steps and documentation links to proceed:
  • Use this link to iterate over files in current directory in path with a specific file type (.TIF) for our case. Refer to the following code instance for your case:
myDir = uigetdir; %gets directory
myFiles = dir(fullfile(myDir,'*.tif'); %gets all .TIF files in struct
for k = 1:length(myFiles)
baseFileName = myFiles(k).name;
fullFileName = fullfile(myDir, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
num = importdata(fullFileName); %or readtable
% all of your actions go here
end
  • Use this link as reference for Raster to Point Shapefile conversion
  • Read through the documentation of MATLAB command: "writetable()" to write matrix data into a file (.CSV or .XLS for our case), something like:
% assuming M is your data matrix to write into file.csv
writematrix(M,'file.xls')
Hope it helps!

Categorías

Más información sobre Mapping Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by