def make_leg(route, i, j, name=True, arrow=False, style_url=None): coord0 = route.tps[i].coord coord1 = route.tps[j].coord line_string = kml.LineString(coordinates=[coord0, coord1], altitudeMode='clampToGround', tessellate=1) multi_geometry = kml.MultiGeometry(line_string) if name: point = kml.Point(coordinates=[coord0.halfway_to(coord1)]) multi_geometry.add(point) distance = coord0.distance_to(coord1) name = kml.name('%.1fkm' % (distance / 1000.0)) if arrow: bearing = coord1.initial_bearing_to(coord0) coordinates = [ coord1.coord_at(bearing - pi / 12.0, 400.0), coord1, coord1.coord_at(bearing + pi / 12.0, 400.0) ] line_string = kml.LineString(coordinates=coordinates, altitudeMode='clampToGround', tessellate=1) multi_geometry.add(line_string) if style_url is None: style_url = globals.stock.xc_style.url() return kml.Placemark(name, multi_geometry, styleUrl=style_url)
def make_task_folder(globals, task): name = task.name or 'Task' rows = [] tp0 = None total = 0.0 count = -1 for sl in util.runs([tp.name for tp in task.tps]): if tp0 is None: tp0 = task.tps[sl.start] continue tp1 = task.tps[sl.stop - 1] distance = tp0.coord.distance_to(tp1.coord) th = '%s %s %s' % (tp0.name, RIGHTWARDS_ARROW, tp1.name) td = '%.1fkm' % (distance / 1000.0) rows.append((th, td)) total += distance count += 1 tp0 = tp1 rows.append(('Total', '%.1fkm' % (total / 1000.0))) table = make_table(rows) snippet = '%.1fkm via %d turnpoints' % (total / 1000.0, count) style_url = globals.stock.check_hide_children_style.url() folder = kml.Folder(name=name, description=kml.CDATA(table), Snippet=snippet, styleUrl=style_url) style_url = globals.stock.xc_style.url() done = set() for tp in task.tps: key = tp.name if key in done: continue else: done.add(key) point = kml.Point(coordinates=[tp.coord]) folder.add(kml.Placemark(point, name=tp.name, styleUrl=style_url)) done = set() for tp in task.tps: if tp.radius == 0: continue key = (tp.name, tp.radius) if key in done: continue else: done.add(key) coordinates = kml.coordinates.circle(tp.coord, tp.radius) line_string = kml.LineString(coordinates, tessellate=1) folder.add(kml.Placemark(line_string, styleUrl=style_url)) tp0 = None for sl in util.runs([tp.name for tp in task.tps]): if tp0 is None: tp0 = task.tps[sl.start] continue tp1 = task.tps[sl.stop - 1] coord0 = tp0.coord.coord_at(tp0.coord.initial_bearing_to(tp1.coord), tp0.radius) theta = tp1.coord.initial_bearing_to(tp0.coord) coord1 = tp1.coord.coord_at(theta, tp1.radius) line_string1 = kml.LineString(coordinates=[coord0, coord1], tessellate=1) coords = [ coord1.coord_at(theta - pi / 12.0, 400.0), coord1, coord1.coord_at(theta + pi / 12.0, 400.0) ] line_string2 = kml.LineString(coordinates=coords, tessellate=1) multi_geometry = kml.MultiGeometry(line_string1, line_string2) folder.add(kml.Placemark(multi_geometry, styleUrl=style_url)) tp0 = tp1 return kmz.kmz(folder)