public async Task <bool> ShowFriendsOnMap(ToggleSwitch toggleSwitch, Pushpin userPin) { const int myEntityId = 1; var furthestAwayFriend = 1.0; var switchName = toggleSwitch.Content.ToString(); var layerName = toggleSwitch.LayerName(); toggleSwitch.Opacity = 0.8; var tagLayer = this.FindOrAddLayerByName(layerName); var results = await Discovr.Classes.Core.LocationEntity.GetFriends(myEntityId, switchName); if (results != null) { ClearLayer(tagLayer); var pointToCompareTo = userPin != null && userPin.GeoCoordinate != null ? userPin.GeoCoordinate : MainMap.Center; var newColor = Extensions.GetRandomColor(); toggleSwitch.SwitchForeground = newColor; foreach (var result in results) { var distanceToFriend = Map.AddOrUpdatePinToLayer(pointToCompareTo, new GeoCoordinate(result.Latitude, result.Longitude), result.EntityLabel, result.AvatarUrl, tagLayer, true, null, newColor, new AppSettings().ShowMetric); furthestAwayFriend = distanceToFriend > furthestAwayFriend ? distanceToFriend : furthestAwayFriend; } MainMap.ZoomLevel = GeoConverter.GetZoomLevelFromMeters(furthestAwayFriend); toggleSwitch.Opacity = 1; } return(true); }
private void areaMap1_DragDrop(object sender, DragEventArgs e) { Shape2 shape = null; Area area = null; if (e.Data.GetDataPresent(typeof(Polygon2))) { shape = (Polygon2)e.Data.GetData(typeof(Polygon2)); } else { if (e.Data.GetDataPresent(typeof(Area))) { area = (Area)e.Data.GetData(typeof(Area)); } else { shape = (Circle)e.Data.GetData(typeof(Circle)); } } Point mapDropPoint = AreaMapComponent.PointToClient(new Point(e.X, e.Y)); mapDropPoint.Offset(GeoConverter.ConvertRound(AreaMapComponent.Offset * -1)); if (shape != null) { shape.Offset((new Vector2(mapDropPoint.X, mapDropPoint.Y)) * (1f / AreaMapComponent.Scaling)); shape.Clamp(0, AreaMapComponent.Dimensions.Width, 0, AreaMapComponent.Dimensions.Height); AreaMapComponent.AddShape(shape); RefreshListBox(); } else if (area != null) { //Has a picture with path relative to library if (area.ImgPath != "" && area.ImgPath != libraryUCtrl1.AreaMapComp.CurrentAreaMap.GetAbsolutePath(area.ImgPath)) { if (AreaMapComponent.CurrentAreaMap.Path != "") { area.Map = libraryUCtrl1.AreaMapComp.CurrentAreaMap; AreaMapComponent.Migrate(area, PathHelper.GetFolderPath(AreaMapComponent.CurrentAreaMap.Path)); } else { MessageBox.Show("You must save your AreaMap to be able to use library items with relative pictures !", "File not saved"); return; } } area.Center = (new Vector2(mapDropPoint.X, mapDropPoint.Y)) * (1f / AreaMapComponent.Scaling); area.Clamp(0, AreaMapComponent.Dimensions.Width, 0, AreaMapComponent.Dimensions.Height); area.SetRefCenter(); AreaMapComponent.AddArea(area); RefreshListBox(); } }
public override void DidUpdateUserLocation(MKMapView mapView, MKUserLocation userLocation) { if (userLocation != null && !m_HasZoomedToUser) { CLLocationCoordinate2D coords = mapView.UserLocation.Coordinate; MKCoordinateSpan span = new MKCoordinateSpan(GeoConverter.MilesToLatitudeDegrees(MapSettings.ScreenMapSpan), GeoConverter.MilesToLongitudeDegrees(MapSettings.ScreenMapSpan, coords.Latitude)); mapView.Region = new MKCoordinateRegion(coords, span); m_HasZoomedToUser = true; } }
/// <summary> /// Draws the Lat/Lon Grid spaced by 10 degrees each using the GeoConverter /// </summary> /// <param name="bmp">The Bitmap</param> /// <param name="gc">A geoconverter initialized with Satellite Parameters</param> /// <param name = "color"></param> /// <param name = "lineWidth"></param> /// <param name = "fixCrop"></param> public static void DrawLatLonLines(ref Bitmap bmp, GeoConverter gc, Color color, int lineWidth = 5, bool fixCrop = false) { var pen = new Pen(color, lineWidth); using (var graphics = Graphics.FromImage(bmp)) { float lastX; float lastY; for (var lat = gc.MinLatitude; lat < gc.MaxLatitude; lat += 10f) { lastX = float.NaN; lastY = float.NaN; for (var lon = gc.MinLongitude; lon < gc.MaxLongitude; lon += 0.1f) { var xy = gc.latlon2xy(lat, lon); if (fixCrop) { xy = new Tuple <int, int>(xy.Item1 - gc.CropLeft, xy.Item2); } if (!float.IsNaN(lastX) && !float.IsNaN(lastY)) { graphics.DrawLine(pen, lastX, lastY, xy.Item1, xy.Item2); } lastX = xy.Item1; lastY = xy.Item2; } } for (var lon = gc.MinLongitude; lon < gc.MaxLongitude; lon += 10f) { lastX = float.NaN; lastY = float.NaN; for (var lat = gc.MinLatitude; lat < gc.MaxLatitude; lat += 0.1f) { var xy = gc.latlon2xy(lat, lon); if (fixCrop) { xy = new Tuple <int, int>(xy.Item1 - gc.CropLeft, xy.Item2); } if (!float.IsNaN(lastX) && !float.IsNaN(lastY)) { graphics.DrawLine(pen, lastX, lastY, xy.Item1, xy.Item2); } lastX = xy.Item1; lastY = xy.Item2; } } } }
public static void LoadLRIT() { UIConsole.Log($"Loading Headers from Visible file at {visFilename}"); XRITHeader header = FileParser.GetHeaderFromFile(visFilename); Regex x = new Regex(@".*\((.*)\)", RegexOptions.IgnoreCase); var regMatch = x.Match(header.ImageNavigationHeader.ProjectionName); satelliteLongitude = float.Parse(regMatch.Groups[1].Captures[0].Value, CultureInfo.InvariantCulture); var inh = header.ImageNavigationHeader; gc = new GeoConverter(satelliteLongitude, inh.ColumnOffset, inh.LineOffset, inh.ColumnScalingFactor, inh.LineScalingFactor); var od = new OrganizerData(); od.Segments.Add(0, visFilename); od.FirstSegment = 0; od.Columns = header.ImageStructureHeader.Columns; od.Lines = header.ImageStructureHeader.Lines; od.ColumnOffset = inh.ColumnOffset; od.PixelAspect = 1; UIConsole.Log($"Generating Visible Bitmap"); bmp = ImageTools.GenerateFullImage(od); if (bmp.PixelFormat != PixelFormat.Format32bppArgb) { bmp = bmp.ToFormat(PixelFormat.Format32bppArgb, true); } // od.Segments[0] = irfilename; irBmp = ImageTools.GenerateFullImage(od); if (bmp.PixelFormat != PixelFormat.Format32bppArgb) { bmp = bmp.ToFormat(PixelFormat.Format32bppArgb, true); } // Geo Converter latRange = new[] { gc.MinLatitude, gc.MaxLatitude }; lonRange = new[] { gc.MinLongitude, gc.MaxLongitude }; coverage = new[] { gc.LatitudeCoverage, gc.LongitudeCoverage }; trim = new[] { gc.TrimLatitude, gc.TrimLongitude }; size = new[] { (uint)bmp.Width, (uint)bmp.Height }; coff = inh.ColumnOffset; loff = inh.LineOffset; cfac = inh.ColumnScalingFactor; lfac = inh.LineScalingFactor; }
/// <summary> /// Agent that runs a scheduled task /// </summary> /// <param name="task"> /// The invoked task /// </param> /// <remarks> /// This method is called when a periodic or resource intensive task is invoked /// </remarks> protected async override void OnInvoke(ScheduledTask task) { var geolocator = new Geolocator(); var maximumAge = TimeSpan.FromMinutes(1); var timeOut = TimeSpan.FromSeconds(30); try { var geoposition = await geolocator.GetGeopositionAsync(maximumAge, timeOut); if (geoposition != PreviousPosition) { var userLocation = GeoConverter.ConvertGeocoordinate(geoposition.Coordinate); PreviousPosition = geoposition; // TODO: Send update to cloud server //var toast = new ShellToast //{ // Title = "Location DiscovR'd", // Content = string.Format("{0}:{1} {2} accuracy", userLocation.Latitude, userLocation.Longitude, GeoConverter.MetersToReadableString(geoposition.Coordinate.Accuracy, true)) //}; //toast.Show(); } else { //var toast = new ShellToast { Title = "DiscovR", Content = string.Format("You haven't moved!") }; //toast.Show(); } } catch (Exception ex) { if ((uint)ex.HResult == 0x80004004) { var toast = new ShellToast { Title = "DiscovR", Content = "Location is disabled on this device :(" }; toast.Show(); } } NotifyComplete(); }
public static Bitmap ReprojectLinear(Bitmap bmp, GeoConverter gc, bool fixCrop = false) { var output = new Bitmap(bmp.Width, bmp.Height, PixelFormat.Format32bppArgb); var pdata = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); var odata = output.LockBits(new Rectangle(0, 0, output.Width, output.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); unsafe { var dPtr = (byte *)odata.Scan0.ToPointer(); var pPtr = (byte *)pdata.Scan0.ToPointer(); var stride = odata.Stride; for (var y = 0; y < output.Height; y++) { for (var x = 0; x < output.Width; x++) { var lat = (gc.MaxLatitude - gc.TrimLatitude) - ((y * (gc.LatitudeCoverage - gc.TrimLatitude * 2)) / output.Height); var lon = ((x * (gc.LongitudeCoverage - gc.TrimLongitude * 2)) / output.Width) + (gc.MinLongitude + gc.TrimLongitude); if (lat > gc.MaxLatitude || lat < gc.MinLatitude || lon > gc.MaxLongitude || lon < gc.MinLongitude) { dPtr [y * stride + x] = 0; } else { var xy = gc.latlon2xyf(lat, lon); var newx = xy.Item1; var newy = xy.Item2; if (fixCrop) { newx -= gc.CropLeft; } dPtr [y * stride + x * 4 + 0] = BilinearInterp(pPtr, newx, newy, pdata.Stride, 0); dPtr [y * stride + x * 4 + 1] = BilinearInterp(pPtr, newx, newy, pdata.Stride, 1); dPtr [y * stride + x * 4 + 2] = BilinearInterp(pPtr, newx, newy, pdata.Stride, 2); dPtr [y * stride + x * 4 + 3] = BilinearInterp(pPtr, newx, newy, pdata.Stride, 3); } } } } bmp.UnlockBits(pdata); output.UnlockBits(odata); return(output); }
private void GenerateImageOverlay(ref Bitmap bmp, GroupData gd, OrganizerData od) { var columnOffset = od.ColumnOffset != -1 ? od.ColumnOffset : gd.FallBackColumnOffset; var lineOffset = od.LineOffset != -1 ? od.LineOffset : gd.FallBackLineOffset; var columnScalingFactor = od.ColumnScalingFactor != 0 ? od.ColumnScalingFactor : gd.FallBackColumnScalingFactor; var lineScalingFactor = od.LineScalingFactor != 0 ? od.LineScalingFactor : gd.FallBackLineScalingFactor; if (gd.HasNavigationData) { var gc = new GeoConverter(gd.SatelliteLongitude, columnOffset, lineOffset, columnScalingFactor, lineScalingFactor, true, od.Columns); if (mapDrawer != null && GenerateMapOverlays) { mapDrawer.DrawMap(ref bmp, gc, MapOverlayPenColor, MapOverlayPenThickness, gd.CropImage); } if (GenerateLatLonOverlays) { ImageTools.DrawLatLonLines(ref bmp, gc, LatLonOverlayPenColor, LatLonOverlayPenThickness, gd.CropImage); } if (EnableReproject) { var reprojBmp = ImageTools.ReprojectLinear(bmp, gc, gd.CropImage); bmp.Dispose(); bmp = reprojBmp; } if (GenerateLabels) { ImageTools.ImageLabel(ref bmp, gd, od, gc, GenerateLatLonLabel); } } else if (GenerateLabels) { ImageTools.ImageLabel(ref bmp, gd, od, null, false); } }
public async void LoadLRIT() { await Task.Run(async() => { LockControls(); UIConsole.Log($"Loading Headers from Visible file at {visFilename}"); XRITHeader header = FileParser.GetHeaderFromFile(visFilename); Regex x = new Regex(@".*\((.*)\)", RegexOptions.IgnoreCase); var regMatch = x.Match(header.ImageNavigationHeader.ProjectionName); float satelliteLongitude = float.Parse(regMatch.Groups[1].Captures[0].Value, CultureInfo.InvariantCulture); var inh = header.ImageNavigationHeader; gc = new GeoConverter(satelliteLongitude, inh.ColumnOffset, inh.LineOffset, inh.ColumnScalingFactor, inh.LineScalingFactor); var od = new OrganizerData(); od.Segments.Add(0, visFilename); od.FirstSegment = 0; od.Columns = header.ImageStructureHeader.Columns; od.Lines = header.ImageStructureHeader.Lines; od.ColumnOffset = inh.ColumnOffset; od.PixelAspect = 1; UIConsole.Log($"Generating Visible Bitmap"); visBmp = ImageTools.GenerateFullImage(od); visBmp = ImageTools.ResizeImage(visBmp, visBmp.Width / 4, visBmp.Height / 4, true); od = new OrganizerData(); od.Segments.Add(0, irfilename); od.FirstSegment = 0; od.Columns = header.ImageStructureHeader.Columns; od.Lines = header.ImageStructureHeader.Lines; od.ColumnOffset = inh.ColumnOffset; od.PixelAspect = 1; UIConsole.Log($"Generating Infrared Bitmap"); irBmp = ImageTools.GenerateFullImage(od); irBmp = ImageTools.ResizeImage(irBmp, irBmp.Width / 4, irBmp.Height / 4, true); UIConsole.Log("Generating False Color"); await GenerateFalseColor(); UIConsole.Log("Done"); UnlockControls(); }); }
private void GenerateImageOverlay(ref Bitmap bmp, GroupData gd, OrganizerData od) { if (gd.HasNavigationData) { var gc = new GeoConverter(gd.SatelliteLongitude, gd.ColumnOffset, gd.LineOffset, gd.ColumnScalingFactor, gd.LineScalingFactor, true, od.Columns); if (mapDrawer != null && GenerateMapOverlays) { mapDrawer.DrawMap(ref bmp, gc, MapOverlayPenColor, MapOverlayPenThickness, gd.CropImage); } if (GenerateLatLonOverlays) { ImageTools.DrawLatLonLines(ref bmp, gc, LatLonOverlayPenColor, LatLonOverlayPenThickness, gd.CropImage); } if (GenerateLabels) { ImageTools.ImageLabel(ref bmp, gd, od, gc, GenerateLatLonLabel); } } else if (GenerateLabels) { ImageTools.ImageLabel(ref bmp, gd, od, null, false); } }
public void Draw(Graphics inGraphics, Vector2 inOffset, float inScale) { if (_isVisible) { //Adjust font if (_fontChanged) { _fontChanged = false; _textSize = TextFont.Size / inScale; } else { _textFont = new Font(_textFont.FontFamily, _textSize * inScale, _textFont.Style); } //Image if (_image != null && _imgIsBackground) { inGraphics.DrawImage(_image, inOffset.X + (RefCenter.X + _imgPosition.X) * inScale, inOffset.Y + (RefCenter.Y + _imgPosition.Y) * inScale, _imgDimension.X * inScale * _imgScaling.X, _imgDimension.Y * inScale * _imgScaling.Y); } Pen framePen = _smoothPen; //Bounds if (IsMovable && !IsSubComponent) { float minBounds = 10f; if (IsSelected || IsHovered) { //Use a more solid pen framePen = _blackPen; } Vector2 center = Center; float width = Math.Max(minBounds, MaxX - MinX); float height = Math.Max(minBounds, MaxY - MinY); float x = _refCenter.X + MinX - (IsMovableX ? 0f : minBounds / 2f); float y = _refCenter.Y + MinY - (IsMovableY ? 0f : minBounds / 2f); //Pointer inGraphics.DrawRectangle(framePen, inOffset.X + center.X * inScale - 1, inOffset.Y + center.Y * inScale - 1, 2, 2); //Bounds inGraphics.DrawRectangle(framePen, inOffset.X + x * inScale - 1, inOffset.Y + y * inScale - 1, width * inScale + 2, height * inScale + 2); inGraphics.DrawRectangle(_whitePen, inOffset.X + x * inScale, inOffset.Y + y * inScale, width * inScale, height * inScale); //Suggested Bounds if (HasLimits()) { float internalMinXOffset = 0f; float internalMaxXOffset = 0f; if (!_xYSymmetryMode) { if (_minSuggestedX != _maxSuggestedX) { if (IsMovableX) { if (_minSuggestedX > ValueMinX) { internalMinXOffset = (_minSuggestedX - ValueMinX) * inScale / _xMultiply; inGraphics.FillRectangle(_redBrush, inOffset.X + x * inScale + 1, inOffset.Y + y * inScale + 1, internalMinXOffset - 1, height * inScale - 2); } if (_maxSuggestedX < ValueMaxX) { internalMaxXOffset = (ValueMaxX - _maxSuggestedX) * inScale / _xMultiply; inGraphics.FillRectangle(_redBrush, inOffset.X + (x + width) * inScale - internalMaxXOffset, inOffset.Y + y * inScale + 1, internalMaxXOffset - 1, height * inScale - 2); } } } } if (_minSuggestedY != _maxSuggestedY) { if (IsMovableY) { float internalMinYOffset = 0f; float internalMaxYOffset = 0f; if (_minSuggestedY > ValueMinY) { internalMinYOffset = (_minSuggestedY - ValueMinY) * inScale / _yMultiply; inGraphics.FillRectangle(_redBrush, inOffset.X + x * inScale + internalMinXOffset, inOffset.Y + (y + height) * inScale - 1 - internalMinYOffset, width * inScale - internalMinXOffset - internalMaxXOffset, internalMinYOffset); } if (_maxSuggestedY < ValueMaxY) { internalMaxYOffset = (ValueMaxY - _maxSuggestedY) * inScale / _yMultiply; inGraphics.FillRectangle(_redBrush, inOffset.X + x * inScale + internalMinXOffset, inOffset.Y + y * inScale + 1, width * inScale - internalMinXOffset - internalMaxXOffset, internalMaxYOffset - 1); } } } } } //Shape switch (RealType) { case ShapeType.Circle: //Circle Shape inGraphics.FillEllipse(CurrentBrush, inOffset.X + Corner.X * inScale, inOffset.Y + Corner.Y * inScale, Radius * 2 * inScale, Radius * 2 * inScale); if (_borderColor.A > 0) { inGraphics.DrawEllipse(CurrentPen, inOffset.X + Corner.X * inScale, inOffset.Y + Corner.Y * inScale, Radius * 2 * inScale, Radius * 2 * inScale); //Button style if (Behavior == AreaBehavior.Button) { inGraphics.DrawEllipse(CurrentPen, inOffset.X + Corner.X * inScale + 2, inOffset.Y + Corner.Y * inScale + 2, Radius * 2 * inScale - 4, Radius * 2 * inScale - 4); } } break; case ShapeType.Polygon: //Polygon Shape Polygon2 poly = _shape as Polygon2; if (Points.Count > 2) { PointF[] points = GeoConverter.Convert(Points, inOffset, inScale); inGraphics.FillPolygon(CurrentBrush, points); if (_borderColor.A > 0) { inGraphics.DrawPolygon(CurrentPen, points); } } break; case ShapeType.Rectangle: //Rectangle Shape GeometryLib.Rectangle rect = _shape as GeometryLib.Rectangle; Vector2 corner = inOffset + (rect.Corner * inScale); inGraphics.FillRectangle(CurrentBrush, corner.X, corner.Y, rect.Width * inScale, rect.Height * inScale); if (_borderColor.A > 0) { inGraphics.DrawRectangle(CurrentPen, corner.X, corner.Y, rect.Width * inScale, rect.Height * inScale); //Button style if (Behavior == AreaBehavior.Button) { inGraphics.DrawRectangle(CurrentPen, corner.X + 2, corner.Y + 2, rect.Width * inScale - 4, rect.Height * inScale - 4); } } break; } //Image if (_image != null && !_imgIsBackground) { inGraphics.DrawImage(_image, inOffset.X + (Corner.X + _imgPosition.X) * inScale, inOffset.Y + (Corner.Y + _imgPosition.Y) * inScale, _imgDimension.X * inScale * _imgScaling.X, _imgDimension.Y * inScale * _imgScaling.Y); } //Text if (!string.IsNullOrEmpty(Text)) { inGraphics.DrawString(_text, _textFont, _textBrush, new PointF(inOffset.X + (Corner.X + _textPosition.X) * inScale, inOffset.Y + (Corner.Y + _textPosition.Y) * inScale)); } } }
public static void ImageLabel(ref Bitmap inbmp, GroupData gd, OrganizerData od, GeoConverter gc, bool genLatLonLabel) { var usedFontSize = FONT_SIZES [0]; if (inbmp.Width >= 4000) { usedFontSize = FONT_SIZES [3]; } else if (inbmp.Width >= 2000) { usedFontSize = FONT_SIZES [2]; } else if (inbmp.Width >= 1000) { usedFontSize = FONT_SIZES [1]; } var bgBrush = new SolidBrush(Color.Black); var font = new Font("Arial", usedFontSize); var fontBrush = new SolidBrush(Color.White); var upperText = $"{gd.SatelliteName} ({gd.SatelliteLongitude}) - {gd.RegionName}"; var usedLabelSize = PADDING * 2; using (var g = Graphics.FromImage(inbmp)) { usedLabelSize += (int)Math.Round(g.MeasureString(upperText, font).Height); } var bmp = new Bitmap(inbmp.Width, inbmp.Height + ((genLatLonLabel && gc != null) ? usedLabelSize * 3 : usedLabelSize * 2), inbmp.PixelFormat); var sf = new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center }; if (od.FileHeader != null && od.FileHeader.SubProduct.Name != "None") { upperText = upperText + " - " + od.FileHeader.SubProduct.Name; } var dt = LLTools.UnixTimeStampToDateTime(od.Timestamp); var lowerText = $"{dt.ToShortDateString ()} {dt.ToLongTimeString()} UTC - {OSPLABEL}"; using (var g = Graphics.FromImage(bmp)) { g.CompositingQuality = CompositingQuality.HighQuality; g.FillRectangle(bgBrush, 0, 0, bmp.Width, bmp.Height); g.DrawImage(inbmp, 0, usedLabelSize, inbmp.Width, inbmp.Height); // Upper Label // var textSize = g.MeasureString (upperText, font); var rect = new RectangleF(PADDING, 0, bmp.Width - PADDING * 2, usedLabelSize); g.DrawString(upperText, font, fontBrush, rect, sf); // Lower Label with Lat/Lon if (genLatLonLabel && gc != null) { var latlon = gc.xy2latlon(inbmp.Width / 2, inbmp.Height / 2); var lat = latlon.Item1.ToString("##.000000", CultureInfo.InvariantCulture); var lon = latlon.Item2.ToString("##.000000", CultureInfo.InvariantCulture); var latLonText = $"Center Coord: ({lat}; {lon})"; lowerText += $"\r\n{latLonText}"; // textSize = g.MeasureString (lowerText, font); rect = new RectangleF(PADDING, usedLabelSize + inbmp.Height, bmp.Width - PADDING * 2, usedLabelSize * 2); g.DrawString(lowerText, font, fontBrush, rect, sf); } else // Lower Label without Lat/Lon // textSize = g.MeasureString (lowerText, font); { rect = new RectangleF(PADDING, usedLabelSize + inbmp.Height, bmp.Width - PADDING * 2, usedLabelSize); g.DrawString(lowerText, font, fontBrush, rect, sf); } } inbmp.Dispose(); inbmp = bmp; }
/// <summary> /// Creates a new PushPin, adds it to the layer then returns the distance to the friend. /// </summary> public static double AddOrUpdatePinToLayer(GeoCoordinate pointToCompareTo, GeoCoordinate friendLocation, string friendLabel, string avatarUrl, MapLayer mapLayer, bool isFriend, Pushpin existingPin, Brush pinColor, bool showMetric) { var newPin = existingPin ?? new Pushpin(); newPin.Name = isFriend ? "Pin_" + friendLabel : UserPinName; if (pinColor != null) { newPin.Background = pinColor; } // This will hold our text and image var pinPanel = new StackPanel(); newPin.GeoCoordinate = friendLocation; var distanceToFriend = newPin.GeoCoordinate.GetDistanceTo(pointToCompareTo); // Define the image to use as the pushpin icon. var pinImage = new Image(); pinImage.Source = !String.IsNullOrEmpty(avatarUrl) ? new BitmapImage(new Uri(avatarUrl, UriKind.Absolute)) : new BitmapImage(new Uri("https://lh3.googleusercontent.com/-2cAEJfwgJU0/AAAAAAAAAAI/AAAAAAAAAAA/2qq4qKqgmlA/s80-c-k-no/photo.jpg", UriKind.Absolute)); pinImage.HorizontalAlignment = HorizontalAlignment.Left; pinImage.VerticalAlignment = VerticalAlignment.Top; pinImage.Height = 56; pinImage.Width = 56; pinPanel.Children.Add(pinImage); var textContent = new TextBlock(); textContent.HorizontalAlignment = HorizontalAlignment.Left; textContent.VerticalAlignment = VerticalAlignment.Top; textContent.Margin = new Thickness(65, -56, 5, 0); if (isFriend) { textContent.Text = String.Format("{0} is here!", friendLabel) + Environment.NewLine + GeoConverter.MetersToReadableString(distanceToFriend, showMetric) + " from you"; } else { textContent.Text = friendLabel; } pinPanel.Children.Add(textContent); newPin.Content = pinPanel; if (existingPin == null) { var pinOverlay = new MapOverlay(); pinOverlay.Content = newPin; pinOverlay.GeoCoordinate = friendLocation; pinOverlay.PositionOrigin = new Point(0, 1); mapLayer.Add(pinOverlay); } return(distanceToFriend); }
private async void ShowLocationOnMap() { if (_currentlySearching) { return; } if (AppSettings.LocationConsent == false) { // The user has opted out of Location. LoadingBar.Opacity = 0; return; } _currentlySearching = true; var maximumAge = TimeSpan.FromSeconds(10); var timeOut = TimeSpan.FromSeconds(5); Geolocator.DesiredAccuracyInMeters = 4000; // If we aleady have a pin, let's see if we can be more accurate if (Map.UserLayer != null) { Geolocator.DesiredAccuracy = PositionAccuracy.High; timeOut = TimeSpan.FromSeconds(20); } try { var geoposition = await Geolocator.GetGeopositionAsync(maximumAge, timeOut); var userLocation = GeoConverter.ConvertGeocoordinate(geoposition.Coordinate); MainMap.Center = userLocation; if (!double.IsNaN(userLocation.Course)) { MainMap.Heading = userLocation.Course; } MainMap.Pitch = GeoConverter.GetPitchFromSpeed(userLocation.Speed); Pushpin pin = null; if (Map.UserLayer != null && Map.UserLayer.Any()) { var overlay = Map.UserLayer[0]; if (overlay != null) { pin = (Pushpin)overlay.Content; overlay.GeoCoordinate = userLocation; } } else { Map.UserLayer = new MapLayer(); MainMap.Layers.Add(Map.UserLayer); } var extraInfo = !double.IsNaN(userLocation.Speed) ? GeoConverter.MetersPerSecondToReadableString(userLocation.Speed, AppSettings.ShowMetric) : string.Format("{0} accuracy", GeoConverter.MetersToReadableString(geoposition.Coordinate.Accuracy, AppSettings.ShowMetric)); Map.AddOrUpdatePinToLayer(userLocation, userLocation, string.Format("You are here!{0}{1}", Environment.NewLine, extraInfo), UserAvatar, Map.UserLayer, false, pin, (Brush)Resources["PhoneAccentBrush"], AppSettings.ShowMetric); if (_friendLocation != null) { var friendCoordinate = new GeoCoordinate(_friendLocation.Latitude, _friendLocation.Longitude); var distanceToFriend = Map.AddOrUpdatePinToLayer(userLocation, friendCoordinate, _friendLocation.Label, string.Empty, Map.UserLayer, true, null, null, AppSettings.ShowMetric); // Center the map on the friend and zoom out enough to see both if (_resetZoom) { MainMap.Center = friendCoordinate; MainMap.ZoomLevel = GeoConverter.GetZoomLevelFromMeters(distanceToFriend); _resetZoom = false; } } else if (_resetZoom) { MainMap.ZoomLevel = GeoConverter.GetZoomLevelFromMeters(geoposition.Coordinate.Accuracy); } AppSettings.LastKnownLatitude = geoposition.Coordinate.Latitude; AppSettings.LastKnownLongitude = geoposition.Coordinate.Longitude; LoadingBar.Opacity = 0; _currentlySearching = false; } catch (Exception ex) { if ((uint)ex.HResult == 0x80004004) { // the application does not have the right capability or the location master switch is off MessageBox.Show("Location is disabled on this device. Please enable Location in your phone settings so we can find where you are.", "Location Disabled", MessageBoxButton.OKCancel); } LoadingBar.Opacity = 0; _currentlySearching = false; } }
public static void Main(string[] args) { Console.WriteLine($"XRIT Version: {LibInfo.Version}"); AppDomain.CurrentDomain.UnhandledException += CrashReport.DefaultExceptionHandler; //* //Organizer org = new Organizer("./himawari"); //org.Update(); //var gd = org.GroupData[1490489400]; //var od = gd.Infrared; /* * Console.WriteLine("Initializing organizer"); * Organizer org = new Organizer("/home/lucas/Works/OpenSatelliteProject/split/goesdump/XRITLibraryTest/bin/Debug/channels/Images/Full Disk/"); * org.Update(); * int k = 0; * int c = 0; * foreach (var z in org.GroupData.Keys) { * k = z; * c++; * if (c == 2) { // 20 For US * break; * } * } * var gd = org.GroupData[k]; * var od = gd.Visible; * * Console.WriteLine("Initializing GeoConverter"); * var gc = new GeoConverter(gd.SatelliteLongitude, gd.ColumnOffset, gd.LineOffset, gd.ColumnScalingFactor, gd.LineScalingFactor, true, od.Columns); * * Console.WriteLine("Generating BMP"); * //var bmp = ImageTools.GenerateFullImage(od); * var bmp = ImageTools.GenerateFalseColor(gd); * var mapDrawer = new MapDrawer("/home/lucas/Works/OpenSatelliteProject/split/borders/ne_10m_admin_1_states_provinces.shp"); * //var mapDrawer = new MapDrawer("/home/lucas/Works/OpenSatelliteProject/split/borders/ne_50m_admin_0_countries.shp"); * Console.WriteLine("Drawing Map"); * mapDrawer.DrawMap(ref bmp, gc, Color.Aqua, 2, true); * * Console.WriteLine("Drawing LatLon Lines"); * ImageTools.DrawLatLonLines(ref bmp, gc, Color.Brown, 1, true); * * bmp.Save("unitedstates.jpg", ImageFormat.Jpeg); * bmp.Dispose(); * // */ ///* string filename = "./OR_ABI-L2-CMIPF-M3C13_G16_s20170861545382_e20170861556160_c20170861556231.lrit"; string visFilename = "./OR_ABI-L2-CMIPF-M3C02_G16_s20170861545382_e20170861556149_c20170861556217.lrit"; XRITHeader header = FileParser.GetHeaderFromFile(filename); Console.WriteLine($"Parsing file {header.Filename}"); Regex x = new Regex(@".*\((.*)\)", RegexOptions.IgnoreCase); var regMatch = x.Match(header.ImageNavigationHeader.ProjectionName); float satelliteLongitude = float.Parse(regMatch.Groups[1].Captures[0].Value, CultureInfo.InvariantCulture); var inh = header.ImageNavigationHeader; var gc = new GeoConverter(satelliteLongitude, inh.ColumnOffset, inh.LineOffset, inh.ColumnScalingFactor, inh.LineScalingFactor); var od = new OrganizerData(); od.Segments.Add(0, filename); od.FirstSegment = 0; od.Columns = header.ImageStructureHeader.Columns; od.Lines = header.ImageStructureHeader.Lines; od.ColumnOffset = inh.ColumnOffset; od.PixelAspect = 1; var bmp = ImageTools.GenerateFullImage(od); od = new OrganizerData(); od.Segments.Add(0, visFilename); od.FirstSegment = 0; od.Columns = header.ImageStructureHeader.Columns; od.Lines = header.ImageStructureHeader.Lines; od.ColumnOffset = inh.ColumnOffset; od.PixelAspect = 1; var vbmp = ImageTools.GenerateFullImage(od); UIConsole.GlobalEnableDebug = true; var shapeFile = ShapeFiles.InitShapeFiles(); //bmp.Save(filename + "-orig.png", ImageFormat.Png); //vbmp.Save(visFilename + "-orig.png", ImageFormat.Png); var mapDrawer = new MapDrawer(shapeFile); //ImageTools.DrawLatLonLines(ref bmp, gc, Color.Brown); ImageTools.ApplyCurve(OpenSatelliteProject.Presets.NEW_VIS_FALSE_CURVE, ref vbmp); vbmp = ImageTools.ToFormat(vbmp, PixelFormat.Format32bppArgb, true); bmp = ImageTools.ToFormat(bmp, PixelFormat.Format32bppArgb, true); ImageTools.Apply2DLut(OpenSatelliteProject.Presets.FalseColorLUTVal, ref vbmp, bmp); var startTime = LLTools.TimestampMS(); mapDrawer.DrawMap(ref vbmp, gc, Color.Yellow, 2, false, true); var delta = LLTools.TimestampMS() - startTime; Console.WriteLine($"Took {delta} ms to generate map."); vbmp.Save(visFilename + ".jpg", ImageFormat.Jpeg); Bitmap landMap = mapDrawer.GenerateLandMap(gc, bmp.Width, bmp.Height); landMap.Save(filename + "-landmap.jpg", ImageFormat.Jpeg); landMap.Dispose(); bmp.Dispose(); return; // */ /* * Bitmap test0 = (Bitmap) Bitmap.FromFile("test0.jpg"); * Bitmap test1 = (Bitmap) Bitmap.FromFile("test1.jpg"); * Bitmap overlay = (Bitmap) Bitmap.FromFile("goes13-fulldisk.jpg"); * * test0 = test0.ToFormat(PixelFormat.Format24bppRgb, true); * * overlay.Save("hue.jpg", ImageFormat.Jpeg); * * ImageTools.ApplyOverlay(ref test0, overlay); * test0.Save("test0-ovl.jpg", ImageFormat.Jpeg); * * ImageTools.ApplyOverlay(ref test1, overlay); * test1.Save("test1-ovl.jpg", ImageFormat.Jpeg); * * test0.Dispose(); * test1.Dispose(); * overlay.Dispose(); */ //* //string dcsFile = "/home/lucas/Works/OpenSatelliteProject/split/goesdump/XRITLibraryTest/bin/Debug/channels/DCS/pM-17085003239-A.dcs"; //List<DCSHeader> d = DCSParser.parseDCS(dcsFile); //* //string debugFrames = "/media/ELTN/tmp/demuxdump-1490627438.bin"; //string debugFrames = "/media/ELTN/tmp/debug5/demuxdump-1492732814.bin"; //string debugFrames = "/home/lucas/Works/OpenSatelliteProject/split/issues/trango/3/debug_frames.bin"; //string debugFrames = "/media/ELTN/tmp/debug3/raw_data.bin"; /* * var mapDrawer = new MapDrawer("/home/lucas/Works/OpenSatelliteProject/split/borders/ne_50m_admin_0_countries.shp"); * var fList = mapDrawer.ShapeFile.Features.ToList (); * var bmp = new Bitmap (1280, 720, PixelFormat.Format24bppRgb); * using (var graphics = Graphics.FromImage (bmp)) { * Brush bgBrush = new SolidBrush (Color.Black); * Brush polyBrush = new SolidBrush (Color.White); * graphics.FillRectangle (bgBrush, 0, 0, 1280, 720); * int o = 0; * foreach (var fo in fList) { * Console.WriteLine ($"Writting Geometry {o}"); * Pen pen = new Pen(Color.FromArgb((int)((255.0 * o) / fList.Count), 127, 127), 3); * o++; * for (var n = 0; n < fo.NumGeometries; n++) { * //Console.WriteLine ($"Writting Geometry {n}"); * var fg = fo.GetBasicGeometryN (n); * var k = fg.Coordinates; * * float lastX = float.NaN; * float lastY = float.NaN; * * List<PointF> points = new List<PointF> (); * foreach (var z in k) { * float lon = (float)z.X; * float lat = (float)z.Y; * * float X = bmp.Width / 2 + bmp.Width * (lon / 360); * float Y = bmp.Height / 2 - bmp.Height * (lat / 180); * * if (!float.IsNaN (lastX) && !float.IsNaN (lastY)) { * //graphics.DrawLine (pen, lastX, lastY, X, Y); * } * lastX = X; * lastY = Y; * * points.Add (new PointF (X, Y)); * } * graphics.FillPolygon(polyBrush, points.ToArray()); * } * } * } * Console.WriteLine ("Saving"); * bmp.Save ("/home/lucas/test.png", ImageFormat.Png); * bmp.Dispose (); * Console.WriteLine ("Done"); * return; */ EventMaster.On("newFile", d => { var ed = (NewFileReceivedEventData)d.Data; //Console.WriteLine($"Received event for new file {ed.Name} at {ed.Path}"); //Console.WriteLine(ed.ToString()); }); Console.WriteLine("Hash: " + LibInfo.CommitID); Console.WriteLine("Log: " + LibInfo.LogLines); Console.WriteLine("Short Hash: " + LibInfo.ShortCommitID); Console.WriteLine("Version: " + LibInfo.Version); //string debugFrames = "/media/ELTN/tmp/demuxdump-1490627438.bin"; //string debugFrames = "/media/ELTN/tmp/G16JuneTest/demuxdump-1496790733.bin"; //string debugFrames = "/media/ELTN/tmp/G16JuneTest/demuxdump-1500179126.bin"; //string debugFrames = "/media/ELTN/tmp/debug14/demuxdump-1495166529.bin"; string debugFrames = "/media/ELTN/tmp/trango/demuxdump-1500736657.bin"; //var mapDrawer = new MapDrawer("/home/lucas/Works/OpenSatelliteProject/split/borders/ne_10m_admin_1_states_provinces.shp"); var im0 = new ImageManager("output/Images/Full Disk/"); var im1 = new ImageManager("output/Images/Northern Hemisphere/"); var im2 = new ImageManager("output/Images/Southern Hemisphere/"); var im3 = new ImageManager("output/Images/Area of Interest/"); var im4 = new ImageManager("output/Images/United States/"); var im5 = new ImageManager("output/Images/FM1/"); var im6 = new ImageManager("output/Images/Unknown/"); im0.InitMapDrawer(); im1.InitMapDrawer(); im2.InitMapDrawer(); im3.InitMapDrawer(); im4.InitMapDrawer(); im5.InitMapDrawer(); im6.InitMapDrawer(); ImageManager.GenerateVisible = true; ImageManager.GenerateInfrared = true; ImageManager.GenerateFalseColor = true; ImageManager.GenerateWaterVapour = true; ImageManager.GenerateOtherImages = true; ImageManager.EraseFiles = false; ImageManager.UseNOAAFileFormat = true; ImageManager.GenerateLatLonOverlays = true; ImageManager.GenerateMapOverlays = true; ImageManager.GenerateLabels = true; ImageManager.GenerateLatLonLabel = true; ImageManager.SaveNonOverlay = false; //im0.Start (); //im1.Start (); //im2.Start (); //im3.Start (); //im4.Start (); im5.Start(); //im6.Start (); // */ //*/ // /* /* * DemuxManager dm = new DemuxManager (); * FileHandler.SkipDCS = true; * FileHandler.SkipEMWIN = true; * //const int startFrame = 956000; * const int startFrame = 0; * FileStream file = File.OpenRead (debugFrames); * byte[] data = new byte[892]; * long bytesRead = startFrame * 892; * long bytesToRead = file.Length; * int frameN = startFrame; * file.Position = bytesRead; * while (bytesRead < bytesToRead) { * if (frameN % 1000 == 0) { * //Console.WriteLine("Injecting Frame {0}", frameN); * } * bytesRead += file.Read (data, 0, 892); * dm.parseBytes (data); * frameN++; * } * * Console.WriteLine ("CRC Fails: {0}", dm.CRCFails); * Console.WriteLine ("Bugs: {0}", dm.Bugs); * Console.WriteLine ("Frame Loss: {0}", dm.FrameLoss); * Console.WriteLine ("Length Fails: {0}", dm.LengthFails); * Console.WriteLine ("Packets: {0}", dm.Packets); * * Console.WriteLine ("Received Products: "); * foreach (int pID in dm.ProductsReceived.Keys) { * Console.WriteLine ("\t{0}: {1}", ((NOAAProductID)pID).ToString (), dm.ProductsReceived [pID]); * } * //*/ //im.Stop(); //*/ //ProcessFile("/home/lucas/Works/OpenSatelliteProject/split/goesdump/goesdump/bin/Debug/channels/Text/NWSTEXTdat043204159214.lrit"); /* * Organizer organizer = new Organizer("/home/lucas/Works/OpenSatelliteProject/split/goesdump/goesdump/bin/Debug/channels/Images/Full Disk"); * organizer.Update(); * * var data = organizer.GroupData; * * foreach (var z in data) { * var mData = z.Value; * var bmp = ImageTools.GenerateFalseColor(mData); * * if (bmp != null) { * bmp.Save(string.Format("{0}-{1}-{2}-{3}.jpg", mData.SatelliteName, mData.RegionName, "FLSCLR", z.Key), ImageFormat.Jpeg); * bmp.Dispose(); * mData.IsProcessed = true; * } else { * if (mData.Visible.IsComplete && mData.Visible.MaxSegments != 0) { * bmp = ImageTools.GenerateFullImage(mData.Visible); * bmp.Save(string.Format("{0}-{1}-{2}-{3}.jpg", mData.SatelliteName, mData.RegionName, "VIS", z.Key), ImageFormat.Jpeg); * bmp.Dispose(); * } * if (mData.Infrared.IsComplete && mData.Infrared.MaxSegments != 0) { * bmp = ImageTools.GenerateFullImage(mData.Infrared); * bmp.Save(string.Format("{0}-{1}-{2}-{3}.jpg", mData.SatelliteName, mData.RegionName, "IR", z.Key), ImageFormat.Jpeg); * bmp.Dispose(); * } * if (mData.WaterVapour.IsComplete && mData.WaterVapour.MaxSegments != 0) { * bmp = ImageTools.GenerateFullImage(mData.WaterVapour); * bmp.Save(string.Format("{0}-{1}-{2}-{3}.jpg", mData.SatelliteName, mData.RegionName, "WV", z.Key), ImageFormat.Jpeg); * bmp.Dispose(); * } * Console.WriteLine("Not all segments available!"); * } * } * * * //*/ /* * string visFile = "/home/lucas/Works/OpenSatelliteProject/split/samples/FD 26-02-17 2106 G13VI.jpg"; * string irFile = "/home/lucas/Works/OpenSatelliteProject/split/samples/FD 26-02-17 2106 G13IR.jpg"; * * Bitmap vis = new Bitmap(visFile); * ImageTools.ApplyCurve(Presets.VIS_FALSE_CURVE, ref vis); * vis.Save("test.jpg", ImageFormat.Jpeg); * //vis = vis.ToFormat(PixelFormat.Format32bppArgb, true); * * Bitmap ir = new Bitmap(irFile); * ir = ir.ToFormat(PixelFormat.Format32bppArgb, true); * ImageTools.ApplyLUT(Presets.THERMAL_FALSE_LUT, ref ir, 3); * ir.Save("test2.jpg", ImageFormat.Jpeg); * * ir = ir.ToFormat(PixelFormat.Format32bppArgb); * ImageTools.CombineHStoV(ref ir, vis); * * ir.Save("final.jpg", ImageFormat.Jpeg); * //*/ do { while (!Console.KeyAvailable) { Thread.Sleep(1000); } } while (Console.ReadKey(true).Key != ConsoleKey.Escape); }