def main(): parser = Parser() igc = parser.parse('2015-08-13-Lai_Alv.igc') kml = Kml() for record in igc.records: kml.add_point(igc.date, record) kml.create('test.kml')
def test_bearing(self): kml = Kml('BearingTest', 2500) point = Wgs84Point(46.978308, 8.254787) step = pi / 12 bearing = 0 for n in range(24): new_point = point_from_distance_and_bearing(point, 2000, bearing) new_bearing = bearing_between_two_points(point, new_point) print('step: {}, bearing: {}, calculated bearing: {} to point: {}'.format(n, bearing, new_bearing, new_point)) self.assertAlmostEqual(bearing, new_bearing, places=4) kml.add_point('Bearing', '{}'.format(n), new_point) bearing += step kml.build('BearingTest.kml')
#except IndexError: # print row pts.sort(LatLngCompare) grouper = Grouper() for (i,pt) in enumerate(pts): grouper.append(pt) optimizer = GroupSwapOptimizer(grouper) optimizer.process() #Output generation dom = Kml() group_style = xml.dom.minidom.parseString(""" <Style id="group"> <IconStyle> <color>ff00ff00</color> <scale>1.1</scale> <Icon> <href>http://maps.google.com/mapfiles/kml/pal3/icon21.png</href> </Icon> </IconStyle> <PolyStyle> <color>4cff5500</color> </PolyStyle> <LineStyle> <color>ffffffff</color>
def get(self): url = """http://vagasapien.blogspot.com/feeds/posts/default""" response = urlfetch.fetch(url) if response.status_code != 200: return soup = BeautifulSoup.BeautifulSoup(response.content) kml = Kml("Vagasapien") waypoint_style = Style( "waypoint", IconStyle( "http://maps.google.com/mapfiles/ms/micons/red.png") ) current_style = Style( "current", IconStyle( "http://maps.google.com/mapfiles/ms/micons/red-dot.png") ) line_style = Style( "line", LineStyle( "A00000FF", 5) ) coordinates = [] first = True pub_months = {} pub_years = {} for entry in soup('entry'): published = entry('published')[0].text published = datetime.datetime.strptime(published[:19], '%Y-%m-%dT%H:%M:%S') pub_key = published.strftime("%Y/%m") pub_months[pub_key] = pub_months.get(pub_key, 0) + 1 pub_yr_key = published.strftime("%Y") pub_years[pub_yr_key] = pub_years.get(pub_yr_key, 0) + 1 for entry in soup('entry'): title = entry('title')[0].text href = entry('link', {'rel':'alternate'})[0]['href'] content = unescape(entry('content')[0].text) points = entry('georss:point') if not points: continue latitude, longitude = entry('georss:point')[0].text.split() thumbnails = entry('media:thumbnail') thumbnail = thumbnails[0]['url'] if thumbnails else None published = entry('published')[0].text published = datetime.datetime.strptime(published[:19], '%Y-%m-%dT%H:%M:%S') coordinate = Coordinate(latitude, longitude) style = current_style if first else waypoint_style first = False content = "<p>" + datetime.datetime.now().strftime("%A, %B %d, %Y %I:%M %p") + "</p>" if thumbnail: content += '<p><img src="{}" /></p>'.format(thumbnail) content += '<p><a href="{}" >View Blog Entry</a></p>'.format(href) pub_key = published.strftime("%Y/%m") pub_count = pub_months[pub_key] pub_yr_key = published.strftime("%Y") pub_yr_count = pub_years[pub_yr_key] year_sort = str(5000 - int(published.strftime("%Y"))) month_sort = str(50 - int(published.strftime("%m"))) place = Place('<a href="{}" >{}</a>'.format(href, title), content, coordinate, style, folder=year_sort + "|" + published.strftime("%Y") + " ({})/".format(pub_yr_count) + month_sort + "|" + published.strftime("%B") + " ({})".format(pub_count)) coordinates.append(coordinate) kml.places.append(place) kml.lines.append(LineString("Route", line_style, coordinates)) self.response.headers['Content-Type'] = "text/xml" self.response.out.write(kml.to_string())