public IGrid Generate()
        {
            if (Source == null)
            {
                Source = new RegularGrid();
            }
            if (Domain != null)
            {
                Source.Origin                     = this.Origin;
                Source.ActualLayerCount           = this.LayerCount;
                Source.RowCount                   = RowCount;
                Source.ColumnCount                = ColumnCount;
                Source.IBound                     = new DataCube <float>(this.LayerCount, RowCount, ColumnCount);
                Source.DELC                       = new DataCube <float>(1, 1, RowCount);
                Source.DELR                       = new DataCube <float>(1, 1, ColumnCount);
                Source.DELC.Flags[0, 0]           = TimeVarientFlag.Constant;
                Source.DELR.Flags[0, 0]           = TimeVarientFlag.Constant;
                Source.DELC.Constants[0, 0]       = this.XSize;
                Source.DELR.Constants[0, 0]       = this.YSize;
                Source.DELC.ILArrays[0]["0", ":"] = this.XSize;
                Source.DELR.ILArrays[0]["0", ":"] = this.YSize;
                Source.Projection                 = Domain.Projection;
                Source.BBox                       = new Envelope(Domain.Extent.MinX, Domain.Extent.MaxX, Domain.Extent.MinY, Domain.Extent.MaxY);

                int active = 0;
                var geo    = Domain.Features[0].Geometry.Coordinates;
                List <Coordinate> centroids = new List <Coordinate>();
                for (int r = 0; r < RowCount; r++)
                {
                    for (int c = 0; c < ColumnCount; c++)
                    {
                        var cor = Source.LocateCentroid(c + 1, r + 1);

                        if (SpatialRelationship.PointInPolygon(geo, cor))
                        {
                            for (int l = 0; l < Source.ActualLayerCount; l++)
                            {
                                Source.IBound[l, r, c] = 1;
                            }
                            active++;
                            centroids.Add(cor);
                        }
                    }
                }
                Source.ActiveCellCount         = active;
                Source.Elevations              = new DataCube <float>(Source.LayerCount, 1, active);
                Source.Elevations.Variables[0] = "Top Elevation";

                for (int i = 0; i < active; i++)
                {
                    //var cell = DEM.ProjToCell(centroids[i]);
                    //if (cell != null && cell.Row > 0)
                    //    Source.Elevations.Value[0][0][i] = (float)DEM.Value[cell.Row, cell.Column];
                    //else
                    //    Source.Elevations.Value[0][0][i] = 0;
                    var pt = new Coordinate(centroids[i].X - 0.5 * XSize, centroids[i].Y - 0.5 * YSize);
                    Source.Elevations[0, 0, i] = ZonalStatastics.GetCellAverage(DEM, pt, XSize, AveragingMethod);
                }

                for (int l = 1; l < Source.LayerCount; l++)
                {
                    Source.Elevations.Variables[l] = string.Format("Layer {0} Bottom Elevation", l);
                    for (int i = 0; i < active; i++)
                    {
                        Source.Elevations[l, 0, i] = (float)(Source.Elevations[l - 1, 0, i] - LayerGroups[l - 1].LayerHeight);
                    }
                }
                Source.BuildTopology();
                Source.Elevations.Topology = Source.Topology;
            }
            else
            {
                Error = "The domain featureset is null";
            }
            return(Source);
        }
        public override void Map()
        {
            var fea_target = TargetFeatureSet.Features;
            int progress   = 0;
            int index_ap   = 0;

            if (Source is IRaster)
            {
                try
                {
                    OnProcessing(progress);
                    var     ras = Source as IRaster;
                    float[] vec = null;
                    if (TargetFeatureSet.FeatureType == FeatureType.Point)
                    {
                        vec = ZonalStatastics.ZonalByPoint(ras, TargetFeatureSet);
                    }
                    else
                    if (TargetFeatureSet.FeatureType == FeatureType.Polygon)
                    {
                        vec = ZonalStatastics.ZonalByGrid(ras, TargetFeatureSet, AveragingMethod);
                    }
                    foreach (var ap in ArealProperties)
                    {
                        if (ap.IsParameter)
                        {
                            for (int i = 0; i < vec.Length; i++)
                            {
                                var vv = GetValue(ap.ParameterName, vec[i].ToString());
                                if (vv != ZonalStatastics.NoDataValueString)
                                {
                                    ap.Parameter.SetValue(float.Parse(vv), i);
                                }
                                else
                                {
                                    ap.Parameter.SetValue(ap.DefaultValue, i);
                                }
                            }
                        }
                        else
                        {
                            var mat = Package.GetType().GetProperty(ap.PropertyName).GetValue(Package) as DataCube <float>;
                            if (mat != null)
                            {
                                if (mat[GridLayer] != null)
                                {
                                    for (int i = 0; i < vec.Length; i++)
                                    {
                                        var vv = GetValue(ap.PropertyName, vec[i].ToString());
                                        if (vv != ZonalStatastics.NoDataValueString)
                                        {
                                            mat[GridLayer, 0, i] = float.Parse(vv);
                                        }
                                        else
                                        {
                                            mat[GridLayer, 0, i] = (float)ap.DefaultValue;
                                        }
                                    }
                                }
                            }
                        }
                        progress = index_ap * 100 / ArealProperties.Count;
                        OnProcessing(progress);
                        index_ap++;
                    }
                    OnProcessing(100);
                    OnProcessed(ConstantWords.Successful);
                }
                catch (Exception ex)
                {
                    OnProcessing(100);
                    OnProcessed("Failed. Error message: " + ex.Message);
                }
            }
        }