def test_kml_filter(self): coordinates = [ (-76.0, 38.0, 0.0), (-76.0, 38.0, 10.0), (-76.0, 38.0, 20.0), (-76.0, 38.0, 30.0), (-76.0, 38.0, 100.0), (-76.0, 38.0, 30.0), (-76.0, 38.0, 60.0), ] filtered_out = [(0.1, 0.001, 100), (0.0, 0.0, 0)] # Create Coordinates start = TakeoffOrLandingEvent(user=self.user, uas_in_air=True) start.save() for coord in coordinates: self.create_log_element(*coord) for coord in filtered_out: self.create_log_element(*coord) end = TakeoffOrLandingEvent(user=self.user, uas_in_air=False) end.save() kml = Kml() UasTelemetry.kml(user=self.user, logs=UasTelemetry.by_user(self.user), kml=kml, kml_doc=kml) for filtered in filtered_out: tag = self.coord_format.format(filtered[1], filtered[0], filtered[2]) self.assertTrue(tag not in kml.kml()) for coord in coordinates: tag = self.coord_format.format(coord[1], coord[0], coord[2]) self.assertTrue(tag in kml.kml())
def get_kml(self, app_session): kml = Kml() node_style = Style(iconstyle=IconStyle(scale=0.8, icon=Icon( href='https://maps.google.com/mapfiles/kml/paddle/blu-circle-lv.png'))) node_folder = kml.newfolder(name="Nodes") for p in [node_folder.newpoint(name=n.name, coords=[(n.longitude, n.latitude)]) for n in app_session.data_set.query(Node).all()]: p.style = node_style node_index = {} node_counter = 0 arc_folder = kml.newfolder(name="Arcs") for flow in app_session.data_set.query(NetworkFlow).all(): if not node_index.get(flow.orig_name, None): node_index.update({flow.orig_name: node_counter}) node_counter += 1 arc_style = Style( linestyle=LineStyle(color=MapFlowOutput.get_cycled_hex_colour(node_index.get(flow.orig_name)), width=4)) l = arc_folder.newlinestring(name="arc", coords=[(flow.orig_node.longitude, flow.orig_node.latitude), (flow.dest_node.longitude, flow.dest_node.latitude)]) l.style = arc_style return kml.kml()
def test_kml_simple(self): coordinates = [ (-76.0, 38.0, 0.0), (-76.0, 38.0, 10.0), (-76.0, 38.0, 20.0), (-76.0, 38.0, 30.0), (-76.0, 38.0, 100.0), (-76.0, 38.0, 30.0), (-76.0, 38.0, 60.0), ] # Create Coordinates start = TakeoffOrLandingEvent(user=self.user, uas_in_air=True) start.save() for coord in coordinates: self.create_log_element(*coord) end = TakeoffOrLandingEvent(user=self.user, uas_in_air=False) end.save() kml = Kml() UasTelemetry.kml(user=self.user, logs=UasTelemetry.by_user(self.user), kml=kml, kml_doc=kml) for coord in coordinates: tag = self.coord_format.format(coord[1], coord[0], units.feet_to_meters(coord[2])) self.assertTrue(tag in kml.kml())
def get_kml(self, app_session): kml = Kml() # set up map points for Plants plants_folder = kml.newfolder(name="Potential Facilities") plants_points = [ plants_folder.newpoint(name=plant.name, coords=[(plant.longitude, plant.latitude)]) for plant in app_session.data_set.query(Plant).all() ] for p in plants_points: p.style = plant_style # set up map points for Shops shops_folder = kml.newfolder(name="Shops") shops_points = [ shops_folder.newpoint(name=shop.name, coords=[(shop.longitude, shop.latitude)]) for shop in app_session.data_set.query(Shop).all() ] for p in shops_points: p.style = shop_style return kml.kml()
def get_kml(self, app_session): kml = Kml() stores = app_session.data_set.query(Store).all() for store in stores: kml.newpoint(name=store.name, coords=[(store.longitude, store.latitude)]) return kml.kml()
def test_kml_simple(self): coordinates = [ (0, -76.0, 38.0, 0.0, 0), (1, -76.0, 38.0, 10.0, 0), (2, -76.0, 38.0, 20.0, 0), (3, -76.0, 38.0, 30.0, 0), (4, -76.0, 38.0, 100.0, 0), (5, -76.0, 38.0, 30.0, 0), (6, -76.0, 38.0, 60.0, 0), ] # Create Coordinates start = TakeoffOrLandingEvent(user=self.user, uas_in_air=True) start.save() start.timestamp = self.now start.save() for coord in coordinates: self.create_log_element(*coord) end = TakeoffOrLandingEvent(user=self.user, uas_in_air=False) end.save() end.timestamp = self.now + datetime.timedelta(seconds=7) end.save() kml = Kml() UasTelemetry.kml( user=self.user, logs=UasTelemetry.by_user(self.user), kml=kml, kml_doc=kml.document) for coord in coordinates: tag = self.coord_format.format(coord[2], coord[1], units.feet_to_meters(coord[3])) self.assertTrue(tag in kml.kml())
def get_kml(self, app_session): kml = Kml() person_style = Style(iconstyle=IconStyle( scale=0.8, icon=Icon( href= 'https://maps.google.com/mapfiles/kml/paddle/blu-circle-lv.png' ))) people_folder = kml.newfolder(name="Potential Facilities") for p in [ people_folder.newpoint(name=person.name, coords=[(person.longitude, person.latitude)]) for person in app_session.data_set.query(Person).all() ]: p.style = person_style place_style = Style(iconstyle=IconStyle( scale=0.4, icon=Icon( href= 'https://maps.google.com/mapfiles/kml/paddle/red-circle-lv.png' ))) places_folder = kml.newfolder(name="Places") for p in [ places_folder.newpoint(name=place.name, coords=[(place.longitude, place.latitude)]) for place in app_session.data_set.query(Place).all() ]: p.style = place_style return kml.kml()
def create_kml(start_dt, traces): mintime = datetime(2100,1,1) maxtime = datetime(1901,1,1) bbox_nw = (sys.maxint, sys.maxint) bbox_se = (-sys.maxint, -sys.maxint) kml = Kml(name="Tracer") doc = kml.newdocument() fol = doc.newfolder(name="Traces") i = 0 for id_, trace in traces: trace = list(trace) trk = fol.newgxtrack(name='Trace id: %s' % id_) times = [start_dt + timedelta(seconds=int(p['time'])) for p in trace] trk.newwhen([format_date(t) for t in times]) places = [ (float(p['lon']), float(p['lat']), 0) for p in trace ] trk.newgxcoord(places) m = min(places, key=operator.itemgetter(0)) if m[0] < bbox_nw[0] and not (m[0] == 0.0 or m[1] == 0.0): bbox_nw = m[:2] m = max(places, key=operator.itemgetter(0)) if m[0] > bbox_se[0] and not (m[0] == 0.0 or m[1] == 0.0): bbox_se = m[:2] mintime = min([mintime] + times) maxtime = max([maxtime] + times) trk.altitudemode = 'relativeToGround' trk.stylemap.normalstyle.iconstyle.icon.href = 'http://earth.google.com/images/kml-icons/track-directional/track-0.png' trk.stylemap.normalstyle.linestyle.color = CATEGORICAL_COLORS[i % len(CATEGORICAL_COLORS)] trk.stylemap.normalstyle.linestyle.width = 5 trk.stylemap.normalstyle.labelstyle.scale = 1 trk.stylemap.highlightstyle.iconstyle.icon.href = 'http://earth.google.com/images/kml-icons/track-directional/track-0.png' trk.stylemap.highlightstyle.iconstyle.scale = 1.2 trk.stylemap.highlightstyle.linestyle.color = CATEGORICAL_COLORS[i % len(CATEGORICAL_COLORS)] trk.stylemap.highlightstyle.linestyle.width = 8 i += 1 doc.lookat.gxtimespan.begin = format_date(mintime) doc.lookat.gxtimespan.end = format_date(maxtime) doc.lookat.longitude = bbox_nw[0] + (bbox_se[0] - bbox_nw[0]) / 2 doc.lookat.latitude = bbox_nw[1] + (bbox_se[1] - bbox_nw[1]) / 2 doc.lookat.range = 13000.00 #doc.lookat.longitude, doc.lookat.latitude = list(list(traces)[0][1])[0] return kml.kml()
def get_kml(self, app_session): kml = Kml() node_style = Style(iconstyle=IconStyle(scale=0.8, icon=Icon( href='https://maps.google.com/mapfiles/kml/paddle/blu-circle-lv.png'))) node_folder = kml.newfolder(name="Nodes") for p in [node_folder.newpoint(name=n.name, coords=[(n.longitude, n.latitude)]) for n in app_session.data_set.query(Node).all()]: p.style = node_style return kml.kml()
def get_kml(self, app_session): kml = Kml() def LongLat(l): return (l.longitude, l.latitude) mylocstyle = Style(iconstyle=IconStyle( scale=0.8, icon=Icon( href= 'https://maps.google.com/mapfiles/kml/paddle/blu-circle-lv.png' ))) LocsFolder = kml.newfolder(name="Locations") locations = app_session.data_set.query(Location).all() if len(locations) < 100: for p in [ LocsFolder.newpoint(name=loc.name, coords=[LongLat(loc)]) for loc in locations ]: p.style = mylocstyle mylinestyle = Style(linestyle=LineStyle(color='FF0000FF', width=4)) PathsFolder = kml.newfolder(name="Paths") paths = app_session.data_set.query(Path).all() if len(paths) < 100: for path in [ PathsFolder.newlinestring(name='path', coords=[ LongLat(l.start_location), LongLat(l.end_location) ]) for l in paths ]: path.style = mylinestyle mylinestyle = Style(linestyle=LineStyle(color='FF00FF00', width=4)) PathsFolder = kml.newfolder(name="Paths") paths = app_session.data_set.query(OutputPath).all() if len(paths) < 100: for path in [ PathsFolder.newlinestring(name='path', coords=[ LongLat(l.start_location), LongLat(l.end_location) ]) for l in paths ]: path.style = mylinestyle return kml.kml()
def flask_get_kml(): """ Return KML with autorefresh """ _config = autorx.config.global_config kml = Kml() netlink = kml.newnetworklink(name="Radiosonde Auto-RX Live Telemetry") netlink.open = 1 netlink.link.href = flask.request.host_url + "rs_feed.kml" try: netlink.link.refreshinterval = _config["kml_refresh_rate"] except KeyError: netlink.link.refreshinterval = 10 netlink.link.refreshmode = "onInterval" return kml.kml(), 200, {"content-type": "application/vnd.google-earth.kml+xml"}
def get_kml(self, app_session): kml = Kml() node_style = Style(iconstyle=IconStyle(scale=0.8, icon=Icon( href='https://maps.google.com/mapfiles/kml/paddle/blu-circle-lv.png'))) node_folder = kml.newfolder(name="Nodes") for p in [node_folder.newpoint(name=n.name, coords=[(n.longitude, n.latitude)]) for n in app_session.data_set.query(Node).all()]: p.style = node_style arc_folder = kml.newfolder(name="Arcs") Arcs = app_session.data_set.query(Arc).all() for arc in Arcs: arc_style = Style(linestyle=LineStyle(color=MapArcInput.get_cycled_hex_colour(Arcs.index(arc)), width=4)) l = arc_folder.newlinestring(name="arc", coords=[(arc.orig_node.longitude, arc.orig_node.latitude), (arc.dest_node.longitude, arc.dest_node.latitude)]) l.style = arc_style return kml.kml()
def get_kml(self, app_session): kml = Kml() for tweet in app_session.data_set.query(Tweet).all(): kml.newpoint(name=tweet.author + "-" + str(tweet.tweetId), coords=[tweet.coordinates]) return kml.kml()
def flask_get_kml_feed(): """ Return KML with RS telemetry """ kml = Kml() kml.resetidcounter() kml.document.name = "Track" kml.document.open = 1 # Station Placemark pnt = kml.newpoint( name="Ground Station", altitudemode=AltitudeMode.absolute, description="AutoRX Ground Station", ) pnt.open = 1 pnt.iconstyle.icon.href = flask.request.host_url + "static/img/antenna-green.png" pnt.coords = [ ( autorx.config.global_config["station_lon"], autorx.config.global_config["station_lat"], autorx.config.global_config["station_alt"], ) ] for rs_id in flask_telemetry_store: try: coordinates = [] for tp in flask_telemetry_store[rs_id]["track"].track_history: coordinates.append((tp[2], tp[1], tp[3])) rs_data = """\ {type}/{subtype} Frequency: {freq} Altitude: {alt:.1f} m Heading: {heading:.1f} degrees Ground Speed: {vel_h:.2f} m/s Ascent Rate: {vel_v:.2} m/s Temperature: {temp:.1f} C Humidity: {humidity:.1f} % Pressure: {pressure:.1f} hPa """ if flask_telemetry_store[rs_id]["latest_telem"]["vel_v"] > -5: icon = flask.request.host_url + "static/img/balloon-green.png" else: icon = flask.request.host_url + "static/img/parachute-green.png" # Add folder fol = kml.newfolder(name=rs_id) # HAB Placemark pnt = fol.newpoint( name=rs_id, altitudemode=AltitudeMode.absolute, description=rs_data.format( **flask_telemetry_store[rs_id]["latest_telem"] ), ) pnt.iconstyle.icon.href = icon pnt.coords = [ ( flask_telemetry_store[rs_id]["latest_telem"]["lon"], flask_telemetry_store[rs_id]["latest_telem"]["lat"], flask_telemetry_store[rs_id]["latest_telem"]["alt"], ) ] linestring = fol.newlinestring(name="Track") linestring.coords = coordinates linestring.altitudemode = AltitudeMode.absolute linestring.extrude = 1 linestring.stylemap.normalstyle.linestyle.color = "ff03bafc" linestring.stylemap.highlightstyle.linestyle.color = "ff03bafc" linestring.stylemap.normalstyle.polystyle.color = "AA03bafc" linestring.stylemap.highlightstyle.polystyle.color = "CC03bafc" # Add LOS line linestring = fol.newlinestring(name="LOS") linestring.altitudemode = AltitudeMode.absolute linestring.coords = [ ( autorx.config.global_config["station_lon"], autorx.config.global_config["station_lat"], autorx.config.global_config["station_alt"], ), ( flask_telemetry_store[rs_id]["latest_telem"]["lon"], flask_telemetry_store[rs_id]["latest_telem"]["lat"], flask_telemetry_store[rs_id]["latest_telem"]["alt"], ), ] except Exception as e: logging.error( "KML - Could not parse data from RS %s - %s" % (rs_id, str(e)) ) return ( re.sub("<Document.*>", "<Document>", kml.kml()), 200, {"content-type": "application/vnd.google-earth.kml+xml"}, )
def get_kml(self, app_session): kml = Kml() flows = app_session.data_set.query(Flow).all() # set up points for Plants used plants_used = list(set([flow.plant for flow in flows])) plants_used_folder = kml.newfolder(name="Facilities Chosen") plants_used_points = [ plants_used_folder.newpoint(name=plant.name, coords=[(plant.longitude, plant.latitude)]) for plant in plants_used ] for p in plants_used_points: p.style = plant_style # set up points for Plants not used plants_not_used_folder = kml.newfolder(name="Facilities Not Chosen") plants_not_used_points = [ plants_not_used_folder.newpoint(name=plant.name, coords=[(plant.longitude, plant.latitude)]) for plant in app_session.data_set.query(Plant).all() if plant not in plants_used ] for p in plants_not_used_points: p.style = plant_style for plant in plants_used: catchment_folder = kml.newfolder(name="Catchment for " + plant.name) catchment_points = [ catchment_folder.newpoint(name=shop.name, coords=[(shop.longitude, shop.latitude)]) for shop in [flow.shop for flow in plant.flows] ] for point in catchment_points: point.style = shop_style plant_location = catchment_folder.newpoint(name=plant.name, coords=[ (plant.longitude, plant.latitude) ]) plant_location.style = plant_style catchment_line_style = Style( linestyle=LineStyle(color=KMLMapOutput.get_cycled_hex_colour( plants_used.index(plant)), width=4)) catchment_lines = [ catchment_folder.newlinestring( name='From: %s<br>To: %s<br>Flow: %s' % (flow.plant_name, flow.shop_name, flow.volume), coords=[(flow.plant.longitude, flow.plant.latitude), (flow.shop.longitude, flow.shop.latitude)]) for flow in plant.flows ] for l in catchment_lines: l.style = catchment_line_style return kml.kml()
def export(request, ref): mosaic_obj = Mosaic.objects.get(ref=ref) if not mosaic_obj.big_preview_url: imgByteArr = mosaic_obj.generatePreview(100) response = cloudinary.uploader.upload(imgByteArr, public_id=mosaic_obj.ref + '_100') mosaic_obj.big_preview_url = response['url'] mosaic_obj.save() kml = Kml() normalstyle = Style() normalstyle.iconstyle.color = 'ffd18802' normalstyle.iconstyle.scale = 1 normalstyle.iconstyle.icon.href = 'http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png' normalstyle.iconstyle.hotspot.x = 32 normalstyle.iconstyle.hotspot.xunits = 'pixels' normalstyle.iconstyle.hotspot.y = 64 normalstyle.iconstyle.hotspot.xunits = 'insetPixels' normalstyle.labelstyle.scale = 0 normalstyle.linestyle.color = 'ffd18802' normalstyle.linestyle.width = 5 highlightstyle = Style() highlightstyle.iconstyle.color = 'ffd18802' highlightstyle.iconstyle.scale = 1 highlightstyle.iconstyle.icon.href = 'http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png' highlightstyle.iconstyle.hotspot.x = 32 highlightstyle.iconstyle.hotspot.xunits = 'pixels' highlightstyle.iconstyle.hotspot.y = 64 highlightstyle.iconstyle.hotspot.xunits = 'insetPixels' highlightstyle.labelstyle.scale = 1 stylemap = StyleMap(normalstyle, highlightstyle) folder = kml.newfolder(name=mosaic_obj.title) for mission_obj in mosaic_obj.missions.all().order_by('order'): multipnt = folder.newmultigeometry(name=mission_obj.title) multipnt.stylemap = stylemap multipnt.description = '<![CDATA[<img src="' + mosaic_obj.big_preview_url + '" height="200" width="auto" />' + mission_obj.desc + ']]>' multipnt.extendeddata.newdata('MIM link', 'https://www.myingressmosaics.com/mosaic/' + mosaic_obj.ref) pnt = multipnt.newpoint() linestring = multipnt.newlinestring(name=mission_obj.title) actions = '' coordinates = [] jsondata = json.loads(mission_obj.data) if len(jsondata) > 9: index = 0 for portal in jsondata[9]: index += 1 lat = 0.0 lng = 0.0 if portal[5]: if portal[5][0] == 'f': lat = portal[5][1] / 1000000.0 lng = portal[5][2] / 1000000.0 if portal[5][0] == 'p': lat = portal[5][2] / 1000000.0 lng = portal[5][3] / 1000000.0 actions += str(index) + '.' if portal[2] == 'Unavailable': actions += 'Unavailable ' else: if portal[4] == 1: actions += 'hack ' if portal[4] == 2: actions += 'capture ' if portal[4] == 7: actions += 'view ' if portal[4] == 8: actions += 'passphrase ' if lat and lng: coordinates.append((lng, lat)) if lat and lng and index==1: pnt.coords = [(lng, lat)] linestring.coords = coordinates multipnt.extendeddata.newdata('actions', actions) response = HttpResponse(kml.kml()) response['Content-Disposition'] = 'attachment; filename="' + mosaic_obj.title + '.kml"' response['Content-Type'] = 'application/kml' return response