⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kml2xyz.m

📁 MATLAB语言下的(有源码):Mike Zero系列软件的前后处理 GE中岸线与MIKE岸线相互转换 Mapinfo与MIKE中数据相互转换.(对学习MIKE与学习MATLAB编程人皆有帮助,且有说
💻 M
字号:
function kml2xyz(UserPath)
%转换kml文件为xyz格式文件
TempStr=strcat(UserPath,'*.kml');
%
%打开文件
[KmlFileName,KmlFilePath]=uigetfile(TempStr,'请选择需转换的Kml文件:');
if strcmp(KmlFilePath(length(KmlFilePath)),'\')~=1
    KmlFilePath(length(KmlFilePath)+1)='\';
end
%
KmlFilePathName=strcat(KmlFilePath,KmlFileName); %Kml 文件绝对路径引用
XYZFileName=strcat(KmlFileName(1:length(KmlFileName)-3),'xyz');
XYZFilePathName=strcat(KmlFilePath,XYZFileName); %txt 文件绝对路径引用,生成的同名xyz文件存于与Kml文件相同目录中。
Fid_Kml=fopen(KmlFilePathName,'r');
if Fid_Kml==-1
    msgbox(strcat('Can''t open the file-',KmlFilePathName));
    error(strcat('Can''t open the file-',KmlFilePathName));
end
Fid_XYZ=fopen(XYZFilePathName,'w'); %
if Fid_XYZ==-1
    msgbox(strcat('Can''t open the file-',XYZFilePathName));
    error(strcat('Can''t open the file-',XYZFilePathName));
end
%%
while feof(Fid_Kml)~=1
    CurrentStr=fgetl(Fid_Kml);
    Tag=findstr(CurrentStr,'<coordinates>');
    if (length(Tag)==1)&(Tag>0)
        CurrentStr=fgetl(Fid_Kml);
        Tag=findstr(CurrentStr,'</coordinates>');
        AllData=str2num(CurrentStr(1:(Tag-1)));
        N=length(AllData);
        Longitude=AllData(1:3:N);
        Lagitude=AllData(2:3:N);
        Elevation=Lagitude.*0+10; %设定岸线为10m高程.
        Connectivity=Longitude.*0+1;
        Connectivity(length(Connectivity))=0;
        NewData=[Longitude',Lagitude',Connectivity',Elevation'];
        [M,N]=size(NewData);
        for c1=1:M 
            fprintf(Fid_XYZ,'%.10f\t%.10f\t%.0f\t%.2f\n',NewData(c1,1),NewData(c1,2),NewData(c1,3),NewData(c1,4));
        end
    end
end
fclose(Fid_Kml);
fclose(Fid_XYZ);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -