示例#1
0
文件: Form1.cs 项目: koperniki/DefLab
        public GridField testKriging()
        {
            var config = new KrigingModelConfig();

            config.ModelType = KrigingModelType.linear;
            config.Nugget    = 10;
            config.Range     = 10;
            config.Sill      = 10;
            var gridInfo = new GridInfo();

            gridInfo.Extent = new Extent(0, 10, 0, 10);
            gridInfo.Step   = 0.1;

            var krigingKonfig = new KrigingConfig();

            krigingKonfig.MaxPointsInSector = 10;
            krigingKonfig.SearchRadius      = 10;
            krigingKonfig.SectorsCount      = 1;

            var semivarianse = TheoreticalModel.getModelDelegate(config);

            var points = new[] { new GridPoint(1, 1, 5), new GridPoint(8, 8, 5), new GridPoint(1, 8, 5), new GridPoint(8, 1, 5), new GridPoint(5, 5, 0) };

            var grid = Kriging.getGrid(gridInfo, false, krigingKonfig, semivarianse, points, null, null);

            return(grid);
        }
示例#2
0
        public static void DrawGridByKriging(double[] t, double[] x, double[] y, double[] extent, double resolution, string fileName)
        {
            Kriging kriging = new Kriging(x, y, t);

            kriging.Train(KrigingModel.Exponential, 0, 100);
            DrawGrid(extent, resolution, kriging, fileName);
        }
示例#3
0
        public ActionResult TestIDW(DateTime time)
        {
            IDW     idw;
            Kriging kriging;

            using (DataCenterServiceClient client = new DataCenterServiceClient())
            {
                StationHourData[] data = client.GetStationHourDataListFromHistoryByTime("GDAEIB", "2019!@GD", time);
                data = data.Where(o => o.AQI != "—").ToArray();
                double[] X = new double[data.Length], Y = new double[data.Length], T = new double[data.Length];
                for (int i = 0; i < data.Length; i++)
                {
                    StationHourData item = data[i];
                    double          x = double.Parse(item.Longitude), y = double.Parse(item.Latitude);
                    double          t = double.Parse(item.AQI);
                    X[i] = x;
                    Y[i] = y;
                    T[i] = t;
                }
                idw     = new IDW(X, Y, T);
                kriging = new Kriging(X, Y, T);
            }
            double temp = idw.Predict(112, 36);

            kriging.Train(KrigingModel.Exponential, 0, 100);
            temp = kriging.Predict(112, 36);
            return(Content(temp.ToString()));
        }
示例#4
0
        private void button4_Click(object sender, EventArgs e)
        {
            #region GP工具的使用
            #region 得到参数
            IFeatureLayer layer     = GetFeatureLayer((string)comboBox1.SelectedItem); //输入点要素
            string        Zfield    = (string)comboBox2.SelectedItem;                  //Z字段
            string        outRaster = textBox1.Text;                                   //输出栅格


            string semiVariogramprops = ""; //半变异函数属性
            string semivariogramType;       //克里金方法
            if (radioButton1.Checked)
            {
                semivariogramType  = (string)comboBox3.SelectedItem;
                semiVariogramprops = "KrigingModelOrdinary(" + semivariogramType + "," + lagsize + "," + majorrange + "," + partialsill + "," + nugget + ")";
            }
            else if (radioButton2.Checked)
            {
                semivariogramType  = (string)comboBox4.SelectedItem;
                semiVariogramprops = "KrigingModelUniversal(" + semivariogramType + "," + lagsize + "," + majorrange + "," + partialsill + "," + nugget + ")";
            }

            object cellSize = textBox2.Text; //输出像元大小

            string searchRadius = "";        //搜索半径
            if (radioButton3.Checked)
            {
                searchRadius = "RadiusFixed(" + textBox3.Text + "," + textBox4.Text + ")";
            }
            else if (radioButton4.Checked)
            {
                searchRadius = "RadiusVariable(" + textBox5.Text + "," + textBox6.Text + ")";
            }

            string outvarianceprediction_raster = textBox7.Text;//输出预测栅格数据的方差
            #endregion
            #region 设置GP工具
            //实例化GP工具
            Geoprocessor gp = new Geoprocessor();
            gp.OverwriteOutput = true;
            //设置Kriging参数
            Kriging kriging = new Kriging();
            kriging.in_point_features   = layer;
            kriging.z_field             = Zfield;
            kriging.out_surface_raster  = outRaster;
            kriging.semiVariogram_props = semiVariogramprops;
            kriging.cell_size           = cellSize;
            kriging.search_radius       = searchRadius;
            // kriging.out_variance_prediction_raster = outvarianceprediction_raster;
            //执行GP工具
            IGeoProcessorResult results = (IGeoProcessorResult)gp.Execute(kriging, null);
            #endregion
            #endregion
        }
示例#5
0
        private void krigingWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            var surface2D = e.Argument as Surface2D;

            if (surface2D == null)
            {
                e.Cancel = true;
                return;
            }

            var inputPoints = Matrix <float> .Build.DenseOfColumnArrays(surface2D.XValues, surface2D.YValues);

            var valueVector = Vector <float> .Build.DenseOfArray(surface2D.ZValues);

            var vgram = new Powvargram(inputPoints, valueVector);
            var krig  = new Kriging(inputPoints, valueVector, vgram);

            var xmin = surface2D.XValues.Min();
            var ymin = surface2D.YValues.Min();

            // Create the heatmap series
            var surfMap = new HeatMapSeries
            {
                X0                   = surface2D.XValues.Min(),
                X1                   = surface2D.XValues.Max(),
                Y0                   = surface2D.YValues.Min(),
                Y1                   = surface2D.YValues.Max(),
                Data                 = new double[surface2D.Nx, surface2D.Ny],
                Interpolate          = false,
                CoordinateDefinition = HeatMapCoordinateDefinition.Edge
            };

            var progress = 0;

            for (var i = 0; i < surface2D.Ny; i++)
            {
                for (var j = 0; j < surface2D.Nx; j++)
                {
                    progress++;
                    krigingWorker.ReportProgress((progress * 100) / (surface2D.Nx * surface2D.Ny));
                    var point2Interpolate =
                        Vector <float> .Build.DenseOfArray(new[] { xmin + (j * surface2D.Dx), ymin + (i * surface2D.Dy) });

                    surfMap.Data[j, i] = krig.Interpolate(point2Interpolate);
                }
            }

            var result = new Tuple <HeatMapSeries, Surface2D>(surfMap, surface2D);

            e.Result = result;
        }
示例#6
0
        private void krigingToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (targetFeaturePath == null)
            {
                if (MessageBox.Show(this, "No target feature class specified, would you like to choose one?", "Charlotte", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    String path = FileUtil.SelectOpenPath("Select shapefile", "ESRI Shapefile(*.shp)|*.shp");
                    if (path != null)
                    {
                        targetFeaturePath = path;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }

            try
            {
                string       tiffPath = "temp/kriging.tif";
                Geoprocessor gp       = new Geoprocessor();
                Kriging      kriging  = new Kriging();
                kriging.in_point_features   = targetFeaturePath;
                kriging.out_surface_raster  = tiffPath;
                kriging.z_field             = "additional";
                kriging.semiVariogram_props = "Spherical";

                // multi-threading will cause problem here
                // do not attempt!!!

                //new Thread(() =>
                //{
                //    Thread.CurrentThread.IsBackground = true;

                currentStatusText = "Kriging...";
                gp.Execute(kriging, null);
                AddRasterToView(tiffPath);
                currentStatusText = defaultStatusText;
                //}).Start();
            }
            catch (Exception ex)
            {
                ShowGeoprocessingError(ex);
            }
        }
示例#7
0
        static void Main(string[] args)
        {
            string        file  = @"D:\Works\Kriging\Kriging\Data\ZoneA.csv";
            List <double> x     = new List <double>();
            List <double> y     = new List <double>();
            List <double> z     = new List <double>();
            var           lines = File.ReadAllLines(file);

            for (int i = 1; i < lines.Length; i++)
            {
                string[] items = lines[i].Split(',');
                if (items.Length > 3)
                {
                    x.Add(Convert.ToDouble(items[0]));
                    y.Add(Convert.ToDouble(items[1]));
                    z.Add(Convert.ToDouble(items[3]));
                }
            }

            RasterContext rasterContext = new RasterContext(0, 0, 100, 100, 200, 160, false);
            Kriging       kriging       = new Kriging(x.ToArray(), y.ToArray(), z.ToArray(), rasterContext);

            kriging.Initialize();
            float[] buffer = new float[200 * 160];
            var     timer  = System.Diagnostics.Stopwatch.StartNew();

            kriging.OrdinaryKrige(Kriging.Model.Spherical, buffer, 0.0, kriging.GetEstimatedSill(), 4000, 16, 16, 0);
            Console.WriteLine(timer.ElapsedMilliseconds);
            timer.Restart();
            Kriging2 kriging2 = new Kriging2(x.ToArray(), y.ToArray(), z.ToArray(), rasterContext);

            kriging2.SimpleKrige(Kriging2.Model.Spherical, buffer, 0.0, kriging.GetEstimatedSill(), 4000);
            Console.WriteLine(timer.ElapsedMilliseconds);
            Console.ReadKey();
            Console.WriteLine("");
        }
示例#8
0
        private void button4_Click(object sender, EventArgs e)
        {
            #region GP工具的使用
            #region 得到参数
            IFeatureLayer layer = GetFeatureLayer((string)comboBox1.SelectedItem);//输入点要素
            string Zfield = (string)comboBox2.SelectedItem;//Z字段
            string outRaster = textBox1.Text;//输出栅格

            string semiVariogramprops = "";//半变异函数属性
            string semivariogramType;//克里金方法
            if (radioButton1.Checked)
            {
                semivariogramType = (string)comboBox3.SelectedItem;
                semiVariogramprops = "KrigingModelOrdinary(" + semivariogramType + "," + lagsize + "," + majorrange + "," + partialsill + "," + nugget + ")";
            }
            else if (radioButton2.Checked)
            {
                semivariogramType = (string)comboBox4.SelectedItem;
                semiVariogramprops = "KrigingModelUniversal(" + semivariogramType + "," + lagsize + "," + majorrange + "," + partialsill + "," + nugget + ")";
            }

            object cellSize = textBox2.Text;//输出像元大小

            string searchRadius = "";//搜索半径
            if (radioButton3.Checked)
            {
                searchRadius = "RadiusFixed(" + textBox3.Text + "," + textBox4.Text + ")";
            }
            else if (radioButton4.Checked)
            {
                searchRadius = "RadiusVariable(" + textBox5.Text + "," + textBox6.Text + ")";
            }

            string outvarianceprediction_raster = textBox7.Text;//输出预测栅格数据的方差
            #endregion
            #region 设置GP工具
            //实例化GP工具
            Geoprocessor gp = new Geoprocessor();
            gp.OverwriteOutput = true;
            //设置Kriging参数
            Kriging kriging = new Kriging();
            kriging.in_point_features = layer;
            kriging.z_field = Zfield;
            kriging.out_surface_raster = outRaster;
            kriging.semiVariogram_props = semiVariogramprops;
            kriging.cell_size = cellSize;
            kriging.search_radius = searchRadius;
               // kriging.out_variance_prediction_raster = outvarianceprediction_raster;
            //执行GP工具
            IGeoProcessorResult results = (IGeoProcessorResult)gp.Execute(kriging, null);
            #endregion
            #endregion
        }