菜单
  

    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. 内河运输船舶碰撞与搁浅...

  3. 产业集群与城市化英文文献和中文翻译

  4. 轴承的摩擦与润滑英文文献和中文翻译

  5. 承载力的立足点在斜坡带...

  6. 国际工程项目组织与管理英文文献和参考文献

  7. 计算机语言性能与分析英文文献和中文翻译

  8. 中考体育项目与体育教学合理结合的研究

  9. 酸性水汽提装置总汽提塔设计+CAD图纸

  10. 大众媒体对公共政策制定的影响

  11. 乳业同业并购式全产业链...

  12. 电站锅炉暖风器设计任务书

  13. 当代大学生慈善意识研究+文献综述

  14. 杂拟谷盗体内共生菌沃尔...

  15. 十二层带中心支撑钢结构...

  16. java+mysql车辆管理系统的设计+源代码

  17. 河岸冲刷和泥沙淤积的监测国内外研究现状

  

About

751论文网手机版...

主页:http://www.751com.cn

关闭返回