使用python进行GoogleEarth实时更新

时间:2017-11-14 16:31:47

标签: python flask real-time kml google-earth

我正试图在谷歌地球上实时显示一个物体。

我找到了几个网页,让我相信这有点可行。我遇到了一些问题。

我已经获得了一个kml文件的网络链接,我定期用新的lat / lon更新,但由于一个程序正在写入该文件(我的python代码)而另一个程序需要从中读取(google earth),因此存在瓶颈它会造成令人讨厌的滞后。

我还看到你可以使用python脚本作为网络链接文件,因为它在服务器上。我假设每次google earth刷新它会调用返回kml字符串的python脚本。

我用烧瓶实施了这个理论,但我没有得到任何结果。有谁知道我做错了什么?

以下代码:

我的网络链接kml:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Folder>
    <name>Network Links</name>
    <visibility>0</visibility>
    <open>0</open>
    <description>Network link example 1</description>
    <NetworkLink>
      <name>Aircraft 1</name>
      <visibility>0</visibility>
      <open>0</open>
      <description>Test description</description>
      <refreshVisibility>0</refreshVisibility>
      <flyToView>0</flyToView>
      <Link>
        <href>127.0.0.1:5000/aircraft.kml</href>
          <refreshMode>onInterval</refreshMode>
          <refreshInterval>0.05</refreshInterval>
      </Link>
    </NetworkLink>
  </Folder>
</kml>

Flask App:

from flask import Flask, request, send_from_directory
from GoogleEarthDraw import kml_updater

# set the project root directory as the static folder, you can set others.
app = Flask(__name__, static_url_path='')

@app.route('/aircraft.kml')
def send_py_app():
    print("Returning py file")
    return kml_updater.to_print_output()

if __name__ == "__main__":
    app.run()

Python KML制作人(kml_updater.py):

def get_kml_text(latitude, longitude, altitude):
    return \
'''<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Placemark>
    <name>Aircraft 1</name>
    <description>Show flight of aircraft 1</description>
    <Point>
      <coordinates>{},{},{}</coordinates>
    </Point>
  </Placemark>
</kml>
'''.format(longitude, latitude, altitude)


def to_print_output():
    # Create the lat/lon/alt
    lat = 41.98583333
    lon = -91.57055556
    alt = 0

    return get_kml_text(lat, lon, alt)

0 个答案:

没有答案