Beispiel #1
0
        public MapStationDlg(LocationDesignator ld)
        {
            StationLocation = ld;
            InitializeComponent();

            // set initial settings for user details
            GMap.NET.MapProviders.GMapProvider.UserAgent = "AirScout";
            gm_Callsign.MapProvider = GMap.NET.MapProviders.GMapProviders.Find(Properties.Settings.Default.Map_Provider);
            gm_Callsign.IgnoreMarkerOnMouseWheel = true;
            gm_Callsign.MinZoom             = 0;
            gm_Callsign.MaxZoom             = 20;
            gm_Callsign.Zoom                = 1;
            gm_Callsign.DragButton          = System.Windows.Forms.MouseButtons.Left;
            gm_Callsign.CanDragMap          = true;
            gm_Callsign.ScalePen            = new Pen(Color.Black, 3);
            gm_Callsign.HelperLinePen       = null;
            gm_Callsign.SelectionPen        = null;
            gm_Callsign.MapScaleInfoEnabled = true;
            gm_Callsign.Overlays.Add(Callsignpolygons);
            gm_Callsign.Overlays.Add(Callsignspositions);
            Callsignspositions.Markers.Add(UserPos);
            // initially set textboxes
            tb_Callsign.SilentText   = StationLocation.Call;
            tb_Latitude.SilentValue  = StationLocation.Lat;
            tb_Longitude.SilentValue = StationLocation.Lon;
            tb_Locator.SilentText    = MaidenheadLocator.LocFromLatLon(StationLocation.Lat, StationLocation.Lon, Properties.Settings.Default.Locator_SmallLettersForSubsquares, (int)Properties.Settings.Default.Locator_MaxLength / 2, Properties.Settings.Default.Locator_AutoLength);
            tb_Elevation.SilentValue = GetElevation(StationLocation.Lat, StationLocation.Lon);
            ValidateDetails();
            // show initial zoom level in text box
            gm_Callsign_OnMapZoomChanged();
        }
Beispiel #2
0
        /// <summary>
        /// Get the heading from one grid to another.
        /// </summary>
        /// <param name="destination"></param>
        /// <returns></returns>
        private string GetHeading(string destination)
        {
            string homeLocation = settings.Grid;
            double azimuth      = MaidenheadLocator.Azimuth(homeLocation.ToUpper(), destination.ToUpper());

            return(string.Format("{0:0.##}", azimuth));
        }
Beispiel #3
0
        /// <summary>
        /// Get the maidenhead grid form the latitude and longitude.
        /// </summary>
        /// <param name="latitude"></param>
        /// <param name="longitude"></param>
        /// <returns></returns>
        private string GetGridFromLatLong(string latitude, string longitude)
        {
            double lat = Convert.ToDouble(latitude);
            double lon = Convert.ToDouble(longitude);

            string grid = MaidenheadLocator.LatLngToLocator(lat, lon);

            return(grid);
        }
Beispiel #4
0
        /// <summary>
        /// Get the distance from one grid to another.
        /// </summary>
        /// <param name="destination"></param>
        /// <returns></returns>
        private string GetDistance(string destination)
        {
            string homeLocation = settings.Grid;
            double distance     = MaidenheadLocator.Distance(homeLocation.ToUpper(), destination.ToUpper());

            if (settings.Unit == Units.Miles)
            {
                distance /= 1.6;
            }

            return(string.Format("{0:0.##}", distance));
        }
Beispiel #5
0
 public ElevationTileDesignator(string index, int minelv, double minlat, double minlon, int maxelv, double maxlat, double maxlon, int rows, int columns, short[,] elv, DateTime lastupdated) : this()
 {
     TileIndex   = index;
     MinElv      = minelv;
     MinLat      = minlat;
     MinLon      = minlon;
     MaxElv      = maxelv;
     MaxLat      = maxlat;
     MaxLon      = maxlon;
     Rows        = rows;
     Columns     = columns;
     Elv         = elv;
     LastUpdated = lastupdated;
     Bounds      = MaidenheadLocator.BoundsFromLoc(index);
 }
Beispiel #6
0
        private void tb_Locator_TextChanged(object sender, EventArgs e)
        {
            // update lat/lon
            double mlat, mlon;

            if (tb_Locator.Focused)
            {
                // locator box is focused --> update lat/lon
                if (MaidenheadLocator.Check(tb_Locator.Text) && tb_Locator.Text.Length >= 6)
                {
                    MaidenheadLocator.LatLonFromLoc(tb_Locator.Text, PositionInRectangle.MiddleMiddle, out mlat, out mlon);
                    tb_Latitude.SilentValue  = mlat;
                    tb_Longitude.SilentValue = mlon;
                }
                else
                {
                    tb_Latitude.SilentValue  = double.NaN;
                    tb_Longitude.SilentValue = double.NaN;
                }
            }
            ValidateDetails();
        }
Beispiel #7
0
        public LocationDesignator LocationFind(string call, string loc = "")
        {
            // check all parameters
            if (!Callsign.Check(call))
            {
                return(null);
            }
            if (!String.IsNullOrEmpty(loc) && !MaidenheadLocator.Check(loc))
            {
                return(null);
            }
            // get location info
            LocationDesignator ld = (String.IsNullOrEmpty(loc)) ? StationData.Database.LocationFind(call) : StationData.Database.LocationFind(call, loc);

            // return null if not found
            if (ld == null)
            {
                return(null);
            }
            // get elevation
            ld.Elevation         = GetElevation(ld.Lat, ld.Lon);
            ld.BestCaseElevation = false;
            // modify location in case of best case elevation is selected --> but do not store in database or settings!
            if (Properties.Settings.Default.Path_BestCaseElevation)
            {
                if (!MaidenheadLocator.IsPrecise(ld.Lat, ld.Lon, 3))
                {
                    ElvMinMaxInfo maxinfo = GetMinMaxElevationLoc(ld.Loc);
                    if (maxinfo != null)
                    {
                        ld.Lat               = maxinfo.MaxLat;
                        ld.Lon               = maxinfo.MaxLon;
                        ld.Elevation         = maxinfo.MaxElv;
                        ld.BestCaseElevation = true;
                    }
                }
            }
            return(ld);
        }
Beispiel #8
0
        public List <LocationDesignator> LocationFindAll(string call)
        {
            // check all parameters
            if (!Callsign.Check(call))
            {
                return(null);
            }
            // get location info
            List <LocationDesignator> l = StationData.Database.LocationFindAll(call);

            // return null if not found
            if (l == null)
            {
                return(null);
            }
            foreach (LocationDesignator ld in l)
            {
                // get elevation
                ld.Elevation         = GetElevation(ld.Lat, ld.Lon);
                ld.BestCaseElevation = false;
                // modify location in case of best case elevation is selected --> but do not store in database or settings!
                if (Properties.Settings.Default.Path_BestCaseElevation)
                {
                    if (!MaidenheadLocator.IsPrecise(ld.Lat, ld.Lon, 3))
                    {
                        ElvMinMaxInfo maxinfo = GetMinMaxElevationLoc(ld.Loc);
                        if (maxinfo != null)
                        {
                            ld.Lat               = maxinfo.MaxLat;
                            ld.Lon               = maxinfo.MaxLon;
                            ld.Elevation         = maxinfo.MaxElv;
                            ld.BestCaseElevation = true;
                        }
                    }
                }
            }
            return(l);
        }
        static void DisplayScreenThree()
        {
            string mode = _thunderbolt.TimingMode == TimingModes.UTC ? "U" : "G";

            _lcdshield.WriteLine(0, DateTime.UtcNow.ToString(@"dd-MMM-yy \" + mode + " HH:mm:ss"));

            _lcdshield.SetCursorPosition(0, 1);
            var s = "Lat:  " + _thunderbolt.CurrentPosition.Latitude.ToString("N4");

            _lcdshield.Write(s);
            _lcdshield.WriteByte(7);
            _lcdshield.Write(StringExtension.PadLeft("", 16 - (s.Length + 1)));
            _lcdshield.Write("Alt:");

            _lcdshield.SetCursorPosition(0, 2);
            s = "Lon:  " + _thunderbolt.CurrentPosition.Longitude.ToString("N4");
            _lcdshield.Write(s);
            _lcdshield.WriteByte(7);
            _lcdshield.Write(StringExtension.PadLeft("", 14 - (s.Length + 1)));
            _lcdshield.Write(StringExtension.PadLeft(_thunderbolt.CurrentPosition.Altitude.ToString("N0") + "m", 6));

            _lcdshield.WriteLine(3, "Grid: " + StringExtension.PadRight(MaidenheadLocator.LatLongToLocator(_thunderbolt.CurrentPosition.Latitude, _thunderbolt.CurrentPosition.Longitude), 11) + GetAlarmIndicatorString());
        }
Beispiel #10
0
 public void LatLngToLocator_0() => MaidenheadLocator.LatLngToLocator(51.4375, -1.0417).Should().Be("IO91lk");
Beispiel #11
0
 public LocationDesignator(string call) : this(call, MaidenheadLocator.LocFromLatLon(0, 0, false, 3), 0, 0, ScoutBase.Core.GEOSOURCE.UNKONWN, 0, DateTime.UtcNow)
 {
 }
Beispiel #12
0
 public LocationDesignator(string call, string loc, GEOSOURCE source) : this(call, loc, MaidenheadLocator.LatFromLoc(loc), MaidenheadLocator.LonFromLoc(loc), source, 0, DateTime.UtcNow)
 {
 }
Beispiel #13
0
            protected override void OnDoWork(DoWorkEventArgs e)
            {
                // get all parameters
                BACKGROUNDUPDATERSTARTOPTIONS Options = (BACKGROUNDUPDATERSTARTOPTIONS)e.Argument;
                // get update interval
                int interval = (int)Properties.Settings.Default.Background_Update_Period * 60;

                do
                {
                    if (Properties.Settings.Default.Background_Calculations_Enable)
                    {
                        // get all parameters
                        // set name and stepwidth according to model
                        switch (Model)
                        {
                        case ELEVATIONMODEL.GLOBE:
                            Name      = "GLOBE";
                            StepWidth = ElevationData.Database.GetDefaultStepWidth(ELEVATIONMODEL.GLOBE);
                            break;

                        case ELEVATIONMODEL.SRTM3:
                            Name      = "SRTM3";
                            StepWidth = ElevationData.Database.GetDefaultStepWidth(ELEVATIONMODEL.SRTM3);
                            break;

                        case ELEVATIONMODEL.SRTM1:
                            Name      = "SRTM1";
                            StepWidth = ElevationData.Database.GetDefaultStepWidth(ELEVATIONMODEL.SRTM1);
                            break;
                        }
                        // name the thread for debugging
                        if (String.IsNullOrEmpty(Thread.CurrentThread.Name))
                        {
                            Thread.CurrentThread.Name = Name + "_" + this.GetType().Name;
                        }
                        this.ReportProgress(0, Name + " started.");
                        try
                        {
                            // iterate through all locations in the database and calculate the propagation path
                            // chek if databases are ready and changes reported first
                            while (!ElevationData.Database.GetDBStatusBit(Model, DATABASESTATUS.UPTODATE) || !StationData.Database.GetDBStatusBit(DATABASESTATUS.UPTODATE) || !HasDatabaseChanged())
                            {
                                // sleep 10 sec
                                int i = 0;
                                while (!this.CancellationPending && (i < 10))
                                {
                                    Thread.Sleep(1000);
                                    i++;
                                    if (this.CancellationPending)
                                    {
                                        break;
                                    }
                                }
                                if (this.CancellationPending)
                                {
                                    break;
                                }
                            }
                            if (this.CancellationPending)
                            {
                                break;
                            }
                            this.ReportProgress(0, Name + " getting locations...");
                            // get all locations in covered area but don't report progress
                            this.WorkerReportsProgress = false;
                            List <LocationDesignator> lds = StationData.Database.LocationGetAll(this, Properties.Settings.Default.MinLat, Properties.Settings.Default.MinLon, Properties.Settings.Default.MaxLat, Properties.Settings.Default.MaxLon);
                            this.WorkerReportsProgress = true;
                            // start over again with main loog when lds = null for some reason
                            if (lds == null)
                            {
                                continue;
                            }
                            // iterate through locations
                            QRVDesignator myqrv = null;
                            QRVDesignator dxqrv = null;
                            this.ReportProgress(0, Name + " checking locations...");
                            foreach (LocationDesignator ld in lds)
                            {
                                Stopwatch st = new Stopwatch();
                                st.Start();
                                try
                                {
                                    // leave the iteration when something went wrong --> start new
                                    if (ld == null)
                                    {
                                        break;
                                    }
                                    // check lat/lon if valid
                                    if (!GeographicalPoint.Check(Properties.Settings.Default.MyLat, Properties.Settings.Default.MyLon))
                                    {
                                        continue;
                                    }
                                    // check lat/lon if valid
                                    if (!GeographicalPoint.Check(ld.Lat, ld.Lon))
                                    {
                                        continue;
                                    }
                                    // chek for path < MaxDistance
                                    double dist = LatLon.Distance(Properties.Settings.Default.MyLat, Properties.Settings.Default.MyLon, ld.Lat, ld.Lon);
                                    if (dist <= Properties.Settings.Default.Path_MaxLength)
                                    {
                                        // start calculation for each band
                                        foreach (BAND band in Bands.GetValuesExceptNoneAndAll())
                                        {
                                            PropagationPathDesignator pp;
                                            // get my lat/lon from settings
                                            string mycall = Properties.Settings.Default.MyCall;
                                            double mylat  = Properties.Settings.Default.MyLat;
                                            double mylon  = Properties.Settings.Default.MyLon;
                                            string myloc  = MaidenheadLocator.LocFromLatLon(mylat, mylon, false, 3);
                                            double myelv  = ElevationData.Database[mylat, mylon, Model];
                                            // modify location in case of best case elevation is selected --> but do not store in database or settings!
                                            if (Properties.Settings.Default.Path_BestCaseElevation)
                                            {
                                                if (!MaidenheadLocator.IsPrecise(mylat, mylon, 3))
                                                {
                                                    ElvMinMaxInfo maxinfo = ElevationData.Database.ElevationTileFindMinMaxInfo(myloc, Model);
                                                    if (maxinfo != null)
                                                    {
                                                        mylat = maxinfo.MaxLat;
                                                        mylon = maxinfo.MaxLon;
                                                        myelv = maxinfo.MaxElv;
                                                    }
                                                }
                                            }
                                            myqrv = StationData.Database.QRVFind(mycall, myloc, band);
                                            double myheight = ((myqrv != null) && (myqrv.AntennaHeight != 0)) ? myqrv.AntennaHeight : StationData.Database.QRVGetDefaultAntennaHeight(band);
                                            string dxcall   = ld.Call;
                                            // get my lat/lon from settings
                                            double dxlat = ld.Lat;
                                            double dxlon = ld.Lon;
                                            string dxloc = MaidenheadLocator.LocFromLatLon(dxlat, dxlon, false, 3);
                                            double dxelv = ElevationData.Database[dxlat, dxlon, Model];
                                            // modify location in case of best case elevation is selected --> but do not store in database or settings!
                                            if (Properties.Settings.Default.Path_BestCaseElevation)
                                            {
                                                if (!MaidenheadLocator.IsPrecise(dxlat, dxlon, 3))
                                                {
                                                    ElvMinMaxInfo maxinfo = ElevationData.Database.ElevationTileFindMinMaxInfo(dxloc, Model);
                                                    if (maxinfo != null)
                                                    {
                                                        dxlat = maxinfo.MaxLat;
                                                        dxlon = maxinfo.MaxLon;
                                                        dxelv = maxinfo.MaxElv;
                                                    }
                                                }
                                            }
                                            dxqrv = StationData.Database.QRVFind(dxcall, dxloc, band);
                                            double dxheight = ((dxqrv != null) && (dxqrv.AntennaHeight != 0)) ? dxqrv.AntennaHeight : StationData.Database.QRVGetDefaultAntennaHeight(band);
                                            LocalObstructionDesignator o = ElevationData.Database.LocalObstructionFind(mylat, mylon, Model);
                                            double myobstr = (o != null) ? o.GetObstruction(myheight, LatLon.Bearing(mylat, mylon, dxlat, dxlon)) : double.MinValue;
                                            pp = PropagationData.Database.PropagationPathFind(
                                                mylat,
                                                mylon,
                                                myelv + myheight,
                                                dxlat,
                                                dxlon,
                                                dxelv + dxheight,
                                                Bands.ToGHz(band),
                                                LatLon.Earth.Radius * Properties.Settings.Default.Path_Band_Settings[band].K_Factor,
                                                Properties.Settings.Default.Path_Band_Settings[band].F1_Clearance,
                                                ElevationData.Database.GetDefaultStepWidth(Model),
                                                Model,
                                                myobstr);
                                            // skip if path already in database
                                            if (pp != null)
                                            {
                                                Thread.Sleep(Properties.Settings.Default.Background_Calculations_ThreadWait);
                                                continue;
                                            }
                                            // create new propagation path
                                            pp = PropagationData.Database.PropagationPathCreateFromLatLon(
                                                this,
                                                mylat,
                                                mylon,
                                                myelv + myheight,
                                                dxlat,
                                                dxlon,
                                                dxelv + dxheight,
                                                Bands.ToGHz(band),
                                                LatLon.Earth.Radius * Properties.Settings.Default.Path_Band_Settings[band].K_Factor,
                                                Properties.Settings.Default.Path_Band_Settings[band].F1_Clearance,
                                                ElevationData.Database.GetDefaultStepWidth(Model),
                                                Model,
                                                myobstr);
                                            st.Stop();
                                            this.ReportProgress(0, Name + " calculating path[ " + Bands.GetStringValue(band) + "]: " + Properties.Settings.Default.MyCall + "<>" + ld.Call + ", " + st.ElapsedMilliseconds.ToString() + " ms.");
                                        }
                                        if (this.CancellationPending)
                                        {
                                            break;
                                        }
                                    }
                                    if (this.CancellationPending)
                                    {
                                        break;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Log.WriteMessage(Name + " error processing call [" + ld.Call + "]: " + ex.ToString());
                                }
                                // keep cpu load low --> TODO: find better solution here
                                Thread.Sleep(10);
                            }
                            // save station database timestamp
                            SaveDatabaseTimeStamp();
                            // wait to keep cpu load low
                            Thread.Sleep(Properties.Settings.Default.Background_Calculations_ThreadWait);
                            this.ReportProgress(0, Name + " finished.");
                        }
                        catch (Exception ex)
                        {
                            Log.WriteMessage(ex.ToString(), LogLevel.Error);
                        }
                    }
                    // sleep when running periodically
                    if (Options == BACKGROUNDUPDATERSTARTOPTIONS.RUNPERIODICALLY)
                    {
                        int i = 0;
                        while (!this.CancellationPending && (i < interval))
                        {
                            Thread.Sleep(1000);
                            i++;
                        }
                    }
                }while (Options == BACKGROUNDUPDATERSTARTOPTIONS.RUNPERIODICALLY);
                if (this.CancellationPending)
                {
                    this.ReportProgress(0, Name + " cancelled.");
                    Log.WriteMessage(Name + " cancelled.");
                }
                else
                {
                    this.ReportProgress(0, Name + " finished.");
                    Log.WriteMessage(Name + " finished.");
                }
            }
Beispiel #14
0
 public void LocatorToLatLng_2()
 {
     var(lat, lon) = MaidenheadLocator.LocatorToLatLng("IO91lk45xa");
     lat.Should().Be(51.437586805555554);
     lon.Should().Be(-1.0418402777777942);
 }
Beispiel #15
0
 public ElevationTileDesignator(DataRow row) : this()
 {
     FillFromDataRow(row);
     Bounds = MaidenheadLocator.BoundsFromLoc(TileIndex);
 }
Beispiel #16
0
        private string DeliverElevationPath(string paramstr)
        {
            string json = "";
            // set default values
            string mycallstr = "";
            string mylocstr  = "";
            string dxcallstr = "";
            string dxlocstr  = "";
            BAND   band      = Properties.Settings.Default.Band;

            // get parameters
            try
            {
                if (paramstr.Contains("?"))
                {
                    // OK, we have parameters --> cut them out and make all uppercase
                    paramstr = paramstr.Substring(paramstr.IndexOf("?") + 1).ToUpper();
                    var pars = System.Web.HttpUtility.ParseQueryString(paramstr);
                    mycallstr = pars.Get("MYCALL");
                    mylocstr  = pars.Get("MYLOC");
                    dxcallstr = pars.Get("DXCALL");
                    dxlocstr  = pars.Get("DXLOC");
                }
            }
            catch (Exception ex)
            {
                // return error
                return("Error while parsing parameters!");
            }
            // check parameters
            if (!Callsign.Check(mycallstr))
            {
                return("Error: " + mycallstr + " is not a valid callsign!");
            }
            if (!Callsign.Check(dxcallstr))
            {
                return("Error: " + dxcallstr + " is not a valid callsign!");
            }
            if (!String.IsNullOrEmpty(mylocstr) && !MaidenheadLocator.Check(mylocstr))
            {
                return("Error: " + mylocstr + " is not a valid Maidenhead locator!");
            }
            if (!String.IsNullOrEmpty(dxlocstr) && !MaidenheadLocator.Check(dxlocstr))
            {
                return("Error: " + dxlocstr + " is not a valid Maidenhead locator!");
            }
            // search call in station database, return empty string if not found
            LocationDesignator myloc = LocationFind(mycallstr, mylocstr);

            if (myloc == null)
            {
                return("Error: MyLocation not found in database!");
            }
            LocationDesignator dxloc = LocationFind(dxcallstr, dxlocstr);

            if (dxloc == null)
            {
                return("Error: DXLocation not found in database!");
            }

            // get qrv info or create default
            QRVDesignator myqrv = StationData.Database.QRVFindOrCreateDefault(myloc.Call, myloc.Loc, band);

            // set qrv defaults if zero
            if (myqrv.AntennaHeight == 0)
            {
                myqrv.AntennaHeight = StationData.Database.QRVGetDefaultAntennaHeight(band);
            }
            if (myqrv.AntennaGain == 0)
            {
                myqrv.AntennaGain = StationData.Database.QRVGetDefaultAntennaGain(band);
            }
            if (myqrv.Power == 0)
            {
                myqrv.Power = StationData.Database.QRVGetDefaultPower(band);
            }

            // get qrv info or create default
            QRVDesignator dxqrv = StationData.Database.QRVFindOrCreateDefault(dxloc.Call, dxloc.Loc, band);

            // set qrv defaults if zero
            if (dxqrv.AntennaHeight == 0)
            {
                dxqrv.AntennaHeight = StationData.Database.QRVGetDefaultAntennaHeight(band);
            }
            if (dxqrv.AntennaGain == 0)
            {
                dxqrv.AntennaGain = StationData.Database.QRVGetDefaultAntennaGain(band);
            }
            if (dxqrv.Power == 0)
            {
                dxqrv.Power = StationData.Database.QRVGetDefaultPower(band);
            }

            // get or calculate elevation path
            ElevationPathDesignator epath = ElevationData.Database.ElevationPathFindOrCreateFromLatLon(
                this,
                myloc.Lat,
                myloc.Lon,
                dxloc.Lat,
                dxloc.Lon,
                ElevationData.Database.GetDefaultStepWidth(Properties.Settings.Default.ElevationModel),
                Properties.Settings.Default.ElevationModel);

            if (epath == null)
            {
                return(json);
            }
            // add additional info to ppath
            epath.Location1 = myloc;
            epath.Location2 = dxloc;
            epath.QRV1      = myqrv;
            epath.QRV2      = dxqrv;
            // convert path to json
            json = epath.ToJSON();
            return(json);
        }
Beispiel #17
0
        private string DeliverNearestPlanes(string paramstr, List <PlaneInfo> allplanes)
        {
            string json = "";
            // set default values
            string mycallstr = "";
            string mylocstr  = "";
            string dxcallstr = "";
            string dxlocstr  = "";
            string bandstr   = "";
            BAND   band      = Properties.Settings.Default.Band;

            // get parameters
            try
            {
                if (paramstr.Contains("?"))
                {
                    // OK, we have parameters --> cut them out and make all uppercase
                    paramstr = paramstr.Substring(paramstr.IndexOf("?") + 1).ToUpper();
                    var pars = System.Web.HttpUtility.ParseQueryString(paramstr);
                    mycallstr = pars.Get("MYCALL");
                    mylocstr  = pars.Get("MYLOC");
                    dxcallstr = pars.Get("DXCALL");
                    dxlocstr  = pars.Get("DXLOC");
                    bandstr   = pars.Get("BAND");
                }
            }
            catch (Exception ex)
            {
                // return error
                return("Error while parsing parameters!");
            }
            // check parameters
            if (!Callsign.Check(mycallstr))
            {
                return("Error: " + mycallstr + " is not a valid callsign!");
            }
            if (!Callsign.Check(dxcallstr))
            {
                return("Error: " + dxcallstr + " is not a valid callsign!");
            }
            if (!String.IsNullOrEmpty(mylocstr) && !MaidenheadLocator.Check(mylocstr))
            {
                return("Error: " + mylocstr + " is not a valid Maidenhead locator!");
            }
            if (!String.IsNullOrEmpty(dxlocstr) && !MaidenheadLocator.Check(dxlocstr))
            {
                return("Error: " + dxlocstr + " is not a valid Maidenhead locator!");
            }
            // set band to currently selected if empty
            if (string.IsNullOrEmpty(bandstr))
            {
                band = Properties.Settings.Default.Band;
            }
            else
            {
                band = Bands.ParseStringValue(bandstr);
            }
            if (band == BAND.BNONE)
            {
                return("Error: " + bandstr + " is not a valid band value!");
            }
            // search call in station database, return empty string if not found
            LocationDesignator myloc = LocationFind(mycallstr, mylocstr);

            if (myloc == null)
            {
                return("Error: MyLocation not found in database!");
            }
            LocationDesignator dxloc = LocationFind(dxcallstr, dxlocstr);

            if (dxloc == null)
            {
                return("Error: DXLocation not found in database!");
            }

            // get qrv info or create default
            QRVDesignator myqrv = StationData.Database.QRVFindOrCreateDefault(myloc.Call, myloc.Loc, band);

            // set qrv defaults if zero
            if (myqrv.AntennaHeight == 0)
            {
                myqrv.AntennaHeight = StationData.Database.QRVGetDefaultAntennaHeight(band);
            }
            if (myqrv.AntennaGain == 0)
            {
                myqrv.AntennaGain = StationData.Database.QRVGetDefaultAntennaGain(band);
            }
            if (myqrv.Power == 0)
            {
                myqrv.Power = StationData.Database.QRVGetDefaultPower(band);
            }

            // get qrv info or create default
            QRVDesignator dxqrv = StationData.Database.QRVFindOrCreateDefault(dxloc.Call, dxloc.Loc, band);

            // set qrv defaults if zero
            if (dxqrv.AntennaHeight == 0)
            {
                dxqrv.AntennaHeight = StationData.Database.QRVGetDefaultAntennaHeight(band);
            }
            if (dxqrv.AntennaGain == 0)
            {
                dxqrv.AntennaGain = StationData.Database.QRVGetDefaultAntennaGain(band);
            }
            if (dxqrv.Power == 0)
            {
                dxqrv.Power = StationData.Database.QRVGetDefaultPower(band);
            }

            // find local obstruction, if any
            LocalObstructionDesignator o = ElevationData.Database.LocalObstructionFind(myloc.Lat, myloc.Lon, Properties.Settings.Default.ElevationModel);
            double mybearing             = LatLon.Bearing(myloc.Lat, myloc.Lon, dxloc.Lat, dxloc.Lon);
            double myobstr = (o != null) ? o.GetObstruction(myqrv.AntennaHeight, mybearing) : double.MinValue;

            // get or calculate propagation path
            PropagationPathDesignator ppath = PropagationData.Database.PropagationPathFindOrCreateFromLatLon(
                this,
                myloc.Lat,
                myloc.Lon,
                GetElevation(myloc.Lat, myloc.Lon) + myqrv.AntennaHeight,
                dxloc.Lat,
                dxloc.Lon,
                GetElevation(dxloc.Lat, dxloc.Lon) + dxqrv.AntennaHeight,
                Bands.ToGHz(band),
                LatLon.Earth.Radius * Properties.Settings.Default.Path_Band_Settings[band].K_Factor,
                Properties.Settings.Default.Path_Band_Settings[band].F1_Clearance,
                ElevationData.Database.GetDefaultStepWidth(Properties.Settings.Default.ElevationModel),
                Properties.Settings.Default.ElevationModel,
                myobstr);

            if (ppath == null)
            {
                return(json);
            }
            // add additional info to ppath
            ppath.Location1 = myloc;
            ppath.Location2 = dxloc;
            ppath.QRV1      = myqrv;
            ppath.QRV2      = dxqrv;

            /*
             * // estimate positions according to time
             * DateTime time = DateTime.UtcNow;
             * foreach(PlaneInfo plane in allplanes.Planes)
             * {
             *  // change speed to km/h
             *  double speed = plane.Speed_kmh;
             *  // calculate distance after timespan
             *  double dist = speed * (time - allplanes.At).TotalHours;
             *  LatLon.GPoint newpos = LatLon.DestinationPoint(plane.Lat, plane.Lon, plane.Track, dist);
             *  plane.Lat = newpos.Lat;
             *  plane.Lon = newpos.Lon;
             *  plane.Time = time;
             * }
             */
            // get nearest planes
            List <PlaneInfo> nearestplanes = AircraftData.Database.GetNearestPlanes(DateTime.UtcNow, ppath, allplanes, Properties.Settings.Default.Planes_Filter_Max_Circumcircle, Properties.Settings.Default.Path_Band_Settings[band].MaxDistance, Properties.Settings.Default.Planes_MaxAlt);
            // convert nearestplanes to json
            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
            settings.FloatFormatHandling  = FloatFormatHandling.String;
            settings.Formatting           = Newtonsoft.Json.Formatting.Indented;
            json = JsonConvert.SerializeObject(nearestplanes, settings);
            return(json);
        }
Beispiel #18
0
        public DataTableCallsigns FromUSR(string filename)
        {
            // imports a USR with AirScout user data format
            DataTableCallsigns dt = new DataTableCallsigns();

            if (!File.Exists(filename))
            {
                return(dt);
            }
            try
            {
                string s = "";
                using (StreamReader sr = new StreamReader(File.OpenRead(filename)))
                {
                    while (!sr.EndOfStream)
                    {
                        s = sr.ReadLine();
                        if (!String.IsNullOrEmpty(s) && !s.StartsWith("//"))
                        {
                            string[] a = s.Split(';');
                            // store array values in DataTable
                            DataRow   row         = dt.NewRow();
                            string    call        = a[0];
                            double    lat         = System.Convert.ToDouble(a[1], CultureInfo.InvariantCulture);
                            double    lon         = System.Convert.ToDouble(a[2], CultureInfo.InvariantCulture);
                            GEOSOURCE source      = (MaidenheadLocator.IsPrecise(lat, lon, 3) ? GEOSOURCE.FROMUSER : GEOSOURCE.FROMLOC);
                            string    lastupdated = a[6];
                            if (GeographicalPoint.Check(lat, lon))
                            {
                                row["Call"]        = call;
                                row["Lat"]         = lat;
                                row["Lon"]         = lon;
                                row["Source"]      = source.ToString();
                                row["LastUpdated"] = lastupdated;
                                DataRow oldrow = dt.Rows.Find(row["Call"].ToString());
                                if (oldrow != null)
                                {
                                    // call found --> check for update
                                    if (String.Compare(row["LastUpdated"].ToString(), oldrow["LastUpdated"].ToString()) > 0)
                                    {
                                        oldrow["Lat"]         = row["Lat"];
                                        oldrow["Lon"]         = row["Lon"];
                                        oldrow["Source"]      = row["Source"];
                                        oldrow["LastUpdated"] = row["LastUpdated"];
                                    }
                                }
                                else
                                {
                                    // add new row
                                    dt.Rows.Add(row);
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
            }
            return(dt);
        }
Beispiel #19
0
        private string DeliverLocation(string paramstr)
        {
            string json = "";
            // set default values
            string callstr = "";
            string locstr  = "";

            // get parameters
            try
            {
                if (paramstr.Contains("?"))
                {
                    // OK, we have parameters --> cut them out and make all uppercase
                    paramstr = paramstr.Substring(paramstr.IndexOf("?") + 1).ToUpper();
                    var pars = System.Web.HttpUtility.ParseQueryString(paramstr);
                    callstr = pars.Get("CALL");
                    locstr  = pars.Get("LOC");
                }
            }
            catch (Exception ex)
            {
                // return error
                return("Error while parsing parameters!");
            }
            // check parameters
            if (!Callsign.Check(callstr))
            {
                return("Error: " + callstr + " is not a valid callsign!");
            }
            LocationDesignator ld = null;

            // locstr == null or empty --> return last recent location
            if (String.IsNullOrEmpty(locstr))
            {
                ld = LocationFind(callstr);
                if (ld == null)
                {
                    return("Error: Location not found in database!");
                }
                json = ld.ToJSON();
                return(json);
            }
            if (locstr == "ALL")
            {
                List <LocationDesignator> l = LocationFindAll(callstr);
                if (l == null)
                {
                    return("Error: Location not found in database!");
                }
                JsonSerializerSettings settings = new JsonSerializerSettings();
                settings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
                settings.FloatFormatHandling  = FloatFormatHandling.String;
                settings.Formatting           = Newtonsoft.Json.Formatting.Indented;
                settings.Culture = CultureInfo.InvariantCulture;
                json             = JsonConvert.SerializeObject(l, settings);
                return(json);
            }
            if (!MaidenheadLocator.Check(locstr))
            {
                return("Error: " + locstr + " is not a valid Maidenhead locator!");
            }
            // search call in station database, return empty string if not found
            ld = LocationFind(callstr, locstr);
            if (ld == null)
            {
                return("Error: Location not found in database!");
            }
            json = ld.ToJSON();
            return(json);
        }
Beispiel #20
0
        public DataTableCallsigns FromCSV(string filename)
        {
            // imports a variable csv format with autodetect of callsign, loc and timestamp
            DataTableCallsigns dt = new DataTableCallsigns();

            if (!File.Exists(filename))
            {
                return(dt);
            }
            try
            {
                string s = "";
                using (StreamReader sr = new StreamReader(File.OpenRead(filename)))
                {
                    while (!sr.EndOfStream)
                    {
                        s = sr.ReadLine();
                        if (!String.IsNullOrEmpty(s) && !s.StartsWith("//"))
                        {
                            string[] a = s.Split(';');
                            if (a.Length < 2)
                            {
                                a = s.Split(',');
                            }
                            string    call   = "";
                            double    lat    = double.NaN;
                            double    lon    = double.NaN;
                            string    loc    = "";
                            GEOSOURCE source = GEOSOURCE.FROMLOC;
                            // set lastupdated to filetime if no timestamp is found on file
                            string filetime    = File.GetCreationTimeUtc(filename).ToString("u");
                            string lastupdated = filetime;
                            foreach (string entry in a)
                            {
                                // search for 1st locator in line
                                if (MaidenheadLocator.Check(entry) && (entry.Length == 6) && String.IsNullOrEmpty(loc))
                                {
                                    MaidenheadLocator.LatLonFromLoc(entry, PositionInRectangle.MiddleMiddle, out lat, out lon);
                                    break;
                                }
                                // search for 1st callsign in line
                                if (Callsign.Check(entry) && String.IsNullOrEmpty(call))
                                {
                                    call = entry.Trim().ToUpper();
                                }
                                DateTime timestamp;
                                if (DateTime.TryParseExact(entry, "yyyy-MM-dd HH:mm:ssZ", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out timestamp))
                                {
                                    lastupdated = timestamp.ToString("u");
                                }
                            }
                            if (GeographicalPoint.Check(lat, lon))
                            {
                                // store array values in DataTable
                                DataRow row = dt.NewRow();
                                row["Call"]        = call;
                                row["Lat"]         = lat;
                                row["Lon"]         = lon;
                                row["Source"]      = source.ToString();
                                row["LastUpdated"] = lastupdated;
                                DataRow oldrow = dt.Rows.Find(row["Call"].ToString());
                                if (oldrow != null)
                                {
                                    // call found --> check for update
                                    if (String.Compare(row["LastUpdated"].ToString(), oldrow["LastUpdated"].ToString()) > 0)
                                    {
                                        oldrow["Lat"]         = row["Lat"];
                                        oldrow["Lon"]         = row["Lon"];
                                        oldrow["Source"]      = row["Source"];
                                        oldrow["LastUpdated"] = row["LastUpdated"];
                                    }
                                }
                                else
                                {
                                    // add new row
                                    dt.Rows.Add(row);
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
            }
            return(dt);
        }
Beispiel #21
0
        public DataTableCallsigns FromDTB(string filename)
        {
            // imports DTB database from Win-Test

            DataTableCallsigns dt = new DataTableCallsigns();

            if (!File.Exists(filename))
            {
                return(dt);
            }
            try
            {
                using (StreamReader sr = new StreamReader(File.OpenRead(filename)))
                {
                    while (!sr.EndOfStream)
                    {
                        char[] buffer = new char[26];
                        sr.ReadBlock(buffer, 0, 14);
                        sr.ReadBlock(buffer, 14, 12);
                        if (!sr.EndOfStream)
                        {
                            string call        = "";
                            string loc         = "";
                            string lastupdated = "";
                            double lat         = double.NaN;
                            double lon         = double.NaN;
                            int    i           = 0;
                            while ((buffer[i] != 0) && (i < 14))
                            {
                                call += (char)buffer[i];
                                i++;
                            }
                            i = 14;
                            while ((i < 21) && (buffer[i] != 0))
                            {
                                loc += (char)buffer[i];
                                i++;
                            }
                            i = 21;
                            while ((i < 26) && (buffer[i] != 0))
                            {
                                lastupdated += (char)buffer[i];
                                i++;
                            }

                            call = call.Trim().ToUpper();
                            loc  = loc.Trim().ToUpper();
                            try
                            {
                                if (lastupdated[2] < '5')
                                {
                                    lastupdated = "20" + lastupdated[2] + lastupdated[3] + "-" + lastupdated[0] + lastupdated[1] + "-01 00:00:00Z";
                                }
                                else
                                {
                                    lastupdated = "19" + lastupdated[2] + lastupdated[3] + "-" + lastupdated[0] + lastupdated[1] + "-01 00:00:00Z";
                                }
                            }
                            catch
                            {
                            }
                            if (MaidenheadLocator.Check(loc))
                            {
                                MaidenheadLocator.LatLonFromLoc(loc, PositionInRectangle.MiddleMiddle, out lat, out lon);
                            }
                            GEOSOURCE source = GEOSOURCE.FROMLOC;
                            if (GeographicalPoint.Check(lat, lon))
                            {
                                DataRow row = dt.NewRow();
                                row["Call"]        = call;
                                row["Lat"]         = lat;
                                row["Lon"]         = lon;
                                row["Source"]      = source.ToString();
                                row["LastUpdated"] = lastupdated;
                                DataRow oldrow = dt.Rows.Find(row["Call"].ToString());
                                if (oldrow != null)
                                {
                                    // call found --> check for update
                                    if (String.Compare(row["LastUpdated"].ToString(), oldrow["LastUpdated"].ToString()) > 0)
                                    {
                                        oldrow["Lat"]         = row["Lat"];
                                        oldrow["Lon"]         = row["Lon"];
                                        oldrow["Source"]      = row["Source"];
                                        oldrow["LastUpdated"] = row["LastUpdated"];
                                    }
                                }
                                else
                                {
                                    // add new row
                                    dt.Rows.Add(row);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(dt);
        }
Beispiel #22
0
        public DataTableCallsigns FromCALL3(string filename)
        {
            // imports CALL3.TXT as used by WSJT
            // fields are
            // CALLSIGN, LOCATOR, EME FLAG, (these first three fields are used by WSJT)
            // plus optional fields:
            // STATE, FIRST NAME, EMAIL ADDRESS, NOTES, REVISION DATE

            DataTableCallsigns dt = new DataTableCallsigns();

            if (!File.Exists(filename))
            {
                return(dt);
            }
            try
            {
                string s = "";
                using (StreamReader sr = new StreamReader(File.OpenRead(filename)))
                {
                    while (!sr.EndOfStream)
                    {
                        s = sr.ReadLine();
                        if (!String.IsNullOrEmpty(s) && !s.StartsWith("//"))
                        {
                            string[] a = s.Split(',');
                            // store array values in DataTable
                            string call = a[0];
                            string loc  = a[1];
                            double lat  = double.NaN;
                            double lon  = double.NaN;
                            if (MaidenheadLocator.Check(loc))
                            {
                                MaidenheadLocator.LatLonFromLoc(loc, PositionInRectangle.MiddleMiddle, out lat, out lon);
                            }
                            GEOSOURCE source      = GEOSOURCE.FROMLOC;
                            DateTime  lastupdated = DateTime.MinValue.ToUniversalTime();
                            if (a.Length >= 7)
                            {
                                // try to get an revision date maybe in various formats
                                // MMMonVHF
                                try
                                {
                                    lastupdated = DateTime.ParseExact(a[7], "MM/yy", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
                                }
                                catch (Exception ex)
                                {
                                }
                            }
                            if (GeographicalPoint.Check(lat, lon))
                            {
                                DataRow row = dt.NewRow();
                                row["Call"]        = call;
                                row["Lat"]         = lat;
                                row["Lon"]         = lon;
                                row["Source"]      = source.ToString();
                                row["LastUpdated"] = lastupdated.ToString("u");
                                DataRow oldrow = dt.Rows.Find(row["Call"].ToString());
                                if (oldrow != null)
                                {
                                    // call found --> check for update
                                    if (String.Compare(row["LastUpdated"].ToString(), oldrow["LastUpdated"].ToString()) > 0)
                                    {
                                        oldrow["Lat"]         = row["Lat"];
                                        oldrow["Lon"]         = row["Lon"];
                                        oldrow["Source"]      = row["Source"];
                                        oldrow["LastUpdated"] = row["LastUpdated"];
                                    }
                                }
                                else
                                {
                                    // add new row
                                    dt.Rows.Add(row);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(dt);
        }
Beispiel #23
0
 public void LocatorToLatLng_0()
 {
     var(lat, lon) = MaidenheadLocator.LocatorToLatLng("IO91lk");
     lat.Should().Be(51.4375);
     lon.Should().Be(-1.0416666666666572);
 }
Beispiel #24
0
 public void LatLngToLocator_2() => MaidenheadLocator.LatLngToLocator(51.4375, -1.0417, 2).Should().Be("IO91lk45xa");
Beispiel #25
0
        private string DeliverQRV(string paramstr)
        {
            string json = "";
            // set default values
            string callstr = "";
            string locstr  = "";
            string bandstr = "";
            BAND   band    = Properties.Settings.Default.Band;

            // get parameters
            try
            {
                if (paramstr.Contains("?"))
                {
                    // OK, we have parameters --> cut them out and make all uppercase
                    paramstr = paramstr.Substring(paramstr.IndexOf("?") + 1).ToUpper();
                    var pars = System.Web.HttpUtility.ParseQueryString(paramstr);
                    callstr = pars.Get("CALL");
                    locstr  = pars.Get("LOC");
                    bandstr = pars.Get("BAND");
                }
            }
            catch (Exception ex)
            {
                // return error
                return("Error while parsing parameters!");
            }
            // check parameters
            if (!Callsign.Check(callstr))
            {
                return("Error: " + callstr + " is not a valid callsign!");
            }
            if (!MaidenheadLocator.Check(locstr))
            {
                return("Error: " + locstr + " is not a valid Maidenhead locator!");
            }
            // set band to currently selected if empty
            if (string.IsNullOrEmpty(bandstr))
            {
                band = Properties.Settings.Default.Band;
            }
            else
            {
                band = Bands.ParseStringValue(bandstr);
            }
            if (band == BAND.BNONE)
            {
                return("Error: " + bandstr + " is not a valid band value!");
            }
            // search call in station database, return empty string if not found
            if (band != BAND.BALL)
            {
                QRVDesignator qrv = StationData.Database.QRVFind(callstr, locstr, band);
                if (qrv == null)
                {
                    return("Error: QRV info not found in database!");
                }
                json = qrv.ToJSON();
                return(json);
            }
            List <QRVDesignator> qrvs = StationData.Database.QRVFind(callstr, locstr);

            if ((qrvs == null) || (qrvs.Count() == 0))
            {
                return("Error: QRV info not found in database!");
            }
            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
            settings.FloatFormatHandling  = FloatFormatHandling.String;
            settings.Formatting           = Newtonsoft.Json.Formatting.Indented;
            json = JsonConvert.SerializeObject(qrvs, settings);
            return(json);
        }
Beispiel #26
0
 public LocationDesignator(string call, double lat, double lon, GEOSOURCE source) : this(call, MaidenheadLocator.LocFromLatLon(lat, lon, false, 3), lat, lon, source, 0, DateTime.UtcNow)
 {
 }
Beispiel #27
0
        private string DeliverPropagationPath(string paramstr)
        {
            string json = "";
            // set default values
            string mycallstr = "";
            string mylocstr  = "";
            string dxcallstr = "";
            string dxlocstr  = "";
            string bandstr   = "";
            BAND   band      = Properties.Settings.Default.Band;

            // get parameters
            try
            {
                if (paramstr.Contains("?"))
                {
                    // OK, we have parameters --> cut them out and make all uppercase
                    paramstr = paramstr.Substring(paramstr.IndexOf("?") + 1).ToUpper();
                    var pars = System.Web.HttpUtility.ParseQueryString(paramstr);
                    mycallstr = pars.Get("MYCALL");
                    mylocstr  = pars.Get("MYLOC");
                    dxcallstr = pars.Get("DXCALL");
                    dxlocstr  = pars.Get("DXLOC");
                    bandstr   = pars.Get("BAND");
                }
            }
            catch (Exception ex)
            {
                // return error
                return("Error while parsing parameters!");
            }
            // check parameters
            if (!Callsign.Check(mycallstr))
            {
                return("Error: " + mycallstr + " is not a valid callsign!");
            }
            if (!Callsign.Check(dxcallstr))
            {
                return("Error: " + dxcallstr + " is not a valid callsign!");
            }
            if (!String.IsNullOrEmpty(mylocstr) && !MaidenheadLocator.Check(mylocstr))
            {
                return("Error: " + mylocstr + " is not a valid Maidenhead locator!");
            }
            if (!String.IsNullOrEmpty(dxlocstr) && !MaidenheadLocator.Check(dxlocstr))
            {
                return("Error: " + dxlocstr + " is not a valid Maidenhead locator!");
            }
            // set band to currently selected if empty
            if (string.IsNullOrEmpty(bandstr))
            {
                band = Properties.Settings.Default.Band;
            }
            else
            {
                band = Bands.ParseStringValue(bandstr);
            }
            if (band == BAND.BNONE)
            {
                return("Error: " + bandstr + " is not a valid band value!");
            }
            // search call in station database, return empty string if not found
            LocationDesignator myloc = LocationFind(mycallstr, mylocstr);

            if (myloc == null)
            {
                return("Error: MyLocation not found in database!");
            }
            LocationDesignator dxloc = LocationFind(dxcallstr, dxlocstr);

            if (dxloc == null)
            {
                return("Error: DXLocation not found in database!");
            }

            // get qrv info or create default
            QRVDesignator myqrv = StationData.Database.QRVFindOrCreateDefault(myloc.Call, myloc.Loc, band);

            // set qrv defaults if zero
            if (myqrv.AntennaHeight == 0)
            {
                myqrv.AntennaHeight = StationData.Database.QRVGetDefaultAntennaHeight(band);
            }
            if (myqrv.AntennaGain == 0)
            {
                myqrv.AntennaGain = StationData.Database.QRVGetDefaultAntennaGain(band);
            }
            if (myqrv.Power == 0)
            {
                myqrv.Power = StationData.Database.QRVGetDefaultPower(band);
            }

            // get qrv info or create default
            QRVDesignator dxqrv = StationData.Database.QRVFindOrCreateDefault(dxloc.Call, dxloc.Loc, band);

            // set qrv defaults if zero
            if (dxqrv.AntennaHeight == 0)
            {
                dxqrv.AntennaHeight = StationData.Database.QRVGetDefaultAntennaHeight(band);
            }
            if (dxqrv.AntennaGain == 0)
            {
                dxqrv.AntennaGain = StationData.Database.QRVGetDefaultAntennaGain(band);
            }
            if (dxqrv.Power == 0)
            {
                dxqrv.Power = StationData.Database.QRVGetDefaultPower(band);
            }

            // find local obstruction, if any
            LocalObstructionDesignator o = ElevationData.Database.LocalObstructionFind(myloc.Lat, myloc.Lon, Properties.Settings.Default.ElevationModel);
            double mybearing             = LatLon.Bearing(myloc.Lat, myloc.Lon, dxloc.Lat, dxloc.Lon);
            double myobstr = (o != null) ? o.GetObstruction(myqrv.AntennaHeight, mybearing) : double.MinValue;

            // get or calculate propagation path
            PropagationPathDesignator ppath = PropagationData.Database.PropagationPathFindOrCreateFromLatLon(
                this,
                myloc.Lat,
                myloc.Lon,
                GetElevation(myloc.Lat, myloc.Lon) + myqrv.AntennaHeight,
                dxloc.Lat,
                dxloc.Lon,
                GetElevation(dxloc.Lat, dxloc.Lon) + dxqrv.AntennaHeight,
                Bands.ToGHz(band),
                LatLon.Earth.Radius * Properties.Settings.Default.Path_Band_Settings[band].K_Factor,
                Properties.Settings.Default.Path_Band_Settings[band].F1_Clearance,
                ElevationData.Database.GetDefaultStepWidth(Properties.Settings.Default.ElevationModel),
                Properties.Settings.Default.ElevationModel,
                myobstr);

            if (ppath == null)
            {
                return(json);
            }
            // add additional info to ppath
            ppath.Location1 = myloc;
            ppath.Location2 = dxloc;
            ppath.QRV1      = myqrv;
            ppath.QRV2      = dxqrv;
            // convert path to json
            json = ppath.ToJSON();
            return(json);
        }
Beispiel #28
0
        private bool ValidateDetails()
        {
            // validates user details and sets position on map
            // enables/disables next button
            double mlat, mlon;

            // colour Textbox if more precise lat/lon information is available
            if (MaidenheadLocator.IsPrecise(tb_Latitude.Value, tb_Longitude.Value, 3))
            {
                if (tb_Locator.BackColor != Color.PaleGreen)
                {
                    tb_Locator.BackColor = Color.PaleGreen;
                }
            }
            else
            {
                if (tb_Locator.BackColor != Color.FloralWhite)
                {
                    tb_Locator.BackColor = Color.FloralWhite;
                }
            }
            if (GeographicalPoint.Check(tb_Latitude.Value, tb_Longitude.Value))
            {
                // update locator text if not focusd
                if (!tb_Locator.Focused)
                {
                    tb_Locator.SilentText = MaidenheadLocator.LocFromLatLon(tb_Latitude.Value, tb_Longitude.Value, Properties.Settings.Default.Locator_SmallLettersForSubsquares, (int)Properties.Settings.Default.Locator_MaxLength / 2, true);
                }
                // get locator polygon
                Callsignpolygons.Clear();
                List <PointLatLng> l = new List <PointLatLng>();
                // add loc bounds to map polygons
                MaidenheadLocator.LatLonFromLoc(tb_Locator.Text, PositionInRectangle.TopLeft, out mlat, out mlon);
                l.Add(new PointLatLng(mlat, mlon));
                MaidenheadLocator.LatLonFromLoc(tb_Locator.Text, PositionInRectangle.TopRight, out mlat, out mlon);
                l.Add(new PointLatLng(mlat, mlon));
                MaidenheadLocator.LatLonFromLoc(tb_Locator.Text, PositionInRectangle.BottomRight, out mlat, out mlon);
                l.Add(new PointLatLng(mlat, mlon));
                MaidenheadLocator.LatLonFromLoc(tb_Locator.Text, PositionInRectangle.BottomLeft, out mlat, out mlon);
                l.Add(new PointLatLng(mlat, mlon));
                GMapPolygon p = new GMapPolygon(l, tb_Locator.Text.ToString());
                p.Stroke = new Pen(Color.FromArgb(255, Color.Magenta), 3);
                p.Fill   = new SolidBrush(Color.FromArgb(0, Color.Magenta));
                Callsignpolygons.Polygons.Add(p);
                // update user position
                UserPos.Position = new PointLatLng(tb_Latitude.Value, tb_Longitude.Value);
                // update map position
                if (!IsDraggingMarker)
                {
                    string loc = MaidenheadLocator.LocFromLatLon(tb_Latitude.Value, tb_Longitude.Value, Properties.Settings.Default.Locator_SmallLettersForSubsquares, (int)Properties.Settings.Default.Locator_MaxLength / 2, true);
                    MaidenheadLocator.LatLonFromLoc(loc, PositionInRectangle.MiddleMiddle, out mlat, out mlon);
                    gm_Callsign.Position = new PointLatLng(mlat, mlon);
                    // adjust map zoom level
                    int zoom = loc.Length;
                    switch (zoom)
                    {
                    case 6:
                        gm_Callsign.Zoom = 12;
                        break;

                    case 8:
                        gm_Callsign.Zoom = 15;
                        break;

                    case 10:
                        gm_Callsign.Zoom = 17;
                        break;
                    }
                }
            }
            // check all values
            if (Callsign.Check(tb_Callsign.Text) && MaidenheadLocator.Check(tb_Locator.Text) && !double.IsNaN(tb_Latitude.Value) && !double.IsNaN(tb_Longitude.Value))
            {
                StationLocation.Lat      = tb_Latitude.Value;
                StationLocation.Lon      = tb_Longitude.Value;
                StationLocation.Source   = MaidenheadLocator.IsPrecise(tb_Latitude.Value, tb_Longitude.Value, 3) ? GEOSOURCE.FROMUSER : GEOSOURCE.FROMLOC;
                StationLocation.Loc      = MaidenheadLocator.LocFromLatLon(StationLocation.Lat, StationLocation.Lon, false, 3);
                tb_Elevation.SilentValue = GetElevation(StationLocation.Lat, StationLocation.Lon);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #29
0
        public HorizonDlg(string call, double lat, double lon, LocalObstructionDesignator localobstruction)
        {
            InitializeComponent();
            Location         = StationData.Database.LocationFindOrCreate(call, MaidenheadLocator.LocFromLatLon(lat, lon, false, 3));
            QRV              = StationData.Database.QRVFindOrCreateDefault(call, MaidenheadLocator.LocFromLatLon(lat, lon, false, 3), Properties.Settings.Default.Band);
            LocalObstruction = localobstruction;
            Elevation        = ElevationData.Database[Location.Lat, Location.Lon, Properties.Settings.Default.ElevationModel];
            AntennaHeight    = (QRV.AntennaHeight != 0) ? QRV.AntennaHeight : StationData.Database.QRVGetDefaultAntennaHeight(Properties.Settings.Default.Band);
            NumberFormatInfo provider = new NumberFormatInfo();

            provider.NumberDecimalSeparator = ".";
            provider.NumberGroupSeparator   = ",";
            tb_Horizon_Lat.Text             = Location.Lat.ToString("F8", provider);
            tb_Horizon_Lon.Text             = Location.Lon.ToString("F8", provider);
            tb_Horizon_Elevation.Text       = ElevationData.Database[Location.Lat, Location.Lon, Properties.Settings.Default.ElevationModel].ToString("F0", provider);
            tb_Horizon_Height.Text          = AntennaHeight.ToString("F0", provider);
            tb_Horizon_K_Factor.Text        = Properties.Settings.Default.Path_Band_Settings[Properties.Settings.Default.Band].K_Factor.ToString("F2", provider);
            tb_Horizon_QRG.Text             = Bands.GetStringValue(Properties.Settings.Default.Band);
            tb_Horizon_F1_Clearance.Text    = Properties.Settings.Default.Path_Band_Settings[Properties.Settings.Default.Band].F1_Clearance.ToString("F2", provider);
            tb_Horizon_ElevationModel.Text  = Properties.Settings.Default.ElevationModel.ToString();
            // setting User Agent to fix Open Street Map issue 2016-09-20
            GMap.NET.MapProviders.GMapProvider.UserAgent = "AirScout";
            // clearing referrer URL issue 2019-12-14
            gm_Horizon.MapProvider.RefererUrl = "";
            // set initial settings for main map
            gm_Horizon.MapProvider = GMapProviders.Find(Properties.Settings.Default.Map_Provider);
            gm_Horizon.IgnoreMarkerOnMouseWheel = true;
            gm_Horizon.MinZoom             = 0;
            gm_Horizon.MaxZoom             = 20;
            gm_Horizon.Zoom                = 8;
            gm_Horizon.DragButton          = System.Windows.Forms.MouseButtons.Left;
            gm_Horizon.CanDragMap          = true;
            gm_Horizon.ScalePen            = new Pen(Color.Black, 3);
            gm_Horizon.MapScaleInfoEnabled = true;
            gm_Horizon.Overlays.Add(horizons);
            GMarkerGoogle gm = new GMarkerGoogle(new PointLatLng(Location.Lat, Location.Lon), GMarkerGoogleType.red_dot);

            gm.ToolTipText = Location.Call;
            horizons.Markers.Add(gm);
            horizon.Stroke = new Pen(Color.Red, 3);
            horizons.Routes.Add(horizon);
            this.Text = "Radio Horizon of " + Location.Call;
            // initialize charts
            InitializeCharts();
            // activate Polar if nothing checked
            if (!Properties.Settings.Default.Horizon_Plot_Polar && !Properties.Settings.Default.Horizon_Plot_Cartesian && !Properties.Settings.Default.Horizon_Plot_Map)
            {
                Properties.Settings.Default.Horizon_Plot_Polar = true;
            }
            // show according child windows
            UpdateCharts();
            // create ToolTip on this window
            TT       = new ToolTip();
            OwnerWin = gm_Horizon;
            HorizonDlg_SizeChanged(this, null);
            // set map bounds
            Map_Left   = Location.Lon;
            Map_Right  = Location.Lon;
            Map_Top    = Location.Lat;
            Map_Bottom = Location.Lat;
        }
Beispiel #30
0
 public void LocatorToLatLng_1()
 {
     var(lat, lon) = MaidenheadLocator.LocatorToLatLng("IO91lk45");
     lat.Should().Be(51.43958333333333);
     lon.Should().Be(-1.0458333333333485);
 }