菜单
  

    a format we can use in a log file. Although the generic client, cgps, that we used here is useful for viewing coordinates,
    unfortunately it’s really difficult to get usable information from it. For this reason, we’ll use the Python gps module to
    interact with the receiver.
    Setting Up a Log File
    When we get the stream from the GPS, we need to have a place to store it for later use, as it won’t do us much good if
    we’re just printing it to a (nonconnected) screen during the flight. What we can do is set up a log file, using Python’s
    logging module, and then when the Pi is back on the ground, we can parse the file and put it into a format we can use
    in Google Earth.
    Setting up the log file is very simple. Start by typing
    import logging
    logging.basicConfig(filename='locations.log', level=logging.DEBUG, format='%(message)s')
    These two lines import the module, declare the log’s file name and what gets logged, and give the format of each
    line. We’ll save each GPS call in three strings: the longitude, latitude, and altitude—the three coordinates used by
    Google Earth. (They’re actually saved as floats, not strings, which means that we’ll have to convert them to strings
    when we write them to the log file.) To write a line to the log file, the format is simply this:
    logging.info("logged message or string or what-have-you")
    It is not necessary to use the newline (\n) character, because each time you call the logging.info() function, it
    begins on a new line.
    In case you’re wondering, yes, we could simply write the GPS data to a regular file, but logging is an important,
    useful concept that many programmers either don’t fully understand or skip over completely. In the case of Python’s
    logging module, you can set log entries to be entered depending on the severity of the event being tracked. There are
    five severities possible: DEBUG, INFO, WARNING, ERROR and CRITICAL.
    To see the logging module in action, type python to start up a Python prompt and enter the following:
    >>> import logging
    >>> logging.warning("I am a warning.")
    >>> logging.info("I am an info.")
    The second line will output WARNING:root:I am a warning, while the third line, classified as an INFO level, will
    not be output to the console. If, on the other hand, you enter
    >>> logging.basicConfig(level=logging.DEBUG)
    it sets the default level to DEBUG, meaning that every event will be logged or output, regardless of severity. Entering
    the filename and format, as we did earlier, sets the log file and how events are written to it.
    Formatting a KML File
    A KML file is a special kind of XML (eXtensible Markup Language) used by Google Earth to delineate landmarks,
    objects, and even paths. It looks similar to an HTML file, with opening and closing < > tags for different levels of
    information, such as <Document> and </Document>, and <coordinates> and </coordinates>. Once we’ve got the log
    file from the GPS, we need to format the included coordinates in a KML file that Google Earth can recognize. Luckily,
    this is very easy, since we formatted the log file to just have longitude, latitude, and altitude, separated by
    spaces—with format='%(message)s' and the logging.info() line. Now we can parse each line in the log file,
    separate it by spaces with string.split, and write it into a preformatted .kml file. By using the write() function,
    we can write each line to the new file, called 'kml' in the script, like so:
    kml.write('<Document>blah blah blah</Document>\n')
    Since we know how the final KML file needs to look for Google Earth to use it, we can actually write the program
  1. 上一篇:AA2024-T3可成形性金属板英文文献和中文翻译
  2. 下一篇:同时定位和地图构建英文文献和中文翻译
  1. 会计师事务所任期与审计...

  2. ADO.NET结构与概述英文文献和中文翻译

  3. 信息系统开发与数据库开...

  4. 机器人学入门力学与控制英文文献和中文翻译

  5. 园林植物景观的园林绿化...

  6. 船舶与海洋结构物水动力...

  7. VisualBasic语言与算法英文文献和中文翻译

  8. 高警觉工作人群的元情绪...

  9. 现代简约美式风格在室内家装中的运用

  10. 上市公司股权结构对经营绩效的影响研究

  11. NFC协议物理层的软件实现+文献综述

  12. g-C3N4光催化剂的制备和光催化性能研究

  13. 江苏省某高中学生体质现状的调查研究

  14. 中国传统元素在游戏角色...

  15. 浅析中国古代宗法制度

  16. C++最短路径算法研究和程序设计

  17. 巴金《激流三部曲》高觉新的悲剧命运

  

About

优尔论文网手机版...

主页:http://www.youerw.com

关闭返回