예제 #1
0
        public MapZoomInfo CalculateMapZoomInfo(BoundingBox boundingBox, int viewingWidthPx)
        {
            GeographicalPoint centrePoint = this.GetCenterPoint(boundingBox);
            int zoomLevel = this.zoomLevelCalculator.GetZoomLevel(boundingBox, viewingWidthPx);

            return(new MapZoomInfo(centrePoint, zoomLevel));
        }
예제 #2
0
파일: Webserver.cs 프로젝트: dh1df/AirScout
        public short GetElevation(double lat, double lon)
        {
            if (!GeographicalPoint.Check(lat, lon))
            {
                return(0);
            }
            short elv = ElevationData.Database.ElvMissingFlag;

            // try to get elevation data from distinct elevation model
            // start with detailed one
            if (Properties.Settings.Default.Elevation_SRTM1_Enabled && (elv == ElevationData.Database.ElvMissingFlag))
            {
                elv = ElevationData.Database[lat, lon, ELEVATIONMODEL.SRTM1, false];
            }
            if (Properties.Settings.Default.Elevation_SRTM3_Enabled && (elv == ElevationData.Database.ElvMissingFlag))
            {
                elv = ElevationData.Database[lat, lon, ELEVATIONMODEL.SRTM3, false];
            }
            if (Properties.Settings.Default.Elevation_GLOBE_Enabled && (elv == ElevationData.Database.ElvMissingFlag))
            {
                elv = ElevationData.Database[lat, lon, ELEVATIONMODEL.GLOBE, false];
            }
            // set it to zero if still invalid
            if (elv <= ElevationData.Database.TileMissingFlag)
            {
                elv = 0;
            }
            return(elv);
        }
 public GeographicalBoundingBox(GeographicalPoint topLeft, GeographicalPoint bottomRight)
 {
     if (topLeft == null) throw new ArgumentNullException(nameof(topLeft));
     if (bottomRight == null) throw new ArgumentNullException(nameof(bottomRight));
     TopLeft = topLeft;
     BottomRight = bottomRight;
 }
예제 #4
0
    private static int Wind(GeographicalPoint location, Edge edge, Position position)
    {
        if (edge.RelativePositionOf(location) != position)
        {
            return(0);
        }

        return(1);
    }
예제 #5
0
        public bool LocationInRange(GeographicalPoint location, Orientation orientation)
        {
            if (orientation == Orientation.Ascending)
            {
                return(_endPoint.Latitude > location.Latitude);
            }

            return(_endPoint.Latitude <= location.Latitude);
        }
예제 #6
0
    private static int DescendingIntersection(GeographicalPoint location, Edge edge)
    {
        if (edge.AscendingRelativeTo(location))
        {
            return(0);
        }

        if (!edge.LocationInRange(location, Orientation.Descending))
        {
            return(0);
        }

        return(Wind(location, edge, Position.Right));
    }
예제 #7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //string kml2 = File.ReadAllText(@"C:\Users\wu\OneDrive\Documents\_Radius\Peoples Republic of Mandurah.kml", Encoding.UTF8);

        if (!IsPostBack)
        {
            LocationRuleBL          locationRuleBL    = new LocationRuleBL(Application["ConnectionStringName"].ToString());
            List <LocationRuleView> locationRuleViews = locationRuleBL.LocationRuleViewSelectCurrent();

            foreach (LocationRuleView locationRuleView in locationRuleViews)
            {
                if (locationRuleView.LocationType == (int)Enumerators.LocationType.Polygon &&
                    locationRuleView.Polygon.Length > 0)
                {
                    locationRuleView.Polygon = new string(locationRuleView.Polygon.Where(c => !char.IsControl(c)).ToArray());
                    int startIndex = locationRuleView.Polygon.IndexOf("<coordinates>");
                    int endIndex   = locationRuleView.Polygon.IndexOf("</coordinates>");
                    locationRuleView.Polygon = locationRuleView.Polygon.Substring(startIndex + 13, endIndex - startIndex - 13)
                                               .Replace(",0", ",")
                                               .Replace(" ", "")
                                               .Trim(',');

                    double[] doubles = Array.ConvertAll(locationRuleView.Polygon.Split(','), double.Parse);

                    List <GeographicalPoint> points = new List <GeographicalPoint>();

                    for (int i = 0; i <= doubles.Length - 1; i += 2)
                    {
                        points.Add(new GeographicalPoint(doubles[i + 1], doubles[i]));
                    }

                    Polygon           polygon  = new Polygon(points);
                    GeographicalPoint location = new GeographicalPoint(-32.521050, 115.716910); // my house
                    bool contains = polygon.Contains(location);
                }
            }

            string kml    = File.ReadAllText(@"C:\Users\wu\OneDrive\Documents\_Radius\Peoples Republic of Mandurah.kml", Encoding.UTF8);
            string pairs2 = new string(kml.Where(c => !char.IsControl(c)).ToArray());

            //int startIndex = kml.IndexOf("<coordinates>");
            //int endIndex = kml.IndexOf("</coordinates>");
            //string pairs = kml.Substring(startIndex + 13, endIndex - startIndex - 13);
            //pairs = pairs.Replace(",0", ",").Trim(',');
            //pairs = pairs.Replace(" ", "");
            ////pairs = pairs.Replace(@"\n", "");
            ////pairs = pairs.Replace(@"\t", "");
            //pairs2 = new string(pairs.Where(c => !char.IsControl(c)).ToArray());
        }
    }
예제 #8
0
    public bool Contains(GeographicalPoint location)
    {
        GeographicalPoint[] polygonPointsWithClosure = PolygonPointsWithClosure();

        int windingNumber = 0;

        for (int pointIndex = 0; pointIndex < polygonPointsWithClosure.Length - 1; pointIndex++)
        {
            Edge edge = new Edge(polygonPointsWithClosure[pointIndex], polygonPointsWithClosure[pointIndex + 1]);
            windingNumber += AscendingIntersection(location, edge);
            windingNumber -= DescendingIntersection(location, edge);
        }

        return(windingNumber != 0);
    }
예제 #9
0
        public Position RelativePositionOf(GeographicalPoint location)
        {
            double positionCalculation =
                (_endPoint.Longitude - _startPoint.Longitude) * (location.Latitude - _startPoint.Latitude) -
                (location.Longitude - _startPoint.Longitude) * (_endPoint.Latitude - _startPoint.Latitude);

            if (positionCalculation > 0)
            {
                return(Position.Left);
            }

            if (positionCalculation < 0)
            {
                return(Position.Right);
            }

            return(Position.Center);
        }
예제 #10
0
 public bool AscendingRelativeTo(GeographicalPoint location)
 {
     return(_startPoint.Latitude <= location.Latitude);
 }
예제 #11
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);
            }
        }
예제 #12
0
파일: Callsigns.cs 프로젝트: dh1df/AirScout
        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);
        }
예제 #13
0
파일: Callsigns.cs 프로젝트: dh1df/AirScout
        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);
        }
예제 #14
0
파일: Callsigns.cs 프로젝트: dh1df/AirScout
        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);
        }
예제 #15
0
파일: Callsigns.cs 프로젝트: dh1df/AirScout
        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);
        }
예제 #16
0
 public Edge(GeographicalPoint startPoint, GeographicalPoint endPoint)
 {
     _startPoint = startPoint;
     _endPoint   = endPoint;
 }
예제 #17
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.");
                }
            }
예제 #18
0
 public MapZoomInfo(GeographicalPoint centrePoint, int zoomLevel)
 {
     this.CentrePoint = centrePoint;
     this.ZoomLevel   = zoomLevel;
 }