GPSの研究 その11
概要
GPSを理解したかった。
NMEAをパースして、KMLを作って見た。
写真
サンプルコード
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()
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()
以上。
Author And Source
この問題について(GPSの研究 その11), 我々は、より多くの情報をここで見つけました https://qiita.com/ohisama@github/items/78d42406a91028dfb2b1著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .