public EnvironmentalLayerRange GetRange(double?percentile = null)
        {
            double?min = null;
            double?max = null;

            TraverseCells((x, y, value) => {
                if (value != NoValueMarker)
                {
                    if (!min.HasValue)
                    {
                        min = value;
                        max = value;
                    }
                    else
                    {
                        if (value < min)
                        {
                            min = value;
                        }
                        else if (value > max)
                        {
                            max = value;
                        }
                    }
                }
            });
            // Now work out the percentile....
            if (max.HasValue && min.HasValue)
            {
                double val = 0;
                if (percentile.HasValue)
                {
                    val = (max.Value - min.Value) * percentile.Value;
                }
                var range = new EnvironmentalLayerRange {
                    Max = max.Value - val, Min = min.Value - val, Percentile = percentile
                };
                return(range);
            }

            return(null);
        }
        protected override void RunModelImpl(GridLayer targetLayer, IEnumerable <GridLayer> layers, ModelPointSet points)
        {
            double fVal, fDestNoVal;
            bool   bTestFailed;

            // Work out ranges for the varying percentile bands across all layers...
            if (layers.Count() <= 0)
            {
                return;
            }

            List <EnvironmentalLayerRange[]> Range = new List <EnvironmentalLayerRange[]>();

            foreach (GridLayer layer in layers)
            {
                var array = new EnvironmentalLayerRange[4];
                array[0] = layer.GetRangeForPoints(points.Points, 0.0);
                array[1] = layer.GetRangeForPoints(points.Points, 0.05);
                array[2] = layer.GetRangeForPoints(points.Points, 0.1);
                array[3] = layer.GetRangeForPoints(points.Points, 0.25);
                Range.Add(array);
            }

            // For each cell for each layer...
            var firstLayer = layers.ElementAt(0);

            fDestNoVal = firstLayer.NoValueMarker;

            targetLayer.SetAllCells(fDestNoVal);

            for (int y = 0; y < firstLayer.Height; ++y)
            {
                for (int x = 0; x < firstLayer.Width; ++x)
                {
                    // First test %0 - %100
                    bTestFailed = false;
                    for (int i = 0; i < layers.Count(); ++i)
                    {
                        var layer = layers.ElementAt(i);
                        fVal = layer.GetCellValue(x, y);
                        if (fVal == layer.NoValueMarker)
                        {
                            bTestFailed = true;
                            break;
                        }
                        else
                        {
                            if ((fVal < Range[i][0].Min) || (fVal > Range[i][0].Max))   // %0-%100
                            {
                                bTestFailed = true;
                                targetLayer.SetCellValue(x, y, fDestNoVal);
                                break;
                            }
                        }
                    }

                    if (!bTestFailed)
                    {
                        targetLayer.SetCellValue(x, y, 1);
                        // Second test %5 - %95
                        for (int i = 0; i < layers.Count(); ++i)
                        {
                            var layer = layers.ElementAt(i);
                            fVal = layer.GetCellValue(x, y);
                            if ((fVal < Range[i][1].Min) || (fVal > Range[i][1].Max))   // %5-%95
                            {
                                bTestFailed = true;
                                break;
                            }
                        }

                        if (!bTestFailed)
                        {
                            targetLayer.SetCellValue(x, y, 2);
                            for (int i = 0; i < layers.Count(); ++i)
                            {
                                var layer = layers.ElementAt(i);
                                fVal = layer.GetCellValue(x, y);
                                if ((fVal < Range[i][2].Min) || (fVal > Range[i][2].Max))   // %10-%90
                                {
                                    bTestFailed = true;
                                    break;
                                }
                            }

                            if (!bTestFailed)
                            {
                                targetLayer.SetCellValue(x, y, 3);
                                for (int i = 0; i < layers.Count(); ++i)
                                {
                                    var layer = layers.ElementAt(i);
                                    fVal = layer.GetCellValue(x, y);
                                    if ((fVal < Range[i][3].Min) || (fVal > Range[i][3].Max))   // %25-%75
                                    {
                                        bTestFailed = true;
                                        break;
                                    }
                                }

                                if (!bTestFailed)
                                {
                                    targetLayer.SetCellValue(x, y, 4);
                                }
                            }
                        }
                    }
                }

                if ((y % 20) == 0)
                {
                    int percent = (int)(((float)y / (float)targetLayer.Height) * (float)100);
                    if (ProgressObserver != null)
                    {
                        ProgressObserver.ProgressMessage("Running BOXCAR Model...", percent);
                    }

                    if (IsCancelled)
                    {
                        return;
                    }
                }
            }

            if (ProgressObserver != null)
            {
                ProgressObserver.ProgressMessage("Running BOXCAR Model...", 100);
            }
        }
Ejemplo n.º 3
0
        public EnvironmentalLayerRange GetRange(double? percentile = null)
        {
            double? min = null;
            double? max = null;

            TraverseCells((x, y, value) => {
                if (value != NoValueMarker) {
                    if (!min.HasValue) {
                        min = value;
                        max = value;
                    } else {
                        if (value < min) {
                            min = value;
                        } else if (value > max) {
                            max = value;
                        }
                    }
                }
            });
            // Now work out the percentile....
            if (max.HasValue && min.HasValue) {
                double val = 0;
                if (percentile.HasValue) {
                    val = (max.Value - min.Value) * percentile.Value;
                }
                var range = new EnvironmentalLayerRange { Max = max.Value - val, Min = min.Value - val, Percentile = percentile };
                return range;
            }

            return null;
        }
Ejemplo n.º 4
0
        protected override void RunModelImpl(GridLayer targetLayer, IEnumerable<GridLayer> layers, ModelPointSet points)
        {
            double fVal, fDestNoVal;
            bool bTestFailed;

            // Work out ranges for the varying percentile bands across all layers...
            if (layers.Count() <= 0) {
                return;
            }

            List<EnvironmentalLayerRange[]> Range = new List<EnvironmentalLayerRange[]>();
            foreach (GridLayer layer in layers) {
                var array = new EnvironmentalLayerRange[4];
                array[0] = layer.GetRangeForPoints(points.Points, 0.0);
                array[1] = layer.GetRangeForPoints(points.Points, 0.05);
                array[2] = layer.GetRangeForPoints(points.Points, 0.1);
                array[3] = layer.GetRangeForPoints(points.Points, 0.25);
                Range.Add(array);
            }

            // For each cell for each layer...
            var firstLayer = layers.ElementAt(0);
            fDestNoVal = firstLayer.NoValueMarker;

            targetLayer.SetAllCells(fDestNoVal);

            for (int y = 0; y < firstLayer.Height; ++y) {
                for (int x = 0; x < firstLayer.Width; ++x) {
                    // First test %0 - %100
                    bTestFailed = false;
                    for (int i = 0; i < layers.Count(); ++i) {
                        var layer = layers.ElementAt(i);
                        fVal = layer.GetCellValue(x, y);
                        if (fVal == layer.NoValueMarker) {
                            bTestFailed = true;
                            break;
                        } else {
                            if ((fVal < Range[i][0].Min) || (fVal > Range[i][0].Max)) { // %0-%100
                                bTestFailed = true;
                                targetLayer.SetCellValue(x, y, fDestNoVal);
                                break;
                            }
                        }
                    }

                    if (!bTestFailed) {

                        targetLayer.SetCellValue(x, y, 1);
                        // Second test %5 - %95
                        for (int i = 0; i < layers.Count(); ++i) {
                            var layer = layers.ElementAt(i);
                            fVal = layer.GetCellValue(x, y);
                            if ((fVal < Range[i][1].Min) || (fVal > Range[i][1].Max)) { // %5-%95
                                bTestFailed = true;
                                break;
                            }
                        }

                        if (!bTestFailed) {
                            targetLayer.SetCellValue(x, y, 2);
                            for (int i = 0; i < layers.Count(); ++i) {
                                var layer = layers.ElementAt(i);
                                fVal = layer.GetCellValue(x, y);
                                if ((fVal < Range[i][2].Min) || (fVal > Range[i][2].Max)) { // %10-%90
                                    bTestFailed = true;
                                    break;
                                }
                            }

                            if (!bTestFailed) {
                                targetLayer.SetCellValue(x, y, 3);
                                for (int i = 0; i < layers.Count(); ++i) {
                                    var layer = layers.ElementAt(i);
                                    fVal = layer.GetCellValue(x, y);
                                    if ((fVal < Range[i][3].Min) || (fVal > Range[i][3].Max)) { // %25-%75
                                        bTestFailed = true;
                                        break;
                                    }
                                }

                                if (!bTestFailed) {
                                    targetLayer.SetCellValue(x, y, 4);
                                }
                            }
                        }
                    }
                }

                if ((y % 20) == 0) {
                    int percent = (int)(((float)y / (float)targetLayer.Height) * (float)100);
                    if (ProgressObserver != null) {
                        ProgressObserver.ProgressMessage("Running BOXCAR Model...", percent);
                    }

                    if (IsCancelled) {
                        return;
                    }
                }
            }

            if (ProgressObserver != null) {
                ProgressObserver.ProgressMessage("Running BOXCAR Model...", 100);
            }
        }