Пример #1
0
    def export_track(self, track, filename, filetype, trim=None, prepend_datetime=False, zoffset=0, mode="default"):
        # filetype 'gpx', 'kmz' or 'km'
        if filetype not in ["kmz", "kml", "gpx"]:
            raise AssertionError("Unsupported filetype %s" % filetype)

        track_info = self.get_trackinfo(track)
        tpoints = self.get_trackpoints(track_info)
        if prepend_datetime:
            stime = time.localtime(track_info["start"])
            filename = os.path.join(
                os.path.dirname(filename), time.strftime("%Y-%m-%d-%H-%M-%S-", stime) + os.path.basename(filename)
            )

        is_km = filetype in ["kmz", "kml"]
        if is_km:
            from kml import KmlDoc
        if filetype == "gpx":
            from gpx import GpxDoc

        if trim:
            tpoints = trim_trackpoints(track_info, tpoints, trim)

        optpoints = optimize(tpoints, 0)
        self.log.info("Count: %u, opt: %u", len(tpoints), len(optpoints))
        if is_km:
            kml = KmlDoc(os.path.splitext(os.path.basename(filename))[0])
            kml.add_trackpoints(optpoints, int(zoffset), extrude="air" not in mode)
        if filetype == "kmz":
            import zipfile
            import cStringIO as StringIO

            out = StringIO.StringIO()
            kml.write(out)
            out.write("\n")
            z = zipfile.ZipFile(filename, "w", zipfile.ZIP_DEFLATED)
            z.writestr("doc.kml", out.getvalue())
        if filetype == "kml":
            with open(filename, "wt") as out:
                kml.write(out)
                out.write("\n")

        if filetype == "gpx":
            gpx = GpxDoc(os.path.splitext(os.path.basename(filename))[0], track_info["start"])
            gpx.add_trackpoints(optpoints, int(zoffset))
            with open(filename, "wt") as out:
                gpx.write(out)
                out.write("\n")
Пример #2
0
                if km:
                    kml = KmlDoc(os.path.splitext(os.path.basename(km))[0])
                    kml.add_trackpoints(optpoints, int(options.zoffset), 
                                        extrude='air' not in options.mode)
                if options.kmz:
                    import zipfile
                    import cStringIO as StringIO
                    out = StringIO.StringIO()
                    kml.write(out)
                    out.write('\n')
                    z = zipfile.ZipFile(options.kmz, 'w', 
                                        zipfile.ZIP_DEFLATED)
                    z.writestr('doc.kml', out.getvalue())
                if options.kml:
                    with open(options.kml, 'wt') as out:
                        kml.write(out)
                        out.write('\n')
                
                if options.gpx:
                    gpx = GpxDoc(os.path.splitext( \
                                 os.path.basename(options.gpx))[0],
                                 track_info['start'])
                    gpx.add_trackpoints(optpoints, int(options.zoffset))
                    with open(options.gpx, 'wt') as out:
                        gpx.write(out)
                        out.write('\n')
                        
    except AssertionError, e:
        print >> sys.stderr, 'Error: %s' % e[0]

Пример #3
0
                 log.info('Count: %u, opt: %u', 
                           len(tpoints), len(optpoints))
             if km:
                 kml = KmlDoc(os.path.splitext(os.path.basename(km))[0])
                 kml.add_trackpoints(optpoints, int(options.zoffset), 
                                     extrude='air' not in options.mode)
             if options.kmz:
                 import zipfile
                 import cStringIO as StringIO
                 out = StringIO.StringIO()
                 kml.write(out)
                 out.write('\n')
                 z = zipfile.ZipFile(options.kmz, 'w', 
                                     zipfile.ZIP_DEFLATED)
                 z.writestr('doc.kml', out.getvalue())
             if options.kml:
                 with open(options.kml, 'wt') as out:
                     kml.write(out)
                     out.write('\n')
             
             if options.gpx:
                 gpx = GpxDoc(os.path.splitext( \
                              os.path.basename(options.gpx))[0],
                              track_info['start'])
                 gpx.add_trackpoints(optpoints, int(options.zoffset))
                 with open(options.gpx, 'wt') as out:
                     gpx.write(out)
                     out.write('\n')
                     
 except AssertionError, e:
     print >> sys.stderr, 'Error: %s' % e[0]