Ejemplo n.º 1
0
    def __create_lookat(self):
        if not len(self.server.locations):
            return ''

        begin = format_iso_time(min(self.server.locations))
        end = format_iso_time(max(self.server.locations))

        lat = [y for y, _x, _z in self.server.locations.itervalues()]
        lon = [x for _y, x, _z in self.server.locations.itervalues()]
        latMin = min(lat)
        latMax = max(lat)
        lonMin = min(lon)
        lonMax = max(lon)
        latCen = (latMax + latMin) / 2
        lonCen = (lonMax + lonMin) / 2
        dist = haversine(latMin, latMax, lonMin, lonMax)
        dist = limit(dist, 100, 50000)

        lookAt = ('\t\t<LookAt>\n'
                  '\t\t\t<latitude>{}</latitude>\n'
                  '\t\t\t<longitude>{}</longitude>\n'
                  '\t\t\t<altitudeMode>clampToGround</altitudeMode>\n'
                  '\t\t\t<range>{}</range>\n'
                  '\t\t\t<gx:TimeSpan>\n'
                  '\t\t\t\t<begin>{}</begin>\n'
                  '\t\t\t\t<end>{}</end>\n'
                  '\t\t\t</gx:TimeSpan>\n'
                  '\t\t</LookAt>\n').\
            format(latCen, lonCen, dist * 2, begin, end)

        return lookAt
Ejemplo n.º 2
0
def export_gpx(filename, locations, name):
    handle = open(filename, 'wb')

    header = ('<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n'
              '<gpx xmlns="http://www.topografix.com/GPX/1/1" creator="{}" version="1.1">\n'
              '\t<trk>\n'
              '\t\t<name>{}</name>\n'
              '\t\t<trkseg>\n').format(name, 'test name')
    handle.write(header)

    for location in sorted(locations.items()):
        timeStamp = format_iso_time(location[0])
        lat = location[1][0]
        lon = location[1][1]
        alt = location[1][2]
        point = ('\t\t\t<trkpt lat="{}" lon="{}">\n'
                 '\t\t\t\t<ele>{}</ele>\n'
                 '\t\t\t\t<time>{}</time>\n'
                 '\t\t\t</trkpt>\n').format(lat, lon, alt, timeStamp)
        handle.write(point)

    footer = ('\t\t</trkseg>\n'
              '\t</trk>\n'
              '</gpx>\n')
    handle.write(footer)
    handle.close()
Ejemplo n.º 3
0
    def __create_track(self):
        if not len(self.server.locations):
            return ''

        track = ('\t\t<Placemark>\n'
                 '\t\t\t<name>Track</name>\n'
                 '\t\t\t<description>{} locations</description>\n'
                 '\t\t\t<styleUrl>#track</styleUrl>\n'
                 '\t\t\t<gx:Track>\n'
                 '\t\t\t\t<altitudeMode>clampToGround</altitudeMode>\n').\
            format(len(self.server.locations))

        with self.server.lock:
            for timeStamp in sorted(self.server.locations):
                lat, lon, alt = self.server.locations[timeStamp]
                timeStr = format_iso_time(timeStamp)
                if alt is None:
                    track += '\t\t\t\t<gx:coord>{} {}</gx:coord>\n'.\
                        format(lon, lat)

                else:
                    track += '\t\t\t\t<gx:coord>{} {} {}</gx:coord>\n'.\
                        format(lon, lat, alt)
                track += '\t\t\t\t<when>{}</when>\n'.format(timeStr)

        track += ('\t\t\t</gx:Track>\n' '\t\t</Placemark>\n')

        return track