def create_contours(container, document): """Create a KML file containing MMI contour lines. Args: container (ShakeMapOutputContainer): Results of model.conf. datadir (str): Path to data directory where output KMZ will be written. document (Element): LXML KML Document element. """ # TODO - label contours? gx:labelVisibility doesn't seem to be working... folder = document.newfolder(name='Contours', visibility=0) mmi_line_styles = create_line_styles() pgm_line_style = skml.Style(linestyle=skml.LineStyle(width=3)) ic = skml.IconStyle(scale=0) component = list(container.getComponents())[0] imts = container.getIMTs(component) for imt in imts: line_strings = contour(container.getIMTGrids(imt, component), imt, DEFAULT_FILTER_SIZE, None) # make a folder for the contours imt_folder = folder.newfolder(name='%s Contours' % imt, visibility=0) for line_string in line_strings: if imt == 'MMI': val = '%.1f' % line_string['properties']['value'] else: val = '%g' % line_string['properties']['value'] line_list = [] for segment in line_string['geometry']['coordinates']: ctext = [] for vertex in segment: ctext.append((vertex[0], vertex[1])) ls = skml.LineString(coords=ctext) line_list.append(ls) lc = len(ctext) if lc < 10: dopts = [] elif (ctext[0][0] == ctext[-1][0] and ctext[0][1] == ctext[-1][1]): if lc < 30: dopts = [0, int(lc/2)] elif lc < 60: dopts = [0, int(lc/3), int(2*lc/3)] else: dopts = [0, int(lc/4), int(lc/2), int(3*lc/4)] else: dopts = [int(lc/2)] for i in dopts: p = imt_folder.newpoint(name=val, coords=[ctext[i]], visibility=0) p.style.iconstyle = ic mg = imt_folder.newmultigeometry(geometries=line_list, visibility=0, name="%s %s" % (imt, val)) if imt == 'MMI': mg.style = mmi_line_styles[val] else: mg.style = pgm_line_style
def create_line_styles(): """Create line styles for contour KML. Args: """ line_styles = {} cpalette = ColorPalette.fromPreset('mmi') for mmi in np.arange(0, 11, 0.5): pid = '%.1f' % mmi rgb = cpalette.getDataColor(mmi, color_format='hex') line_style = skml.LineStyle(color=flip_rgb(rgb), width=2.0) style = skml.Style(linestyle=line_style) line_styles[pid] = style return line_styles
for pattern_id in pid_trips.keys(): trip = pid_trips[pattern_id][ 0] # Since we only want to map, any trip will do print trip["trip_id"], route["route_id"] if trip["direction_id"] == "1": direction = " (Reverse)" else: # direction = " (Forward)" direction = "" shape = gtfs.GetShape(trip["shape_id"]) coords = [(lon, lat) for (lat, lon, dist) in shape.points] name = route["route_short_name"] + ": " + route[ "route_long_name"] + direction line = routefolder.newlinestring(name=name, coords=coords) line.iconstyle = simplekml.IconStyle(icon=simplekml.Icon( href="http://maps.google.com/mapfiles/kml/pal2/icon13.png")) if "route_color" in route.keys() and route.route_color != '': color = "8F" + route.route_color else: color = "8F" + default_color line.linestyle = simplekml.LineStyle(width=4, color=color) stopfolder = routefolder.newfolder(name="Stops") for stop in trip.GetPattern(): coords = [(stop.stop_lon, stop.stop_lat)] stopfolder.newpoint(coords=coords, name=stop.stop_name) # TODO: Stops not in any route #orphan_stops = kml.newfolder(name="Unused Stops") # Possible TODO: handle multiple instances of same stop kml.save("test.kml", False)
def __init__(self, path, color='FF00FF00', width=2): self.path = path self.linestrings = {} self.linestyle = simplekml.LineStyle(color=color, width=width)
link = {'tx': txRecord} rxRecords = [] for txlicense in cleanrx: if txlicense['AuthorizationNumber'] == txRecord['AuthorizationNumber'] and \ txlicense['Frequency'] == txRecord['Frequency'] and \ txlicense['Latitude'] != txRecord['Latitude'] and \ txlicense['Longitude'] != txRecord['Longitude']: rxRecords.append(txlicense) link['rx'] = rxRecords ptpLinks.append(link) print("Finding RX licenses done, starting KML generation") kml = simplekml.Kml() stl = {"linestyle": simplekml.LineStyle(width=2)} [bellStyle, rogersStyle, telusStyle, xplornetStyle, freedomStyle, otherStyle] = [simplekml.Style(stl) for i in range(6)] bellStyle.linestyle.color = 'ffff0000' # Blue rogersStyle.linestyle.color = 'ff0000ff' # Red telusStyle.linestyle.color = 'ff3CFF14' # Green xplornetStyle.linestyle.color = 'FF1478A0' # Brown freedomStyle.linestyle.color = 'ff14B4FF' # Orange otherStyle.linestyle.color = 'ffFF78F0' # Magenta for ptp in progressbar.progressbar(ptpLinks): if len(ptp['rx']) == 1: linkDesc = f""" Bandwidth(MHz): {str(float(ptp['tx']['OccupiedBandwidthKHz']) / 1000)}