Exemplo n.º 1
0
        public PropagationHorizonDesignator PropagationHorizonFind(PropagationHorizonDesignator hor, ELEVATIONMODEL model)
        {
            System.Data.SQLite.SQLiteDatabase db = GetPropagationDatabase(model);
            // save localobstruction
            LocalObstructionDesignator obstr = hor.LocalObstruction;

            lock (db.DBCommand)
            {
                db.DBCommand.CommandText = "SELECT * FROM " + PropagationHorizonDesignator.TableName + " WHERE Lat = @Lat AND Lon = @Lon AND h = @h AND Dist = @Dist AND QRG = @QRG AND Radius = @Radius AND F1_Clearance = @F1_Clearance AND StepWidth = @StepWidth";
                db.DBCommand.Parameters.Clear();
                db.DBCommand.Parameters.Add(hor.AsDouble("Lat"));
                db.DBCommand.Parameters.Add(hor.AsDouble("Lon"));
                db.DBCommand.Parameters.Add(hor.AsDouble("h"));
                db.DBCommand.Parameters.Add(hor.AsDouble("Dist"));
                db.DBCommand.Parameters.Add(hor.AsDouble("QRG"));
                db.DBCommand.Parameters.Add(hor.AsDouble("Radius"));
                db.DBCommand.Parameters.Add(hor.AsDouble("F1_Clearance"));
                db.DBCommand.Parameters.Add(hor.AsDouble("StepWidth"));
                DataTable Result = db.Select(db.DBCommand);
                if ((Result != null) && (Result.Rows.Count > 0))
                {
                    return(new PropagationHorizonDesignator(Result.Rows[0], obstr));
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        public PropagationHorizonDesignator PropagationHorizonFindOrCreate(BackgroundWorker caller, double lat, double lon, double h, double dist, double qrg, double radius, double f1_clearance, double stepwidth, ELEVATIONMODEL model, LocalObstructionDesignator localobstruction, bool savetodatabase = true)
        {
            PropagationHorizonDesignator hd = this.PropagationHorizonFind(lat, lon, h, dist, qrg, radius, f1_clearance, stepwidth, model, localobstruction);

            if (hd == null)
            {
                hd = PropagationHorizonCreate(caller, lat, lon, h, dist, qrg, radius, f1_clearance, stepwidth, model, localobstruction, savetodatabase);
            }
            return(hd);
        }
Exemplo n.º 3
0
        public void PropagationHorizonInsertOrUpdateIfNewer(PropagationHorizonDesignator hor, ELEVATIONMODEL model)
        {
            System.Data.SQLite.SQLiteDatabase db = GetPropagationDatabase(model);
            DateTime dt = this.PropagationHorizonFindLastUpdated(hor, model);

            if (dt == DateTime.MinValue)
            {
                this.PropagationHorizonInsert(hor, model);
            }
            else if (dt < hor.LastUpdated)
            {
                this.PropagationHorizonUpdate(hor, model);
            }
        }
Exemplo n.º 4
0
 public int PropagationHorizonDelete(PropagationHorizonDesignator hor, ELEVATIONMODEL model)
 {
     System.Data.SQLite.SQLiteDatabase db = GetPropagationDatabase(model);
     lock (db.DBCommand)
     {
         db.DBCommand.CommandText = "DELETE FROM " + PropagationHorizonDesignator.TableName + " WHERE Lat = @Lat AND Lon = @Lon AND h = @h AND Dist = @Dist AND QRG = @QRG AND Radius = @Radius AND F1_Clearance = @F1_Clearance AND StepWidth = @StepWidth";
         db.DBCommand.Parameters.Clear();
         db.DBCommand.Parameters.Add(hor.AsDouble("Lat"));
         db.DBCommand.Parameters.Add(hor.AsDouble("Lon"));
         db.DBCommand.Parameters.Add(hor.AsDouble("h"));
         db.DBCommand.Parameters.Add(hor.AsDouble("Dist"));
         db.DBCommand.Parameters.Add(hor.AsDouble("QRG"));
         db.DBCommand.Parameters.Add(hor.AsDouble("Radius"));
         db.DBCommand.Parameters.Add(hor.AsDouble("F1_Clearance"));
         db.DBCommand.Parameters.Add(hor.AsDouble("StepWidth"));
         return(db.ExecuteNonQuery(db.DBCommand));
     }
 }
Exemplo n.º 5
0
 public int PropagationHorizonUpdate(PropagationHorizonDesignator hor, ELEVATIONMODEL model)
 {
     System.Data.SQLite.SQLiteDatabase db = GetPropagationDatabase(model);
     lock (db.DBCommand)
     {
         db.DBCommand.CommandText = "UPDATE " + PropagationHorizonDesignator.TableName + " SET Lat = @Lat, Lon = @Lon, h = @h, Dist = @Dist, QRG = @QRG, Radius = @Radius, F1_Clearance = @F1_Clearance, @StepWidth = @StepWidth, Horizon = @Horizon, LastUpdated = @LastUpdated WHERE Lat = @Lat AND Lon = @Lon AND h = @h AND Dist = @Dist AND QRG = @QRG AND Radius = @Radius AND F1_Clearance = @F1_Clearance AND StepWidth = @StepWidth";
         db.DBCommand.Parameters.Clear();
         db.DBCommand.Parameters.Add(hor.AsDouble("Lat"));
         db.DBCommand.Parameters.Add(hor.AsDouble("Lon"));
         db.DBCommand.Parameters.Add(hor.AsDouble("h"));
         db.DBCommand.Parameters.Add(hor.AsDouble("Dist"));
         db.DBCommand.Parameters.Add(hor.AsDouble("QRG"));
         db.DBCommand.Parameters.Add(hor.AsDouble("Radius"));
         db.DBCommand.Parameters.Add(hor.AsDouble("F1_Clearance"));
         db.DBCommand.Parameters.Add(hor.AsDouble("StepWidth"));
         db.DBCommand.Parameters.Add(hor.AsBinary("Horizon"));
         db.DBCommand.Parameters.Add(hor.AsUNIXTime("LastUpdated"));
         return(db.ExecuteNonQuery(db.DBCommand));
     }
 }
Exemplo n.º 6
0
 public int PropagationHorizonInsert(PropagationHorizonDesignator hor, ELEVATIONMODEL model)
 {
     System.Data.SQLite.SQLiteDatabase db = GetPropagationDatabase(model);
     lock (db.DBCommand)
     {
         db.DBCommand.CommandText = "INSERT INTO " + PropagationHorizonDesignator.TableName + " (Lat, Lon, h, Dist, QRG, Radius, F1_Clearance, StepWidth, Horizon, LastUpdated) VALUES (@Lat, @Lon, @h, @Dist, @QRG, @Radius, @F1_Clearance, @StepWidth, @Horizon, @LastUpdated)";
         db.DBCommand.Parameters.Clear();
         db.DBCommand.Parameters.Add(hor.AsDouble("Lat"));
         db.DBCommand.Parameters.Add(hor.AsDouble("Lon"));
         db.DBCommand.Parameters.Add(hor.AsDouble("h"));
         db.DBCommand.Parameters.Add(hor.AsDouble("Dist"));
         db.DBCommand.Parameters.Add(hor.AsDouble("QRG"));
         db.DBCommand.Parameters.Add(hor.AsDouble("Radius"));
         db.DBCommand.Parameters.Add(hor.AsDouble("F1_Clearance"));
         db.DBCommand.Parameters.Add(hor.AsDouble("StepWidth"));
         db.DBCommand.Parameters.Add(hor.AsBinary("Horizon"));
         db.DBCommand.Parameters.Add(hor.AsUNIXTime("LastUpdated"));
         return(db.ExecuteNonQuery(db.DBCommand));
     }
 }
Exemplo n.º 7
0
 public DateTime PropagationHorizonFindLastUpdated(PropagationHorizonDesignator hor, ELEVATIONMODEL model)
 {
     System.Data.SQLite.SQLiteDatabase db = GetPropagationDatabase(model);
     lock (db.DBCommand)
     {
         db.DBCommand.CommandText = "SELECT LastUpdated FROM " + PropagationHorizonDesignator.TableName + " WHERE Lat = @Lat AND Lon = @Lon AND h = @h AND Dist = @Dist AND QRG = @QRG AND Radius = @Radius AND F1_Clearance = @F1_Clearance AND StepWidth = @StepWidth";
         db.DBCommand.Parameters.Clear();
         db.DBCommand.Parameters.Add(hor.AsDouble("Lat"));
         db.DBCommand.Parameters.Add(hor.AsDouble("Lon"));
         db.DBCommand.Parameters.Add(hor.AsDouble("h"));
         db.DBCommand.Parameters.Add(hor.AsDouble("Dist"));
         db.DBCommand.Parameters.Add(hor.AsDouble("QRG"));
         db.DBCommand.Parameters.Add(hor.AsDouble("Radius"));
         db.DBCommand.Parameters.Add(hor.AsDouble("F1_Clearance"));
         db.DBCommand.Parameters.Add(hor.AsDouble("StepWidth"));
         object result = db.ExecuteScalar(db.DBCommand);
         if (result != null)
         {
             return(SQLiteEntry.UNIXTimeToDateTime((int)result));
         }
     }
     return(DateTime.MinValue);
 }
Exemplo n.º 8
0
 public bool PropagationHorizonExists(PropagationHorizonDesignator hor, ELEVATIONMODEL model)
 {
     System.Data.SQLite.SQLiteDatabase db = GetPropagationDatabase(model);
     lock (db.DBCommand)
     {
         db.DBCommand.CommandText = "SELECT EXISTS (SELECT LastUpdated FROM " + PropagationHorizonDesignator.TableName + " WHERE Lat = @Lat AND Lon = @Lon AND h = @h AND Dist = @Dist AND QRG = @QRG AND Radius = @Radius AND F1_Clearance = @F1_Clearance AND StepWidth = @StepWidth)";
         db.DBCommand.Parameters.Clear();
         db.DBCommand.Parameters.Add(hor.AsDouble("Lat"));
         db.DBCommand.Parameters.Add(hor.AsDouble("Lon"));
         db.DBCommand.Parameters.Add(hor.AsDouble("h"));
         db.DBCommand.Parameters.Add(hor.AsDouble("Dist"));
         db.DBCommand.Parameters.Add(hor.AsDouble("QRG"));
         db.DBCommand.Parameters.Add(hor.AsDouble("Radius"));
         db.DBCommand.Parameters.Add(hor.AsDouble("F1_Clearance"));
         db.DBCommand.Parameters.Add(hor.AsDouble("StepWidth"));
         long result = (long)db.DBCommand.ExecuteScalar();
         if (result > 0)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 9
0
        public PropagationHorizonDesignator PropagationHorizonCreate(BackgroundWorker caller, double lat, double lon, double h, double dist, double qrg, double radius, double f1_clearance, double stepwidth, ELEVATIONMODEL model, LocalObstructionDesignator localobstruction, bool savetodatabase = true)
        {
            // calculate propagation horizon
            // report status messages and single data points if called from background thread
            HorizonPoint[] hor              = new HorizonPoint[360];
            bool           valid            = true;
            PropagationHorizonDesignator hd = new PropagationHorizonDesignator(lat, lon, h, dist, qrg, radius, f1_clearance, stepwidth, hor, localobstruction);

            for (int j = 0; j < 360; j++)
            {
                // report progress if called from background worker
                if (caller != null)
                {
                    if (caller.WorkerReportsProgress)
                    {
                        caller.ReportProgress(-1, "Calculating horizon " + j.ToString() + "° of 360°");
                    }
                }
                double eps_min  = double.MinValue;
                double eps_dist = 0;
                short  eps_elv  = 0;
                // find or create elevation path
                ElevationPathDesignator ep = ElevationData.Database.ElevationPathFindOrCreateFromBearing(caller, lat, lon, j, dist, stepwidth, model, false);
                for (int i = 0; i < ep.Count; i++)
                {
                    double d  = i * stepwidth / 1000.0;
                    double nf = NearFieldSuppression / 1000.0;
                    double eps;
                    if (d > nf)
                    {
                        double f1c = ScoutBase.Core.Propagation.F1Radius(qrg, d, dist) * f1_clearance;
                        eps = ScoutBase.Core.Propagation.EpsilonFromHeights(h, d, ep.Path[i] + f1c, radius);
                    }
                    else
                    {
                        double f1c = ScoutBase.Core.Propagation.F1Radius(qrg, nf, dist) * f1_clearance;
                        eps = ScoutBase.Core.Propagation.EpsilonFromHeights(h, nf, ep.Path[i] + f1c, radius);
                    }
                    if (eps > eps_min)
                    {
                        eps_min  = eps;
                        eps_dist = d;
                        eps_elv  = ep.Path[i];
                    }
                }
                hor[j] = new HorizonPoint(eps_dist, eps_min, eps_elv);
                // report current horizon if called from background worker
                if (caller != null)
                {
                    if (caller.WorkerReportsProgress)
                    {
                        caller.ReportProgress(j, hor[j]);
                    }
                }
                // take status from elevation path
                if (!ep.Valid)
                {
                    valid = false;
                }
                // abort calculation if called from background worker and cancellation pending
                if (caller != null)
                {
                    if (caller.WorkerSupportsCancellation && caller.CancellationPending)
                    {
                        return(null);
                    }
                }
            }
            // copy over the horizon and status
            hd.Horizon = hor;
            hd.Valid   = valid;
            // store in database if valid
            if ((hd != null) && hd.Valid && savetodatabase)
            {
                this.PropagationHorizonInsertOrUpdateIfNewer(hd, model);
            }
            return(hd);
        }
Exemplo n.º 10
0
        public DateTime PropagationHorizonFindLastUpdated(double lat, double lon, double h, double dist, double qrg, double radius, double f1_clearance, double stepwidth, ELEVATIONMODEL model)
        {
            PropagationHorizonDesignator path = new PropagationHorizonDesignator(lat, lon, h, dist, qrg, radius, f1_clearance, stepwidth, null);

            return(this.PropagationHorizonFindLastUpdated(path, model));
        }
Exemplo n.º 11
0
        public PropagationHorizonDesignator PropagationHorizonFind(double lat, double lon, double h, double dist, double qrg, double radius, double f1_clearance, double stepwidth, ELEVATIONMODEL model, LocalObstructionDesignator localobstruction)
        {
            PropagationHorizonDesignator hor = new PropagationHorizonDesignator(lat, lon, h, dist, qrg, radius, f1_clearance, stepwidth, localobstruction);

            return(this.PropagationHorizonFind(hor, model));
        }