目录

  • 问题:
  • 方法一:借助arc gis软件
    • 1.在Google earth上创建kml
    • 2.在ArcGIS上导入kml文件
    • 3.图层多边形文件转为线要素
    • 4.线要素转为点要素
    • 5.点要素添加点要素的经纬度
    • 6. 查看点要素的属性表
  • 方法二:read_kml函数

问题:

在google earth上创建一个矩形框kml文件,然后获取kml文件上矩形框四个角点的经纬度。

方法一:借助arc gis软件

1.在Google earth上创建kml

(1)

(2)位置另存为kml格式(不是kmz哦)

2.在ArcGIS上导入kml文件

kml文件转为图层文件

3.图层多边形文件转为线要素

4.线要素转为点要素

5.点要素添加点要素的经纬度

6. 查看点要素的属性表

(point_x,point_y)分别为点的经纬度

方法二:read_kml函数

来源:https://www.mathworks.com/matlabcentral/fileexchange/13026-read_kml
经测试,很好用

function [x,y,z] = read_kml(fileName)
% READ_KML Reads in (x,y,z) from a GoogleEarth kml file.
%
%  I have tried to make this code as robust as possible, but it may crash
%  or give unexpected resutls if the file is not formatted exactly as
%  expected.
%
% Example:
%   [x,y,z] = read_kml('test.kml');
%
% where test.kml looks like:
% <?xml version="1.0" encoding="UTF-8"?>
% <kml xmlns="http://earth.google.com/kml/2.1">
% <Placemark>
%   <name>test_length</name>
%   <description>junk</description>
%   <LineString>
%       <tessellate>1</tessellate>
%       <coordinates>
% -73.65138440596144,40.45517368645169,0 -73.39056199144957,40.52146569128411,0 -73.05890757388369,40.59561213913959,0 -72.80519929505505,40.66961872411046,0 -72.61180114704385,40.72997510603909,0 -72.43718187249095,40.77509309196679,0 </coordinates>
%   </LineString>
% </Placemark>
% </kml>
%
% afarris@usgs.gov 2016March09, now can read mulitple sets of coordinates
% afarris@usgs.gov 2006November%% open the data file and find the beginning of the data
fid=fopen(fileName);
if fid < 0error('could not find file')
end% This loop reads the data file one line at a time. If if finds the word
% <coordinates>, it knows there is data until it reads the word
% </coordinates>.  After loading this data, it keeps reading the file,
% looking for another instance of <coordinates> until it finds the word
% </kml> which signals that the end of the file has been reached.
% Some files have all the data on one line, others have newline charecters
% in various points in the file.  I hope this code that works in all cases.done=0;
endoffile = 0;
ar = 1;while endoffile == 0while done == 0junk = fgetl(fid);f = strfind(junk,'<coordinates>');ff = strfind(junk,'</kml>');if ~isempty(f)done = 1;elseif  ~isempty(ff)endoffile = 1;done = 1;endendif endoffilebreakend% 'junk' either ends with the word '<coordinates>' OR % some data follows the word '<coordinates>'  if (f + 13) >= length(junk)  % no data on this line% done2 is set to zero so the next loop will read the datadone2 = 0;else% there is some data in this line following '<coordinates>'clear f2f2 = strfind(junk,'</coordinates>');if ~isempty(f2) %all data is on this line% there may be multiple sets of data on this one line% I read them allfor i = 1 : size(f2,2)alldata{ar} = junk(f(i)+13:f2(i)-1);% I add in whitespace b/c sometimes it is missingalldata{ar+1} = ' ';ar = ar+2;end% done2 is set to one because the next loop does not need to rundone2 = 1;else% only some data is on this linealldata{ar} = junk(f+13:end);% I add in whitespace b/c sometimes it is missingalldata{ar+1} = ' ';ar = ar+2;% done2 is set to zero so the next loop will read the rest of the datadone2 = 0;end% check to see if at end of the fileff = strfind(junk,'</kml>');if  ~isempty(ff)% no more dataendoffile = 1;breakelse% need to keep looking for more datadone = 0;endend% If not all the data was on the line with the word <coordiate>, % read in the datawhile done2 == 0% read in line from data filejunk = fgetl(fid);f = strfind(junk,'</coordinates>');if isempty(f) == 1 % no ending signal, just add this data to the rest alldata{ar} = junk;ar = ar + 1;else% ending signal is presentdone = 0;if f < 20% </coordinates> is in the begining of the line, ergo no data % on this line; just end the loopdone2 = 1;else % the ending signal (</coordinates>) is present: remove it, % add data to the rest and signal the end of the loopf2 = strfind(junk,'</coordinates>');alldata{ar} = junk(1:f2-1);ar = ar + 1;done2 = 1;disp('done with line')endend% check to see if at end of the fileff = strfind(junk,'</kml>');if  ~isempty(ff)% no more dataendoffile = 1;breakelse% need to keep looking for more datadone = 0;endend
end
fclose(fid);%% get the data into neat vectors
%  I have to divide the string into X, Y and Z values.
%
% This is hard b/c there is no comma between points
% (just commans between x and y, and between
% y and z)  ie;  -70.0000,42.0000,0 -70.1000,40.10000,0 -70.2,....
%
% I used to do this by finding commas and spaces, now I use
% 'strsplit'!  Thank you Matlab!% 'alldata' is one huge cell
% turn alldata into regular vector so it is easier to work with
data = cell2mat(alldata);
% data is one huge string, split it so there is seperate element for each number
C = strsplit(data,{',',' '});
% sometimes first and/or last element in C is empty, this causes problems
len = size(C,2);
if isempty(C{1}) && isempty(C{end})D = C(2:len-1);
elseif isempty(C{1}) && ~isempty(C{end})D = C(2:end);
elseif isempty(C{end}) && ~isempty(C{1})D = C(1:len-1);
end% There has GOT to be a better way to split C into 3 variables!
a = 1;
for i = 1 : 3: length(D)-2x(a,1) = str2double(D{i});a=a+1;
end
a=1;
for i = 2 : 3: length(D)-1y(a,1) = str2double(D{i});a=a+1;
end
a=1;
for i = 3 : 3: length(D)z(a,1) = str2double(D{i});a=a+1;
end

提取KML文件上 点 的经纬度相关推荐

  1. 什么软件可以提取扫描文件上的文字

    在工作上会遇到一些不能复制.粘贴文件资料,平常就只能进行简单的截图然后手动提取图片中的文字了,这样操作下来是非常耽误时间的,大家要想快速的解决这个问题,我们必须要借助工具的帮助才行,那么什么软件可以提 ...

  2. 在水经注中导入陈江街道九条河KML文件的应用案例

    概述 水经注软件除了可以轻松下载无水印Google Earth卫星影像.有明确拍摄日期的历史影像.地方高清天地图.百度高德大字体打印地图,且可按1万/5千等国家标准图幅下载,可下载陆地及海洋高程.ST ...

  3. python读取dat文件经纬度_自动提取kml文件中的经纬度

    1.问题描述 工程设计中,经常需要提取奥维地图或者谷歌地图中标记图形的边界点经纬度,如果图形较多,手动提取非常繁琐,因此自动提取这些信息就非常有必要. 2.解决思路 奥维地图和谷歌地图的转化文件是km ...

  4. python读取google earth导出的kml文件内的经纬度信息

     首先利用google earth,描出河段中心线,并导出kml文件  提取kml内的经纬度信息 import kml2geojson as k2g import geopandas as gpd i ...

  5. Springboot文件上传 百度ocr文字识别提取

    前言 在学习过程中突然发现我以前用的文件上传真的好傻.以前的博客记录中还沾沾自喜文件上传模板可以套用,不接收新事物,却发现原来Springboot的文件上传如此简单. 首先,文件上传的三种方式,普通文 ...

  6. Asp.NET大文件上传组件开发总结(二)---提取文件内容

    不知地震什么时候结束,为了给老婆小孩守夜,看来还不能睡,那就把第二篇也写了吧,只是不知对大家有没有用哟. 为了提供文件内容,我们需要首先需确定客户请求中发送的有文件内容,然后确定文件内容的位置.这部分 ...

  7. 【转】Asp.NET大文件上传组件开发总结(二)---提取文件内容

    为了提供文件内容,我们需要首先需确定客户请求中发送的有文件内容,然后确定文件内容的位置.这部分对应的代码如下: 1HttpApplication app = sender as HttpApplica ...

  8. leaflet使用L.KML.js插件上传本地kml文件到leaflet中

    发现网上的案例都是加载项目assets内的kml文件,而实际的需求是:用户需要上传自己计算机上的kml文件,找了半天没找到案例,最后终于研究出来了,喜欢的点赞支持! 1.网上案例使用 L.KML.js ...

  9. 如何在谷歌地球上画路线或者运动轨迹?根据纬经高信息在谷歌地球Google earth中画运动轨迹,首先将Excel文件纬经高信息转换为.csv文件,再转换为.kml文件,最终在谷歌地球中显示。

    (制作运动轨迹的前提是装有谷歌地球和CSV2kml转换工具, CSV2kml转换工具的下载可在下列链接中下载https://download.csdn.net/download/howe1233/10 ...

最新文章

  1. 无人驾驶汽车开发平台,加速无人驾驶汽车的商业化
  2. python【力扣LeetCode算法题库】14-最长公共前缀(列表解压)
  3. 启明云端分享| ESP32-C6有啥特别之处呢?性能如何,搭载的处理器是什么呢?GPIO有多少个呢?采用的框架是什么呢?
  4. 一款实用的前端截图工具
  5. 随机JCache内容:多个提供程序和JMX Bean
  6. Linux文件下载和上传工具lrzsz
  7. JQueryDOM之样式操作
  8. [SCOI2005][BZOJ 1084]最大子矩阵
  9. PHP中钩子函数的实现与认识
  10. 计算机网络 —— 冲突域和广播域
  11. Java程序编写 • 【第4章 程序:随机本周菜品;简易计算器】
  12. MATLAB反色图像处理
  13. 京东运营 不错的帖子
  14. Windows下禁止软件wps热点自启动和后台运行
  15. 注意力机制-多头注意力
  16. 靠肝的爬塔不优雅——养成手游《古今江湖》
  17. GitHub上最火的Android开源项目整理
  18. 苹果支付在哪里设置_微信刷脸支付怎么开通,在哪里设置?
  19. Android调用高德地图直接导航的简单实例
  20. Broekett定理):

热门文章

  1. STM32学习之I2C协议(读写EEPROM)
  2. NLP(八):文本表示:word2vec原理及其gensim实现
  3. 利用LORA无线信号接入数据的手持PDA装置
  4. 【九度OJ】查找第K小数
  5. 令人截图上瘾的录屏神器FSCapture
  6. 通过 itms:services://? 在线安装ipa ,跨过appstore
  7. UE5再次更新!扫描或手动建模面部模型可直接转为绑定好的Metahuman
  8. ceph 数据恢复机制_ceph数据恢复(成功率相当高)
  9. 从零开始学习信号完整性--7-SI分析仿真
  10. Linux内核深入理解定时器和时间管理(6):x86_64 相关的时钟源(kvm-clock,tsc,acpi_pm,hpet)