Ejemplo n.º 1
0
        public F3SharpViewModel(SpatialUnit spatialUnit) : base(spatialUnit)
        {
            AddYearCommand        = new RelayCommand(AddYear);
            AddTimestepCommand    = new RelayCommand(AddTimestep);
            RemoveTimestepCommand = new RelayCommand(RemoveTimestep);
            AddMetricCommand      = new RelayCommand(AddMetric);
            RemoveMetricCommand   = new RelayCommand(RemoveMetric);
            PasteCommand          = new RelayCommand(Paste);
            ApplyMetricsCommand   = new RelayCommand(ApplyMetrics);

            Timestep     = new TimeseriesDatum();
            Metric       = new ObjectiveMetricSingleValue();
            SelectedYear = Model.Attributes.AssessmentYear;

            if (Su.Objective.Function == null)
            {
                SelectedObjective = _objectives.Keys.First();
            }
            else
            {
                foreach (var objective in _objectives)
                {
                    if (Su.Objective.Function.GetType() == objective.Value)
                    {
                        _selectedObjective = objective.Key;
                    }
                }
            }

            Su.Objective.Metrics.CollectionChanged +=
                (sender, args) => RaisePropertyChanged(nameof(CanChangeObjective));
        }
        public F2ViewModel(SpatialUnit spatialUnit) : base(spatialUnit)
        {
            AddTimestepCommand    = new RelayCommand(AddTimestep);
            RemoveTimestepCommand = new RelayCommand(RemoveTimestep);
            AddYearCommand        = new RelayCommand(AddYear);
            PasteCommand          = new RelayCommand(Paste);

            Timestep     = new ObjectiveResult();
            SelectedYear = Model.Attributes.AssessmentYear;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 基于水平与垂直空间结构参数的枝下高模型
        /// </summary>
        /// <param name="unit"></param>
        /// <param name="array"></param>
        /// <param name="age"></param>
        /// <returns></returns>
        public List <Tree> CalcuUBH(SpatialUnit unit, List <Tree> array, List <double> param, int age)
        {
            int    count = 0;
            double avgE  = 0;
            double avgS  = 0;
            double avgW  = 0;
            double avgN  = 0;

            for (int i = 0; i < array.Count; i++)
            {
                if (!array[i].isEdge)
                {
                    //垂直、水平空间结构参数
                    double ePv = unit.CalcuPv(1, i, array);
                    double sPv = unit.CalcuPv(2, i, array);
                    double wPv = unit.CalcuPv(3, i, array);
                    double nPv = unit.CalcuPv(4, i, array);

                    //计算树冠枝下高
                    array[i].eastUnderBranchHeight  = param[0] + param[1] * age + param[2] * ePv; avgE += array[i].eastUnderBranchHeight;
                    array[i].southUnderBranchHeight = param[0] + param[1] * age + param[2] * sPv; avgS += array[i].southUnderBranchHeight;
                    array[i].westUnderBranchHeight  = param[0] + param[1] * age + param[2] * wPv; avgW += array[i].westUnderBranchHeight;
                    array[i].northUnderBranchHeight = param[0] + param[1] * age + param[2] * nPv; avgN += array[i].northUnderBranchHeight;
                    array[i].UnderBranchHeight      = (array[i].eastUnderBranchHeight + array[i].southUnderBranchHeight + array[i].westUnderBranchHeight + array[i].northUnderBranchHeight) / 4;
                    count++;

                    if (Double.IsNaN(array[i].UnderBranchHeight) || Double.IsInfinity(array[i].UnderBranchHeight))
                    {
                        Console.WriteLine("ERROR: NaN or Infinity of UnderBranchHeight");
                        return(null);
                    }
                }
            }

            if (count > 0)
            {
                for (int i = 0; i < array.Count; i++)
                {
                    if (array[i].isEdge)
                    {
                        //计算树冠枝下高
                        array[i].eastUnderBranchHeight  = avgE / count;
                        array[i].southUnderBranchHeight = avgS / count;
                        array[i].westUnderBranchHeight  = avgW / count;
                        array[i].northUnderBranchHeight = avgN / count;
                        array[i].UnderBranchHeight      = (array[i].eastUnderBranchHeight + array[i].southUnderBranchHeight + array[i].westUnderBranchHeight + array[i].northUnderBranchHeight) / 4;
                    }
                }
            }

            return(array);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 基于水平与垂直空间结构参数的冠幅模型
        /// </summary>
        /// <param name="unit"></param>
        /// <param name="array"></param>
        /// <param name="age"></param>
        /// <returns></returns>
        public List <Tree> CalcuCrown1(SpatialUnit unit, List <Tree> array, List <double> param, int age)
        {
            int    count = 0;
            double avgE  = 0;
            double avgS  = 0;
            double avgW  = 0;
            double avgN  = 0;

            for (int i = 0; i < array.Count; i++)
            {
                if (!array[i].isEdge)
                {
                    //垂直、水平空间结构参数
                    double ePh = unit.CalcuPh(1, i, array);
                    double sPh = unit.CalcuPh(2, i, array);
                    double wPh = unit.CalcuPh(3, i, array);
                    double nPh = unit.CalcuPh(4, i, array);

                    //计算冠幅
                    array[i].eastCrownWidth  = param[0] + param[1] * age + param[2] * ePh; avgE += array[i].eastCrownWidth;
                    array[i].southCrownWidth = param[0] + param[1] * age + param[2] * sPh; avgS += array[i].southCrownWidth;
                    array[i].westCrownWidth  = param[0] + param[1] * age + param[2] * wPh; avgW += array[i].westCrownWidth;
                    array[i].northCrownWidth = param[0] + param[1] * age + param[2] * nPh; avgN += array[i].northCrownWidth;
                    array[i].CrownWidth      = (array[i].eastCrownWidth + array[i].southCrownWidth + array[i].westCrownWidth + array[i].northCrownWidth) / 2;
                    count++;

                    if (Double.IsNaN(array[i].CrownWidth) || Double.IsInfinity(array[i].CrownWidth))
                    {
                        Console.WriteLine("ERROR: NaN or Infinity of CrownWidth");
                        return(null);
                    }
                }
            }

            if (count > 0)
            {
                for (int i = 0; i < array.Count; i++)
                {
                    if (array[i].isEdge)
                    {
                        //计算冠幅
                        array[i].eastCrownWidth  = avgE / count;
                        array[i].southCrownWidth = avgS / count;
                        array[i].westCrownWidth  = avgW / count;
                        array[i].northCrownWidth = avgN / count;
                        array[i].CrownWidth      = (array[i].eastCrownWidth + array[i].southCrownWidth + array[i].westCrownWidth + array[i].northCrownWidth) / 2;
                    }
                }
            }
            return(array);
        }
 protected SpatialUnitViewModel(SpatialUnit spatialUnit)
 {
     SpatialUnit   = spatialUnit.Clone();
     LocateCommand = new RelayCommand(Locate);
 }
 public F1ViewModel(SpatialUnit spatialUnit) : base(spatialUnit)
 {
 }
        private async Task ImportFromShapefile()
        {
            var dialog = new OpenFileDialog
            {
                Title      = "Open shapefile with Spatial Unit locations",
                Filter     = "Shapefile (*.shp)|*.shp",
                DefaultExt = ".shp"
            };

            if (dialog.ShowDialog() != true)
            {
                return;
            }
            var filename = dialog.FileName;
            var sf       = await ShapefileFeatureTable.OpenAsync(filename);

            var qp = new QueryParameters();

            var esi = Model.EcosystemServices.FetchIndicators <EcosystemServicesIndicator>().ToList();
            var res = await sf.QueryFeaturesAsync(qp);

            foreach (var r in res)
            {
                Trace.WriteLine($"{r.Geometry}");

                if (!(r.Geometry is MapPoint point))
                {
                    if (!(r.Geometry is Polygon polygon))
                    {
                        continue;
                    }
                    point = polygon.Extent.GetCenter();
                }
                var name = r.Attributes.FirstOrDefault(x => x.Key.ToLowerInvariant() == "name").Value as String;

                var success = false;
                foreach (var es in esi)
                {
                    foreach (var su in es.SpatialUnits)
                    {
                        if (su.Name.ToLowerInvariant() != name?.ToLowerInvariant())
                        {
                            continue;
                        }
                        su.Location.Latitude  = point.Y;
                        su.Location.Longitude = point.X;
                        su.Location.Wkid      = point.SpatialReference.Wkid;
                        success = true;
                    }
                }
                if (success)
                {
                    continue;
                }

                var wkid = point.SpatialReference.Wkid;
                if (wkid == 0)
                {
                    wkid = 4326;    // WGS84
                }
                SpatialUnit nsu = null;

                switch (Indicator.EvidenceLevel)
                {
                case Confidence.F1:
                    nsu = new F1SpatialUnit
                    {
                        Name         = name,
                        NonCompliant = false,
                        Location     = { Latitude = point.Y, Longitude = point.X, Wkid = wkid }
                    };
                    break;

                case Confidence.F2:
                    nsu = new F2SpatialUnit
                    {
                        Name     = name,
                        Location = { Latitude = point.Y, Longitude = point.X, Wkid = wkid }
                    };

                    break;

                case Confidence.F3Sharp:
                    nsu = new F3SharpSpatialUnit
                    {
                        Name     = name,
                        Location = { Latitude = point.Y, Longitude = point.X, Wkid = wkid }
                    };
                    break;

                case Confidence.F3Fuzzy:
                    nsu = new F3FuzzySpatialUnit
                    {
                        Name     = name,
                        Location = { Latitude = point.Y, Longitude = point.X, Wkid = wkid }
                    };
                    break;

                default:
                    throw new ArgumentException("Unknown evidence level.");
                }
                Indicator.SpatialUnits.Add(nsu);
                if (String.IsNullOrWhiteSpace(nsu.Name))
                {
                    nsu.Name = $"SU [{Indicator.SpatialUnits.IndexOf(nsu) + 1}]";
                }
            }
        }