MATLAB 读写ArcGIS *.shp文件

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

 

posted @ 2020-09-15 16:53  CollinsLi  阅读(2245)  评论(0编辑  收藏  举报