Example #1
0
        public bool Equals(DataPoint2D p)
        {
            // If parameter is null return false:
            if ((object)p == null)
            {
                return false;
            }

            // Return true if the fields match:
            return (X == p.X) && (Y == p.Y);
        }
Example #2
0
        public bool Equals(DataPoint2D p)
        {
            // If parameter is null return false:
            if ((object)p == null)
            {
                return(false);
            }

            // Return true if the fields match:
            return((X == p.X) && (Y == p.Y));
        }
Example #3
0
 public bool IsNear(DataPoint2D p, decimal Tolerance)
 {
     double X1 = (double)p.X;
     double X2 = (double)X;
     double Y1 = (double)p.Y;
     double Y2 = (double)Y;
     double distance = Math.Sqrt(Math.Pow(X1-X2,2)+Math.Pow(Y1-Y2,2));
     decimal dist = (decimal)distance;
     if (dist<Tolerance)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Example #4
0
        public bool IsNear(DataPoint2D p, decimal Tolerance)
        {
            double  X1       = (double)p.X;
            double  X2       = (double)X;
            double  Y1       = (double)p.Y;
            double  Y2       = (double)Y;
            double  distance = Math.Sqrt(Math.Pow(X1 - X2, 2) + Math.Pow(Y1 - Y2, 2));
            decimal dist     = (decimal)distance;

            if (dist < Tolerance)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #5
0
        public override bool Equals(System.Object obj)
        {
            // If parameter is null return false.
            if (obj == null)
            {
                return(false);
            }

            // If parameter cannot be cast to Point return false.
            DataPoint2D p = obj as DataPoint2D;

            if ((System.Object)p == null)
            {
                return(false);
            }

            // Return true if the fields match:
            return((X == p.X) && (Y == p.Y));
        }
Example #6
0
        public decimal GetInterpolatedValue(decimal XAbsolute, decimal YAbsolute, decimal InterpolationAdjustment=1.0m, 
            decimal AdjustmentProximityLength=1.0m)
            //if the value is interpolated an adjustment is introduced to account for the 
            //difference between USGS more precise calculation and this procedure
        {
            decimal x = XAbsolute;
            decimal y = YAbsolute;
            decimal x1 = LowerLeftPoint.X;
            decimal x2 = UpperRightPoint.X;
            decimal y1 = LowerLeftPoint.Y;
            decimal y2 = UpperRightPoint.Y;

           decimal R1 = ((x2-x)/(x2-x1))*LowerLeftPoint.Value + ((x-x1)/(x2-x1))*LowerRightPoint.Value;
           decimal R2 = ((x2-x)/(x2-x1))*UpperLeftPoint.Value + ((x-x1)/(x2-x1))*UpperRightPoint.Value;

           decimal P = ((y2 - y) / (y2 - y1)) * R1 + ((y - y1) / (y2 - y1)) * R2;

           DataPoint2D readingPoint = new DataPoint2D(XAbsolute, YAbsolute, 0);
            //it is assumed that the middle 2/3 need adjustment closer to the gridded points no adjustment is made
           decimal t = Math.Min(Math.Abs(LowerRightPoint.X - LowerLeftPoint.X), Math.Abs(LowerRightPoint.Y - UpperLeftPoint.Y)) / AdjustmentProximityLength;
           
            
            if (!LowerLeftPoint.IsNear(readingPoint, t) && !LowerRightPoint.IsNear(readingPoint, t)
               && !UpperLeftPoint.IsNear(readingPoint, t) && !UpperRightPoint.IsNear(readingPoint, t))
           {
               List<decimal> values = new List<decimal>()
            {
            LowerLeftPoint.Value,
            LowerRightPoint.Value,
            UpperLeftPoint.Value,
            UpperRightPoint.Value
            };
               decimal MaxVal = values.Max();
               decimal P_adjusted = P * InterpolationAdjustment;
               decimal P_final = Math.Min(MaxVal, P_adjusted);
               return P_final; 
           }
            else
            {
                return P;
            }
        }
Example #7
0
        public decimal GetInterpolatedValue(decimal XAbsolute, decimal YAbsolute, decimal InterpolationAdjustment = 1.0m,
                                            decimal AdjustmentProximityLength = 1.0m)
        //if the value is interpolated an adjustment is introduced to account for the
        //difference between USGS more precise calculation and this procedure
        {
            decimal x  = XAbsolute;
            decimal y  = YAbsolute;
            decimal x1 = LowerLeftPoint.X;
            decimal x2 = UpperRightPoint.X;
            decimal y1 = LowerLeftPoint.Y;
            decimal y2 = UpperRightPoint.Y;

            decimal R1 = ((x2 - x) / (x2 - x1)) * LowerLeftPoint.Value + ((x - x1) / (x2 - x1)) * LowerRightPoint.Value;
            decimal R2 = ((x2 - x) / (x2 - x1)) * UpperLeftPoint.Value + ((x - x1) / (x2 - x1)) * UpperRightPoint.Value;

            decimal P = ((y2 - y) / (y2 - y1)) * R1 + ((y - y1) / (y2 - y1)) * R2;

            DataPoint2D readingPoint = new DataPoint2D(XAbsolute, YAbsolute, 0);
            //it is assumed that the middle 2/3 need adjustment closer to the gridded points no adjustment is made
            decimal t = Math.Min(Math.Abs(LowerRightPoint.X - LowerLeftPoint.X), Math.Abs(LowerRightPoint.Y - UpperLeftPoint.Y)) / AdjustmentProximityLength;


            if (!LowerLeftPoint.IsNear(readingPoint, t) && !LowerRightPoint.IsNear(readingPoint, t) &&
                !UpperLeftPoint.IsNear(readingPoint, t) && !UpperRightPoint.IsNear(readingPoint, t))
            {
                List <decimal> values = new List <decimal>()
                {
                    LowerLeftPoint.Value,
                    LowerRightPoint.Value,
                    UpperLeftPoint.Value,
                    UpperRightPoint.Value
                };
                decimal MaxVal     = values.Max();
                decimal P_adjusted = P * InterpolationAdjustment;
                decimal P_final    = Math.Min(MaxVal, P_adjusted);
                return(P_final);
            }
            else
            {
                return(P);
            }
        }
        private Quad GetQuad(double ColumnValue, double RowValue, List<double> ColumnHeaders, List<double> RowHeaders, List<List<double>> Data)
        {
            //check for boundaries

            double ColumnLeft, ColumnRight, RowAbove, RowBelow;
            int columnLeftIndex, columnRightIndex, rowAboveIndex, rowBelowIndex;


            if (RowHeaders.Count != Data.Count || ColumnHeaders.Count!=Data[0].Count)
            {
                throw new Exception("Inconsistent data. Row or column headers do not match data.");
            }

            //SPECIAL CASES: coumn or row value out of range
            //----------------------------------------------------

            if (ColumnValue < ColumnHeaders[0] || ColumnValue > ColumnHeaders[ColumnHeaders.Count - 1] || RowValue < RowHeaders[0] || RowValue > RowHeaders[RowHeaders.Count - 1])
            {
                if (ColumnValue < ColumnHeaders[0] || ColumnValue > ColumnHeaders[ColumnHeaders.Count - 1])
                {
                    if (ColumnValue < ColumnHeaders[0])
                    {
                        columnLeftIndex = 0;
                        columnRightIndex = 0;
                    }
                    else // if ( ColumnValue > ColumnHeaders[ColumnHeaders.Count - 1])
                    {
                        columnLeftIndex = ColumnHeaders.Count - 1;
                        columnRightIndex = ColumnHeaders.Count - 1;
                    }

                    //Find low and high ROW values
                    RowAbove = RowHeaders.Where(rv => rv <= RowValue).Max();
                    rowAboveIndex = RowHeaders.LastIndexOf(RowAbove);
                    RowBelow = RowHeaders.Where(rv => rv >= RowValue).Min();
                    rowBelowIndex = RowHeaders.LastIndexOf(RowBelow);
                }


                else //if (RowValue < RowHeaders[0] || RowValue > RowHeaders[RowHeaders.Count - 1])
                {
                    if (RowValue < RowHeaders[0])
                    {
                        rowAboveIndex = 0;
                        rowBelowIndex = 0;
                    }
                    else  //if (RowValue > RowHeaders[RowHeaders.Count-1])
                    {
                        rowAboveIndex = RowHeaders.Count - 1;
                        rowBelowIndex = RowHeaders.Count - 1;
                    }
                    //Find low and high COLUMN values
                    ColumnLeft = ColumnHeaders.Where(cv => cv <= ColumnValue).Max();
                    columnLeftIndex = RowHeaders.LastIndexOf(ColumnLeft);
                    ColumnRight = ColumnHeaders.Where(cv => cv >= ColumnValue).Min();
                    columnRightIndex = RowHeaders.LastIndexOf(ColumnRight);
                }


            }
            else
            {
                //Interpolated value within data table 
                // REGULAR CASE
                //----------------------------------------------------

                List<List<DataPoint2D>> DataPoints = new List<List<DataPoint2D>>();

                //Create array of datapoints
                for (int i = 0; i < RowHeaders.Count; i++)
                {
                    int j = 0;
                    List<DataPoint2D> thisRowOfPoints = new List<DataPoint2D>();

                    foreach (var item in Data[i])
                    {
                        thisRowOfPoints.Add(new DataPoint2D((decimal)ColumnHeaders[j], (decimal)RowHeaders[i], (decimal)Data[i][j]));
                    }
                    DataPoints.Add(thisRowOfPoints);
                }

                ColumnLeft = ColumnHeaders.Where(cv => cv <= ColumnValue).Max();
                columnLeftIndex = ColumnHeaders.FindIndex( x => x==ColumnLeft);
                ColumnRight= ColumnHeaders.Where(cv => cv >= ColumnValue).Min();
                columnRightIndex = ColumnHeaders.FindIndex(x => x ==ColumnRight);


                RowAbove = RowHeaders.Where(cv => cv <= RowValue).Max();
                rowAboveIndex = RowHeaders.FindIndex(x => x==RowAbove);
                RowBelow = RowHeaders.Where(cv => cv >= RowValue).Min();
                rowBelowIndex = RowHeaders.FindIndex(x => x ==RowBelow);
            }


            DataPoint2D lowerLeftPoint  = new DataPoint2D((decimal)ColumnHeaders[columnLeftIndex], (decimal)RowHeaders[rowBelowIndex], (decimal)Data[rowBelowIndex][columnLeftIndex]);
            DataPoint2D lowerRightPoint = new DataPoint2D((decimal)ColumnHeaders[columnRightIndex],(decimal)RowHeaders[rowBelowIndex], (decimal)Data[rowBelowIndex][columnRightIndex]);
            DataPoint2D upperLeftPoint  = new DataPoint2D((decimal)ColumnHeaders[columnLeftIndex], (decimal)RowHeaders[rowAboveIndex], (decimal)Data[rowAboveIndex][columnLeftIndex]);
            DataPoint2D upperRightPoint = new DataPoint2D((decimal)ColumnHeaders[columnRightIndex],(decimal)RowHeaders[rowAboveIndex], (decimal)Data[rowAboveIndex][columnRightIndex]);

            Quad q = new Quad()
            {
                LowerLeftPoint = lowerLeftPoint,
                LowerRightPoint = lowerRightPoint,
                UpperLeftPoint = upperLeftPoint,
                UpperRightPoint = upperRightPoint
            };

            return q;
        }