def main(filelist: list, maxw: int, maxh: int, bunchup: int): infos = { filepath: info for filepath, info in sorted(gen_gpsinfos(filelist), key=lambda stuff: stuff[1]['timestamp']) } # calculate distances & create spatial clusters dists = [(f1, f2, haversine(infos[f1]['lon'], infos[f1]['lat'], infos[f2]['lon'], infos[f2]['lat'])) for f1, f2 in combinations(infos.keys(), 2)] distmap = defaultdict(dict) clusters = defaultdict(set) for f1, f2, dist in dists: distmap[f1][f2] = dist distmap[f2][f1] = dist if dist > bunchup: continue clusters[f1].add(f2) clusters[f2].add(f1) kml = simplekml.Kml() seen = set() # track which files we've handled for filepath, info in infos.items(): if filepath in seen: continue # already handled cluster = clusters[filepath] cluster -= seen # skip files already handled (as part of other clusters) cluster.add(filepath) seen |= cluster # mark all in cluster as handled # sort by time taken, filename clusterfiles = { fname: infos[fname] for fname in sorted(cluster, key=basename) } clusterfiles = dict( sorted( clusterfiles.items(), key=lambda pair: pair[1].get('timestamp', datetime(1, 1, 1)))) # within the cluster, find the most central point and use its coordinates as the coordinates of the whole cluster mostcentral = sorted( ((f1, sum((distmap[f1].get(f2, 0) for f2 in cluster))) for f1 in cluster), key=lambda pair: pair[1])[0][0] # fiddly bit to arrive at a nice point name, depending on how many files and whether there are timestamps available tstamps = sorted( filter(None, (info.get('timestamp') for info in clusterfiles.values()))) pointfile_basename = basename(filepath) pointname = pointfile_basename if len(cluster) > 1: pointname = "%d pics" % len(cluster) if tstamps: tmin, tmax = tstamps[0].date(), tstamps[-1].date() if tmin == tmax: pointname += f' @ {str(tmin)}' else: pointname += f' @ {str(tmin)} — {str(tmax)}' point = kml.newpoint(name=pointname) gpsinfo = infos[mostcentral] point.coords = [ tuple((round(num, 6) for num in (gpsinfo['lon'], gpsinfo['lat'], gpsinfo.get('altitude', 0)))) ] # https://xkcd.com/2170/ point.style = simplekml.Style() mycolor = text2kmlcolor(pointfile_basename) point.style.labelstyle.color = mycolor point.style.iconstyle.color = mycolor point.style.iconstyle.icon.href = 'http://maps.google.com/mapfiles/kml/shapes/camera.png' imagelinks = [] # create the minipage with the pictures for cfname, cinfo in clusterfiles.items(): fullpath, thebasename = abspath(cfname), basename(cfname) title = thebasename if 'timestamp' in cinfo: title = f"""{thebasename} @ {cinfo['timestamp'].isoformat()}""" imagelinks.append( f'''<h1>{xmlentityize(title)}</h1><img style="max-width:{maxw}; max-height:{maxh}px" src="file://{urlquote(fullpath)}">''' ) point.description = F'''<![CDATA[{''.join(imagelinks)}]]>''' print(kml.kml())
fp.write("JETTISON AREA (lon, lat)[deg]:\n") fp.write("\t{0:}, {1:}\n".format(p1[0], p1[1])) fp.write("\t{0:}, {1:}\n".format(p2[0], p2[1])) fp.write("\t{0:}, {1:}\n".format(p3[0], p3[1])) fp.write("\t{0:}, {1:}\n".format(p4[0], p4[1])) fp.write("\t{0:}, {1:}\n".format(p1[0], p1[1])) fp.write("JETTISON ELLIPSE (3 SIGMA) (lon, lat)[deg]:\n") for i in range(37): angle = np.pi / 180 * i * 10 p_tmp = 3 * v1 * math.cos(angle) + 3 * v2 * math.sin(angle) + ave fp.write("\t{0:}, {1:}\n".format(p_tmp[0], p_tmp[1])) fp.close() os.system("aws s3 cp {1:s} s3://otmc/{0:s}/stat/output/ ".format( otmc_mission_name, outputfile)) kml = simplekml.Kml(open=1) kml.newpoint(name="Average LandIn Point", coords=[(ave[0], ave[1])]) inc_area = kml.newlinestring(name="LandIn Inclusion Area") inc_area.coords = [(p1[0],p1[1]),\ (p2[0],p2[1]),\ (p3[0],p3[1]),\ (p4[0],p4[1]),\ (p1[0],p1[1])] inc_area.style.linestyle.color = simplekml.Color.red linestring = kml.newlinestring(name="LandIn Elliposoid Area") arr_coords = [] for i in range(37): angle = np.pi / 180 * i * 10
# Given device id, read dwells file to extract dwells # Read trace data, get traces default_colors = [ 'ffee82ee', 'ff82004b', 'ffff0000', 'ffffff00', 'ff008000', 'ff32cd9a', 'ff00ffff', 'ff00a5ff', 'ff0045ff', 'ff0000ff' ] icon_url = 'http://maps.google.com/mapfiles/kml/shapes/shaded_dot.png' venue_url = 'http://maps.google.com/mapfiles/kml/shapes/ranger_station.png' infilename = sys.argv[1] outfilename = sys.argv[2] #infilename = '/Users/jlenaghan/tmp/back_prop/'+campaign+'.csv' #outfilename = '/Users/jlenaghan/tmp/back_prop/'+campaign+'.kml' kml_file = simplekml.Kml() count = 0 prev_dev = 'prev_dev' infile = open(infilename, 'r') for row in infile: dev_id, tile_id, sts, cts, dev, bl1, bl2, geom, bl3 = row.strip().split( ',') if prev_dev != dev_id: count += 1 prev_dev = dev_id geom = geom.replace("POINT(", "") geom = geom.replace(")", "") lng, lat = geom.split() pnt = kml_file.newpoint(coords=[(float(lng), float(lat))]) pnt.iconstyle.color = default_colors[count % 10] pnt.iconstyle.scale = 1
import json import simplekml ''' 1 pip install simplekml 2 修改jsonpath路径 ''' jsonpath = './shenzhenG107_RoadSign_WGS84.json' with open(jsonpath, 'r') as f: jsondata = json.loads(f.read()) coord = jsondata['Rectangle Signs:'] kml = simplekml.Kml() for key in coord: coord11, coord22 = [], [] coord_pair = [] coord1 = key['Coord'][0] coord2 = key['Coord'][1] coord11.append(coord1[1]) coord11.append(coord1[0]) coord11.append(coord1[2]) coord22.append(coord2[1]) coord22.append(coord2[0]) coord22.append(coord2[2])
from LocalPredict import * import datetime import simplekml tracks = [("Duchesne", (40.191903, -110.38099, 5826)), ("Myton", (40.149089, -110.127036, 5826)), ("Delta", (39.3806386, -112.5077147, 4759)), ("Evanston", (41.2747778, -111.0346389, 7143)), ("Roosevelt", (40.296358, -109.986943, 5331)), ("Near Delta", (39.6676, -113.1269, 5220))] launchtime = datetime.datetime(year=2012, month=11, day=4, hour=9, minute=0) ascentrate = 1045 descentrate = 1763 burstaltitude = 98000 kml = simplekml.Kml(name='Predictions') for name, launchsite in tracks: #LocalPredict.main(launchtime=launchtime,launchsite=launchsite,writefile=str(track[0])+"Prediction.kml",messages=True) if launchtime == None: launchtime = datetime.datetime.now() wxstation = getClosestStation(launchsite) wxstation = wxstation[0] data = getData(launchtime, wxstation, "GFS") if data == "" or data == None: print "No Data, Loading from File...\n*** Warning, this data may be out of date ***" data = getDataFromFile() else: saveDataToFile(data=data) atmosphere = parse_wind(data) track = makeTrack(atmosphere, launchsite, ascentrate, descentrate, burstaltitude)