读取谷歌地球的kml文件中的经纬度坐标

最近我在B站上传了如何获取研究边界的视频,下面分享一个可以读取kml中经纬度的matlab函数,如此一来就可以获取任意区域的经纬度坐标了。

1.谷歌地球中划分区域

2.matlab读取kml文件

function [sname,lon,lat] = kml2xy(ip_kml)
% ip_kml = 'ocean_distubution.kml';
fid = fopen(ip_kml,'r');
[sname, lon, lat] = read_one_record_in_kml(fid)
end
function [sname, lon, lat] = read_one_record_in_kml(fid)
iname = 0;
while ~feof(fid)
    str = fgetl(fid);
    str(isspace(str)) = [];
    if strcmp(str(1:6),'')
        sname = str(7:end-7);
        iname = 1;
    elseif strcmp(str,'')
        scoord = fgetl(fid);
        scoord = strrep( scoord, ',', ' ' );
        coord = sscanf(scoord,'%f',[3,inf]);
        
        lon = coord(1,:);
        lat = coord(2,:);
        lon = lon';lat = lat';
        break;
    end
    
end
if iname == 0
    sname = NaN;
    lon = NaN;
    lat = NaN;
end
end

欢迎点赞收藏转发!

你可能感兴趣的:(机器学习,算法,人工智能)