shaperead
從shapefile讀取矢量特性和屬性
S=shaperead(fileName); %讀取filename文件中的數據及屬性,並將其保存在結構體 S 中。
shapewrite
將地理向量數據結構寫入shapefile
shapewrite(S,resultFileName); %將存儲在shapefile S中的矢量地理特性寫入以shapefile格式的文件名指定的文件。
案例說明:讀取*.shp格式的清單文件,按照控制矩陣改變各個區域網格點數值,最后另存為新的*.shp文件
for month=1:length(Month) Matrix=readtable(['./ControlMatrix/Matrix_PRD_2017_Base' Month{1,month} '_12.csv']); %按月讀取控制矩陣 for file=1:length(file_dir) % 循環讀取並計算所有文件 shp=shaperead(['./emission/' file_dir(file).name '/final_' file_dir(file).name '.shp']);%讀取 *.shp 格式的清單文件 nowRegi=''; nowPoll=''; for pollution=1:length(pollutionName) disp([Month{1,month} ' ' file_dir(file).name ' ' pollutionName{pollution} 'Complete']); eval(['species ={ shp.' pollutionName{pollution} '};']) % 讀取 *.shp 中對應污染物的濃度數據 for point=1:length(regionFile{:,1}) % 遍歷所有網格點,並修正其網格數值 num=col*(regionFile{point,3}-1)+regionFile{point,2}; if ~strcmp(nowRegi,regionFile{point,1}) || ~strcmp(nowPoll,pollutionName{pollution}) nowRegi=regionFile{point,1}; nowPoll=pollutionName{pollution}; for i=1:length(factorFile{:,1}) if strcmp(factorFile{i,2},regionFile{point,1}) && strcmp(factorFile{i,3},pollutionName{pollution}) break end end end species{1,num}=species{1,num}*Matrix{1,i+1}; end for j=1:length(species) eval(['shp(j).' pollutionName{pollution} '= species{j};']) % 將修正過的網格化數據存入清單結構體 end end if exist(['./Result/' Month{1,month}],'dir')==0 % 判斷是否存在結果保存目錄,若不存在則新建 mkdir(['./Result/' Month{1,month}]); end % 保存修改后的清單文件,保存格式為 *.shp resultFileName=['./Result/' Month{1,month} '/final_' file_dir(file).name '.shp' ]; shapewrite(shp,resultFileName); end end
參考資料:
https://ww2.mathworks.cn/help/map/index.html?s_tid=srchtitle
https://ww2.mathworks.cn/help/map/ref/shaperead.html
https://ww2.mathworks.cn/help/map/ref/shapewrite.html