Loop through rasters and extract values using shapefile
显示 更早的评论
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
回答(1 个)
Daksh
2022-12-20
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!
类别
在 帮助中心 和 File Exchange 中查找有关 Mapping Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!