LoginSignup
0
0

More than 5 years have passed since last update.

GPSの研究 その11

Posted at

概要

GPSを理解したかった。
NMEAをパースして、KMLを作って見た。

写真

m6.jpg

サンプルコード

import micropyGPS
from lxml import etree
from pykml.factory import KML_ElementMaker as KML
from pykml.factory import GX_ElementMaker as GX

gps = micropyGPS.MicropyGPS(9, 'dd')
f = open("test10.nmea")
pm = ""
while True:
    line = f.readline()
    if not line:
        break
    if (line[0 : 6] == "$GPGGA"):
        for x in line:
            gps.update(x)
        name = "{}:{}".format(gps.timestamp[1], gps.timestamp[2])
        lat, lon = gps.latitude[0], gps.longitude[0]
        alt = gps.altitude
        pm += "{},{},{} ".format(lon, lat, alt)

doc = KML.kml(
    KML.Placemark(
        KML.name("nmea"),
        KML.LineString(
            KML.extrude(1),
            GX.altitudeMode("relativeToSeaFloor"),
            KML.coordinates(
                pm
            )
        )
    )
)
print (etree.tostring(doc, pretty_print = True).decode())
f = open('micro6.kml', 'w')
f.write(etree.tostring(doc, pretty_print = True).decode())
f.close()

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0