Exemple #1
0
 public void UpdateChart(int[] cellCount1, int time1, LandUseClassificationInfo landUseInfo)
 {
     for (int i = 0; i < cellCount1.Length; i++)
     {
         this.chartTypeCount.Series[i].Points.AddXY(time1, cellCount1[i]);
     }
 }
Exemple #2
0
        private void buttonSet_Click(object sender, EventArgs e)
        {
            var form = new LandUseSetUpForm();

            form.ShowDialog();
            this.LandUse = form.LandUse;
        }
        public override void Run()
        {
            var form = new LogisticSetUpForm();

            form.ShowDialog();
            if (form.DialogResult == DialogResult.OK)
            {
                // 获得参数
                string                    beginLayerName  = form.BeginLayerName;
                string                    endLayerName    = form.EndLayerName;
                string                    resultLayerName = form.SavePathName;
                List <string>             driveLayerNames = form.DriveLayerNames;
                int                       numOfSample     = form.NumberOfSample;
                LandUseClassificationInfo landUse         = form.LandUse;

                // 初始化对象
                var lg = new LogisticRegression(beginLayerName, endLayerName, driveLayerNames);
                lg.updateConsoleEvent += UpdateConsole;
                lg.ResultLayerName     = resultLayerName;
                lg.NumberOfSample      = numOfSample; // 采样的数目
                lg.landUse             = landUse;

                // 显示控制台
                this.consolePad = WorkbenchSingleton.Workbench.GetPad(typeof(ConsolePad)).PadContent.Control as GIS.Common.Dialogs.Console.Console;
                WorkbenchSingleton.Workbench.GetPad(typeof(ConsolePad)).BringPadToFront();
                lg.Run();
                //Thread thread = new Thread(new ThreadStart(lg.Run));
                //thread.IsBackground = true;
                //thread.Start();
            }
            else
            {
            }
        }
        /// <summary>
        /// 获取当前栅格图层中城市用地类型栅格的数量。区分栅格图层是否有属性表两种情况。
        /// </summary>
        /// <param name="rasterLayer"></param>
        /// <param name="landUseClassificationInfo"></param>
        /// <returns></returns>
        public static int GetUrbanCount(IRasterLayer rasterLayer, LandUseClassificationInfo landUseClassificationInfo)
        {
            int urbanConuts           = 0;
            IRasterBandCollection rbc = rasterLayer.Raster as IRasterBandCollection;
            IRasterBand           rb  = rbc.Item(0);
            //ITable table = rbc.Item(0).AttributeTable;
            //AttributeTable - OID, Value, Count
            ITable attributeTable = rb.AttributeTable;

            if (attributeTable != null)
            {
                int     count  = attributeTable.RowCount(null);
                int[]   values = new int[count];
                int[]   counts = new int[count];
                ICursor cursor = attributeTable.Search(null, false);
                IRow    row    = cursor.NextRow();
                int     index  = 0;
                //数据不一定有OBJECTID字段。同时列名称及顺序不一定符合条件Value,Count。
                while (row != null)
                {
                    values[index] = Convert.ToInt32(row.get_Value(GetColumnIndex(attributeTable, "VALUE")));
                    counts[index] = Convert.ToInt32(row.get_Value(GetColumnIndex(attributeTable, "COUNT")));
                    row           = cursor.NextRow();
                    index++;
                }

                for (int j = 0; j < count; j++)
                {
                    for (int i = 0; i < landUseClassificationInfo.UrbanValues.Count; i++)
                    {
                        if (Convert.ToSingle(values[j]) == landUseClassificationInfo.UrbanValues[i].LanduseTypeValue)
                        {
                            urbanConuts += Convert.ToInt32(counts[j]);
                        }
                    }
                }
            }
            else
            {
                rb.ComputeStatsAndHist();
                IRasterHistogram            rh      = rb.Histogram;
                object                      rhCount = rh.Counts;
                double[]                    counts  = (double[])rhCount;
                IRasterUniqueValueRenderer  rasterUniqueValueRenderer  = (IRasterUniqueValueRenderer)rasterLayer.Renderer;
                IRasterRendererUniqueValues rasterRendererUniqueValues = (IRasterRendererUniqueValues)rasterUniqueValueRenderer;
                IUniqueValues               uniqueValues = rasterRendererUniqueValues.UniqueValues;
                for (int j = 0; j < uniqueValues.Count; j++)
                {
                    for (int i = 0; i < landUseClassificationInfo.UrbanValues.Count; i++)
                    {
                        if (Convert.ToSingle(uniqueValues.get_UniqueValue(j)) == landUseClassificationInfo.UrbanValues[i].LanduseTypeValue)
                        {
                            urbanConuts += Convert.ToInt32(counts[j + 1]);
                        }
                    }
                }
            }

            return(urbanConuts);
        }
Exemple #5
0
 public void UpdateImage(double[] buffer, int width, int height, LandUseClassificationInfo landUseInfo)
 {
     for (int row = 0; row < height; row++)
     {
         for (int col = 0; col < width; col++)
         {
             int    pos  = row * width + col;
             double type = buffer[pos];
             if (type < 0)
             {
                 bitmap.SetPixel(col, row, Color.Transparent); // null value
                 continue;
             }
             for (int i = 0; i < landUseInfo.AllTypes.Count; i++)
             {
                 if (landUseInfo.AllTypes[i].LandUseTypeValue == type)
                 {
                     bitmap.SetPixel(col, row, Color.FromArgb(landUseInfo.AllTypes[i].LandUseTypeColor));
                     break;
                 }
             }
         }
     }
     this.pictureBox1.Image = bitmap;
 }
Exemple #6
0
 public KappaTest(double[] realBuffer, double[] simulateBuffer, int width, int height, LandUseClassificationInfo landUseInfo)
 {
     this.realBuffer     = realBuffer;
     this.simulateBuffer = simulateBuffer;
     this.landUseInfo    = landUseInfo;
     this.height         = height;
     this.width          = width;
 }
Exemple #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="beginLayernName">训练模拟起始图层名字</param>
        /// <param name="endLayerName">训练模拟终止图层名字</param>
        /// <param name="driveLayerNames">驱动因子图层名字</param>
        public AnnCa(string beginLayernName, string endLayerName, List <string> driveLayerNames, LandUseClassificationInfo landInfo)
        {
            this.beginLayernName = beginLayernName;
            this.endLayerName    = endLayerName;
            this.driveLayerNames = driveLayerNames;
            this.landInfo        = landInfo;

            //准备数据
            LoadData();
        }
Exemple #8
0
        public ImageForm(double[] buffer, int width, int height, LandUseClassificationInfo landUseInfo)
        {
            InitializeComponent();

            // 初始化图表
            InitialChart(landUseInfo);



            this.buttonStop.Enabled   = false;
            this.buttonResume.Enabled = false;
            isOn = true;

            bitmap = new Bitmap(width, height);
            for (int row = 0; row < height; row++)
            {
                for (int col = 0; col < width; col++)
                {
                    int    pos  = row * width + col;
                    double type = buffer[pos];
                    if (type < 0)
                    {
                        bitmap.SetPixel(col, row, Color.Transparent);     // null value
                        continue;
                    }
                    for (int i = 0; i < landUseInfo.AllTypes.Count; i++)
                    {
                        if (landUseInfo.AllTypes[i].LandUseTypeValue == type)
                        {
                            bitmap.SetPixel(col, row, Color.FromArgb(landUseInfo.AllTypes[i].LandUseTypeColor));
                            break;
                        }
                    }
                    //if (type < 0)
                    //{
                    //    bitmap.SetPixel(col, row, Color.Transparent);
                    //}
                    //if (type == 1)
                    //{
                    //    bitmap.SetPixel(col, row, Color.Black);
                    //}
                    //if (type == 2)
                    //{
                    //    bitmap.SetPixel(col, row, Color.Blue);
                    //}
                    //if (type == 0)
                    //{
                    //    bitmap.SetPixel(col, row, Color.White);
                    //}
                }
            }

            this.pictureBox1.Image = bitmap;
            this.labelTip.Text     = "训练准备";
        }
Exemple #9
0
 /// <summary>
 /// 绘图事件处理函数
 /// </summary>
 /// <param name="imgBuffer"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="landUseInfo"></param>
 protected void UpdateImage(double[] imgBuffer, int width, int height, LandUseClassificationInfo landUseInfo, int cnt)
 {
     if (this.imageForm.InvokeRequired)
     {
         this.imageForm.Invoke(new AsyncUpdateImage((imgBuffer1, width1, height1, landUseInfo1, cnt1) =>
         {
             this.imageForm.UpdateImage(imgBuffer1, width1, height1, landUseInfo1, cnt1);
         }), imgBuffer, width, height, landUseInfo, cnt);
     }
     else
     {
         this.imageForm.UpdateImage(imgBuffer, width, height, landUseInfo, cnt);
     }
 }
Exemple #10
0
 /// <summary>
 /// 绘制图表处理函数
 /// </summary>
 /// <param name="cellCount"></param>
 /// <param name="time"></param>
 protected void UpdateChart(int[] cellCount, int time, LandUseClassificationInfo landUseInfo)
 {
     if (this.imageForm.InvokeRequired)
     {
         this.imageForm.Invoke(new AsyncUpdateChart((cellCount1, time1, landUseInfo1) =>
         {
             this.imageForm.UpdateChart(cellCount1, time1, landUseInfo1);
         }), cellCount, time, landUseInfo);
     }
     else
     {
         this.imageForm.UpdateChart(cellCount, time, landUseInfo);
     }
 }
Exemple #11
0
 private void UpdateImage(double[] imgBuffer, int width, int height, LandUseClassificationInfo landUseInfo)
 {
     if (this.imageForm.InvokeRequired)
     {
         this.imageForm.Invoke(new AsyncUpdateImage(delegate(double[] imgBuffer1, int width1, int height1, LandUseClassificationInfo landUseInfo1)
         {
             this.imageForm.UpdateImage(imgBuffer1, width1, height1, landUseInfo);
         }), imgBuffer, width, height, landUseInfo);
     }
     else
     {
         this.imageForm.UpdateImage(imgBuffer, width, height, landUseInfo);
     }
 }
Exemple #12
0
        /// <summary>
        /// 根据土地利用类型的值获取其所在列表中的索引。
        /// </summary>
        /// <param name="landuseTypeValue"></param>
        /// <param name="landUseClassificationInfo"></param>
        /// <returns></returns>
        public static int GetLandUseTypeIndex(float landuseTypeValue, LandUseClassificationInfo landUseClassificationInfo)
        {
            int index = -1;

            for (int i = 0; i < landUseClassificationInfo.AllTypesCount; i++)
            {
                if (landuseTypeValue == landUseClassificationInfo.AllTypes[i].LanduseTypeValue)
                {
                    index = i;
                    break;
                }
            }
            return(index);
        }
 private void buttonLoadLanduseConfig_Click(object sender, EventArgs e)
 {
     dataGridViewLandUse.Rows.Clear();
     using (OpenFileDialog ofd = new OpenFileDialog())
     {
         ofd.Filter = resourceManager.GetString("String52");
         ofd.Title  = resourceManager.GetString("String53");
         if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             System.IO.StreamReader streamReader = new System.IO.StreamReader(ofd.FileName);
             System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(LandUseClassificationInfo));
             landUseClassificationInfo = (LandUseClassificationInfo)xmlSerializer.Deserialize(streamReader);
             streamReader.Close();
             for (int i = 0; i < landUseClassificationInfo.AllTypesCount; i++)
             {
                 StructLanduseInfo strucLanduseInfo = landUseClassificationInfo.AllTypes[i];
                 dataGridViewLandUse.Rows.Add();
                 if (System.Globalization.CultureInfo.CurrentCulture.Parent.Name == "zh-CHS")
                 {
                     dataGridViewLandUse.Rows[i].Cells[1].Value = strucLanduseInfo.LanduseTypeChsName;
                 }
                 else if (System.Globalization.CultureInfo.CurrentCulture.Parent.Name == "zh-CHT")
                 {
                     dataGridViewLandUse.Rows[i].Cells[1].Value = strucLanduseInfo.LanduseTypeChtName;
                 }
                 else
                 {
                     dataGridViewLandUse.Rows[i].Cells[1].Value = strucLanduseInfo.LanduseTypeEnName;
                 }
                 dataGridViewLandUse.Rows[i].Cells[0].Value = strucLanduseInfo.LanduseTypeValue;
                 dataGridViewLandUse.Rows[i].Cells[3].Value =
                     GeneralOpertor.GetBitmap(15, 15, Color.FromArgb(strucLanduseInfo.LanduseTypeColorIntValue));
                 if (landUseClassificationInfo.UrbanValues.Contains(strucLanduseInfo))
                 {
                     dataGridViewLandUse.Rows[i].Cells[2].Value = resourceManager.GetString("String8");
                 }
                 else if (landUseClassificationInfo.ConvertValues.Contains(strucLanduseInfo))
                 {
                     dataGridViewLandUse.Rows[i].Cells[2].Value = resourceManager.GetString("String6");
                 }
                 else
                 {
                     dataGridViewLandUse.Rows[i].Cells[2].Value = resourceManager.GetString("String7");
                 }
             }
         }
     }
 }
Exemple #14
0
        private void InitialChart(LandUseClassificationInfo landUseClassificationInfo)
        {
            this.chartTypeCount.Series.Clear();
            int size = landUseClassificationInfo.NumOfLandUseTypes;

            for (int j = 0; j < landUseClassificationInfo.AllTypes.Count; j++)
            {
                var landType = landUseClassificationInfo.AllTypes[j];
                var series   = new Series()
                {
                    Name              = landType.LandUseTypeName,
                    Color             = Color.FromArgb(landType.LandUseTypeColor),
                    ChartType         = SeriesChartType.Line,
                    IsVisibleInLegend = true
                };
                this.chartTypeCount.Series.Add(series);
            }
        }
Exemple #15
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            this.landUse = new LandUseClassificationInfo();

            if (IsDataGridViewCellsNotNull(this.count, 4))
            {
                for (int i = 0; i < this.count; i++)
                {
                    string            landUseType = dataGridViewLandUse.Rows[i].Cells[2].Value.ToString();
                    StructLanduseInfo info        = new StructLanduseInfo();
                    info.LandUseTypeName  = dataGridViewLandUse.Rows[i].Cells[1].Value.ToString();
                    info.LandUseTypeValue = Convert.ToDouble(dataGridViewLandUse.Rows[i].Cells[0].Value);
                    info.LandUseTypeColor = ((Bitmap)dataGridViewLandUse.Rows[i].Cells[3].Value).GetPixel(1, 1).ToArgb();
                    if (landUseType == "城市用地")
                    {
                        this.landUse.UrbanInfos.Add(info);
                        this.landUse.AllTypes.Add(info);
                    }
                    else if (landUseType == "可转换为城市用地")
                    {
                        this.landUse.ConvertableInfos.Add(info);
                        this.landUse.AllTypes.Add(info);
                    }
                    else if (landUseType == "不可转换为城市用地")
                    {
                        this.landUse.UnConvertableInfos.Add(info);
                        this.landUse.AllTypes.Add(info);
                    }
                    else if (landUseType == "数据空值")
                    {
                        this.landUse.NullInfo = info;
                    }
                }
                this.Close();
            }
            else
            {
                MessageBox.Show("数据不完整");
            }
        }
 /// <summary>
 /// 执行清空操作。
 /// </summary>
 public void Clear()
 {
     comboBoxTrainingStartImage.Items.Clear();
     comboBoxTrainingEndImage.Items.Clear();
     comboBoxSimStartImage.Items.Clear();
     comboBoxSimEndImage.Items.Clear();
     listAllLayersInMapName.Clear();
     listVariableLayersName.Clear();
     trainingStartImageName   = "";
     trainingEndImageName     = "";
     simulationStartImageName = "";
     simulationEndImageName   = "";
     convertCount             = 0;
     simulationIterations     = 0;
     delta               = 1;
     refreshInterval     = 1;
     outputImageInterval = 1;
     outputFolder        = "";
     isOutput            = false;
     isUsingDefault      = false;
     isFinish            = false;
     varibaleImages.Clear();
     landUseClassificationInfo = new LandUseClassificationInfo();
     structRasterMetaData      = new StructRasterMetaData();
     this.dataGridViewVariableDatas.Rows.Clear();
     this.comboBoxTrainingStartImage.SelectedIndex = -1;
     this.comboBoxTrainingEndImage.SelectedIndex   = -1;
     this.comboBoxSimStartImage.SelectedIndex      = -1;
     this.comboBoxSimEndImage.SelectedIndex        = -1;
     this.comboBoxTrainingStartImage.Text          = "";
     this.comboBoxTrainingEndImage.Text            = "";
     this.comboBoxSimStartImage.Text         = "";
     this.comboBoxSimEndImage.Text           = "";
     VariableMaintainer.IsSimulationFinished = false;
     this.numericUpDownConvertCount.Value    = 100;
     this.numericUpDownIterations.Value      = 10;
     isRegressed = false;
 }
Exemple #17
0
        /// <summary>
        /// 对多类土地利用模拟结果进行混淆矩阵计算。
        /// </summary>
        /// <param name="simulatedData"></param>
        /// <param name="observedData"></param>
        /// <param name="rowCount"></param>
        /// <param name="columnCount"></param>
        /// <param name="landUseClassificationInfo"></param>
        /// <returns></returns>
        public static DataTable GetMultiTypesMatrix(float[,] simulatedData, float[,] observedData, int rowCount, int columnCount, LandUseClassificationInfo landUseClassificationInfo)
        {
            int allTypesCount = landUseClassificationInfo.AllTypesCount;
            //建立记录混淆矩阵的DataTable
            DataTable dtMatrix = new DataTable();

            for (int i = 0; i < allTypesCount; i++)
            {
                if (System.Threading.Thread.CurrentThread.CurrentCulture.Parent.Name == "zh-CHS")
                {
                    dtMatrix.Columns.Add(landUseClassificationInfo.AllTypes[i].LanduseTypeChsName);
                }
                else if (System.Threading.Thread.CurrentThread.CurrentCulture.Parent.Name == "zh-CHT")
                {
                    dtMatrix.Columns.Add(landUseClassificationInfo.AllTypes[i].LanduseTypeChtName);
                }
                else if (System.Threading.Thread.CurrentThread.CurrentCulture.Parent.Name == "en")
                {
                    dtMatrix.Columns.Add(landUseClassificationInfo.AllTypes[i].LanduseTypeEnName);
                }
            }
            System.Resources.ResourceManager resourceManager = null;
            if (System.Globalization.CultureInfo.CurrentCulture.Parent.Name == "zh-CHS")
            {
                resourceManager = new System.Resources.ResourceManager("GeoSOS.CommonLibrary.Properties.Resource_zh_CHS", System.Reflection.Assembly.GetExecutingAssembly());
            }
            else if (System.Globalization.CultureInfo.CurrentCulture.Parent.Name == "zh-CHT")
            {
                resourceManager = new System.Resources.ResourceManager("GeoSOS.CommonLibrary.Properties.Resource_zh_TW", System.Reflection.Assembly.GetExecutingAssembly());
            }
            else if (System.Globalization.CultureInfo.CurrentCulture.Parent.Name == "en")
            {
                resourceManager = new System.Resources.ResourceManager("GeoSOS.CommonLibrary.Properties.Resource_en", System.Reflection.Assembly.GetExecutingAssembly());
            }
            dtMatrix.Columns.Add(resourceManager.GetString("String16"));
            for (int i = 0; i < allTypesCount + 1; i++)
            {
                DataRow row = dtMatrix.NewRow();
                for (int j = 0; j < allTypesCount + 1; j++)
                {
                    row[j] = 0;
                }
                dtMatrix.Rows.Add(row);
            }
            //对真实数据的每个栅格统计其每个值,在模拟结果数据中是什么类型
            for (int i = 0; i < rowCount; i++)
            {
                for (int j = 0; j < columnCount; j++)
                {
                    int simulatedIndex = GetLandUseTypeIndex(simulatedData[i, j], landUseClassificationInfo);
                    int observedIndex  = GetLandUseTypeIndex(observedData[i, j], landUseClassificationInfo);
                    if ((simulatedIndex == -1) || (observedIndex == -1))
                    {
                        continue;
                    }
                    int oldValue = Convert.ToInt32(dtMatrix.Rows[observedIndex][simulatedIndex]);
                    dtMatrix.Rows[observedIndex][simulatedIndex] = oldValue + 1;
                }
            }
            //对每一行和列进行总值统计
            int sumRow    = 0;
            int sumColumn = 0;

            for (int i = 0; i < landUseClassificationInfo.AllTypesCount; i++)
            {
                sumRow = 0;
                for (int j = 0; j < landUseClassificationInfo.AllTypesCount; j++)
                {
                    sumRow += Convert.ToInt32(dtMatrix.Rows[i][j]);
                }
                dtMatrix.Rows[i][allTypesCount] = sumRow;
            }
            for (int i = 0; i < landUseClassificationInfo.AllTypesCount; i++)
            {
                sumColumn = 0;
                for (int j = 0; j < landUseClassificationInfo.AllTypesCount; j++)
                {
                    sumColumn += Convert.ToInt32(dtMatrix.Rows[j][i]);
                }
                dtMatrix.Rows[allTypesCount][i] = sumColumn;
            }
            //对最后一行和列的值进行总计
            int sum = 0;

            for (int i = 0; i < dtMatrix.Columns.Count; i++)
            {
                sum += Convert.ToInt32(dtMatrix.Rows[dtMatrix.Rows.Count - 1][i]);
            }
            dtMatrix.Rows[dtMatrix.Rows.Count - 1][dtMatrix.Columns.Count - 1] = sum;
            return(dtMatrix);
        }
Exemple #18
0
        public override void Run()
        {
            // 显示设置参数窗口
            var setUpForm = new AnnCaSetUpForm();

            setUpForm.ShowDialog();

            if (setUpForm.DialogResult != DialogResult.OK)
            {
            }
            else
            {
                // 获得参数
                string        beginLayerName  = setUpForm.beginLayerName;
                string        endLayerName    = setUpForm.endLayerName;
                List <string> driveLayerNames = setUpForm.driveLayerNames;

                int    numOfSample   = setUpForm.NumOfSample;
                int    numOfTrain    = setUpForm.NumOfTrain;
                int    numOfSimulate = setUpForm.NumOfSimulate;
                double threshold     = setUpForm.Threshold;
                double alpha         = setUpForm.Alpha;

                LandUseClassificationInfo landInfo = setUpForm.LandUse;

                // 显示控制台
                this.consolePad = WorkbenchSingleton.Workbench.GetPad(typeof(ConsolePad)).PadContent.Control as GIS.Common.Dialogs.Console.Console;

                WorkbenchSingleton.Workbench.GetPad(typeof(ConsolePad)).BringPadToFront();

                //string beginLayerName = "2001";
                //string endLayerName = "2006";
                //List<string> driveLayerNames = new List<string>() { "dem", "distocity", "distohighway", "distorailway", "distoroad", "distotown", "slope" };

                if (landInfo == null)
                {
                    landInfo          = new LandUseClassificationInfo();
                    landInfo.NullInfo = new StructLanduseInfo()
                    {
                        LandUseTypeColor = Color.White.ToArgb(), LandUseTypeName = "NULL", LandUseTypeValue = -3.40282306074e+038
                    };
                    landInfo.AllTypes = new List <StructLanduseInfo>()
                    {
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "城市", LandUseTypeValue = 1, LandUseTypeColor = Color.Black.ToArgb()
                        },
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "水", LandUseTypeValue = 2, LandUseTypeColor = Color.Blue.ToArgb()
                        },
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "田", LandUseTypeValue = 3, LandUseTypeColor = Color.Yellow.ToArgb()
                        },
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "森林", LandUseTypeValue = 4, LandUseTypeColor = Color.Green.ToArgb()
                        },
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "果园", LandUseTypeValue = 5, LandUseTypeColor = Color.LightPink.ToArgb()
                        }
                    };
                }



                // 设置网络
                var network = new AnnCa(beginLayerName, endLayerName, driveLayerNames, landInfo);
                network.NumOfSamples = numOfSample;
                network.TimesOfTrain = numOfTrain;
                network.Threshold    = threshold;
                network.Alpha        = alpha;


                network.updateConsoleEvent += this.UpdateConsole;
                network.updateImageEvent   += this.UpdateImage;

                // 设置图像显示
                this.imageForm = new ImageForm(network.BeginBuffer, network.Width, network.Height, landInfo);
                this.imageForm.Show();
                // 开始模拟
                Thread threadSimulate = new Thread(new ParameterizedThreadStart(network.Run));
                threadSimulate.IsBackground = true;
                threadSimulate.Start(numOfSimulate);
            }
        }
Exemple #19
0
        public void Run()
        {
            // 显示设置参数窗口
            var setUpForm = new AnnCaSetUpForm();

            setUpForm.ShowDialog();

            if (setUpForm.DialogResult != DialogResult.OK)
            {
            }
            else
            {
                // 获得参数
                string        beginLayerName  = setUpForm.beginLayerName;
                string        endLayerName    = setUpForm.endLayerName;
                List <string> driveLayerNames = setUpForm.driveLayerNames;

                int    numOfSample     = setUpForm.NumOfSample;
                int    numOfTrain      = setUpForm.NumOfTrain;
                int    numOfSimulate   = setUpForm.NumOfSimulate;
                int    sizeOfNeighbour = setUpForm.SizeOfNeighbour;
                double threshold       = setUpForm.Threshold;
                double alpha           = setUpForm.Alpha;

                LandUseClassificationInfo landInfo = setUpForm.LandUse;



                //string beginLayerName = "2001";
                //string endLayerName = "2006";
                //List<string> driveLayerNames = new List<string>() { "dem", "distocity", "distohighway", "distorailway", "distoroad", "distotown", "slope" };

                if (landInfo == null)
                {
                    landInfo          = new LandUseClassificationInfo();
                    landInfo.NullInfo = new StructLanduseInfo()
                    {
                        LandUseTypeColor = Color.White.ToArgb(), LandUseTypeName = "NULL", LandUseTypeValue = -3.40282306074e+038
                    };
                    landInfo.AllTypes = new List <StructLanduseInfo>()
                    {
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "城市", LandUseTypeValue = 1, LandUseTypeColor = Color.Black.ToArgb()
                        },
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "水", LandUseTypeValue = 2, LandUseTypeColor = Color.Blue.ToArgb()
                        },
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "田", LandUseTypeValue = 3, LandUseTypeColor = Color.Yellow.ToArgb()
                        },
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "森林", LandUseTypeValue = 4, LandUseTypeColor = Color.Green.ToArgb()
                        },
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "果园", LandUseTypeValue = 5, LandUseTypeColor = Color.LightPink.ToArgb()
                        }
                    };
                }



                // 设置网络
                this.network                   = new AnnCa(beginLayerName, endLayerName, driveLayerNames, landInfo);
                network.NumOfSamples           = numOfSample;
                network.TimesOfTrain           = numOfTrain;
                network.Threshold              = threshold;
                network.Alpha                  = alpha;
                network.SizeOfNeighbour        = sizeOfNeighbour;
                network.EndCityCnt             = setUpForm.EndCityCnt;
                network.TransformControlMatrix = setUpForm.TransformControlMatrix;
                network.updateConsoleEvent    += this.UpdateConsole;
                network.updateImageEvent      += this.UpdateImage;
                network.updateChartEvent      += this.UpdateChart;
                network.simulateEndEvent      += this.SimulateEnd;

                // 设置图像显示
                this.imageForm = new ImageForm(network.BeginBuffer, network.Width, network.Height, landInfo);

                this.imageForm.Show();
                //// 开始模拟

                Thread threadSimulate = new Thread(new ParameterizedThreadStart(network.Run));

                threadSimulate.IsBackground = true;
                threadSimulate.Start(numOfSimulate);

                this.imageForm.ThreadSimulate = threadSimulate;
                this.imageForm.ActiveButton();


                //Action<object> simulate = network.Run;
                //simulate.BeginInvoke(numOfSimulate, null, null);
            }
        }
Exemple #20
0
        public override void Run()
        {
            // 读取设置参数
            var form = new DTCaSetUpForm();

            form.ShowDialog();

            if (form.DialogResult != DialogResult.OK)
            {
            }
            else
            {
                var inputColumnNames = form.driveLayerNames;
                var outputColumnName = form.beginLayerName;
                LandUseClassificationInfo landUseInfo = form.LandUse;
                if (landUseInfo == null)
                {
                    landUseInfo          = new LandUseClassificationInfo();
                    landUseInfo.AllTypes = new List <StructLanduseInfo>()
                    {
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "城市", LandUseTypeValue = 1.0, LandUseTypeColor = Color.Black.ToArgb()
                        },
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "非城市", LandUseTypeValue = 0.0, LandUseTypeColor = Color.White.ToArgb()
                        },
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "水体", LandUseTypeValue = 2.0, LandUseTypeColor = Color.Blue.ToArgb()
                        },
                    };
                    landUseInfo.ConvertableInfos.Add(new StructLanduseInfo()
                    {
                        LandUseTypeName = "非城市", LandUseTypeValue = 0.0, LandUseTypeColor = Color.White.ToArgb()
                    });
                    landUseInfo.NullInfo = new StructLanduseInfo()
                    {
                        LandUseTypeName = "空值", LandUseTypeValue = -9999.0, LandUseTypeColor = Color.Transparent.ToArgb()
                    };
                    landUseInfo.UnConvertableInfos.Add(new StructLanduseInfo()
                    {
                        LandUseTypeName = "水体", LandUseTypeValue = 2.0, LandUseTypeColor = Color.Blue.ToArgb()
                    });
                    landUseInfo.UrbanInfos.Add(new StructLanduseInfo()
                    {
                        LandUseTypeName = "城市", LandUseTypeValue = 1.0, LandUseTypeColor = Color.Black.ToArgb()
                    });
                }

                // 初始化控制台
                this.consolePad = WorkbenchSingleton.Workbench.GetPad(typeof(ConsolePad)).PadContent.Control as GIS.Common.Dialogs.Console.Console;
                // 显示控制台
                WorkbenchSingleton.Workbench.GetPad(typeof(ConsolePad)).BringPadToFront();

                // 初始化树
                var tree = new CaDecisionTree(inputColumnNames, outputColumnName);
                tree.updateConsoleInfoEvent += UpdateConsole;
                tree.updateImageEvent       += UpdateImage;
                tree.LandUseInfo             = landUseInfo;
                tree.SampleRate              = form.RateOfSample;
                // 显示模拟图像
                this.imageForm        = new ImageForm(tree.OuputBuffer, tree.Width, tree.Height, landUseInfo);
                this.imageForm.Width  = tree.Width;
                this.imageForm.Height = tree.Height;
                imageForm.Show();
                // 开始训练模拟
                Thread threadSimulate = new Thread(new ParameterizedThreadStart(tree.Run));
                threadSimulate.IsBackground = true;
                threadSimulate.Start(form.NumOfSimulate);
            }
        }
        public void Run()
        {
            var form = new RandomForestSetUpForm();

            form.ShowDialog();
            if (form.DialogResult == DialogResult.OK)
            {
                //// 初始化控制台
                //this.consolePad = WorkbenchSingleton.Workbench.GetPad(typeof(ConsolePad)).PadContent.Control as GIS.Common.Dialogs.Console.Console;
                //// 显示控制台
                //WorkbenchSingleton.Workbench.GetPad(typeof(ConsolePad)).BringPadToFront();

                string        beginLayerName  = form.BeginLayerName;
                string        endLayerName    = form.EndLayerName;
                List <string> driveLayerNames = form.DriveLayerNames;

                LandUseClassificationInfo landInfo = form.LandUse;
                if (landInfo == null)
                {
                    landInfo          = new LandUseClassificationInfo();
                    landInfo.NullInfo = new StructLanduseInfo()
                    {
                        LandUseTypeColor = Color.White.ToArgb(), LandUseTypeName = "NULL", LandUseTypeValue = -3.40282306074e+038
                    };
                    landInfo.AllTypes = new List <StructLanduseInfo>()
                    {
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "城市", LandUseTypeValue = 1, LandUseTypeColor = Color.Black.ToArgb()
                        },
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "水体", LandUseTypeValue = 2, LandUseTypeColor = Color.Blue.ToArgb()
                        },
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "田", LandUseTypeValue = 3, LandUseTypeColor = Color.Yellow.ToArgb()
                        },
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "森林", LandUseTypeValue = 4, LandUseTypeColor = Color.Green.ToArgb()
                        },
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "果园", LandUseTypeValue = 5, LandUseTypeColor = Color.LightPink.ToArgb()
                        }
                    };
                    landInfo.UrbanInfos.Add(new StructLanduseInfo()
                    {
                        LandUseTypeName = "城市", LandUseTypeValue = 1, LandUseTypeColor = Color.Black.ToArgb()
                    });
                }

                var randomForestCa = new RandomForestCa(beginLayerName, endLayerName, driveLayerNames, landInfo);
                randomForestCa.updateConsoleEvent += this.UpdateConsole;
                randomForestCa.updateImageEvent   += this.UpdateImage;
                randomForestCa.simulateEndEvent   += this.SimulateEnd;
                randomForestCa.updateChartEvent   += this.UpdateChart;
                randomForestCa.NumOfSample         = form.NumOfSample;
                randomForestCa.NumOfTree           = form.NumOfTree;
                randomForestCa.SampleRatio         = form.SampleRatio;
                randomForestCa.CoverageRatio       = form.CoverageRatio;
                randomForestCa.SizeOfNeighbour     = form.SizeOfNeighbour;
                randomForestCa.isNeedSignificant   = form.IsNeedSignificant;
                randomForestCa.alpha                  = form.RandomFactor;
                randomForestCa.cityPropAdjust         = form.cityPropAdjust;
                randomForestCa.transformControlMatrix = form.TransformControlMatrix;
                randomForestCa.targetCityCnt          = form.TargetCityCnt;
                this.imageForm = new ImageForm(randomForestCa.BeginBuffer, randomForestCa.Width, randomForestCa.Height, randomForestCa.LandInfo);
                this.imageForm.Show();


                //Action<object> simulate = randomForestCa.Run;
                //simulate.BeginInvoke(form.NumOfSimulate, null, null);


                Thread threadSimulate = new Thread(new ParameterizedThreadStart(randomForestCa.Run));
                threadSimulate.IsBackground = true;
                threadSimulate.Start(form.NumOfSimulate);
                this.imageForm.ThreadSimulate = threadSimulate;
                this.imageForm.ActiveButton();
            }
            else
            {
                MessageBox.Show("参数设置错误!");
            }
        }
        public void Run()
        {
            // 读取设置参数
            var form = new DTCaSetUpForm();

            form.ShowDialog();

            if (form.DialogResult != DialogResult.OK)
            {
                // 错误终止
                return;
            }
            else
            {
                LandUseClassificationInfo landUseInfo = form.LandUse;
                // 默认的土地利用信息
                if (landUseInfo == null)
                {
                    landUseInfo          = new LandUseClassificationInfo();
                    landUseInfo.AllTypes = new List <StructLanduseInfo>()
                    {
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "城市", LandUseTypeValue = 1.0, LandUseTypeColor = Color.Black.ToArgb()
                        },
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "非城市", LandUseTypeValue = 0.0, LandUseTypeColor = Color.White.ToArgb()
                        },
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "水体", LandUseTypeValue = 2.0, LandUseTypeColor = Color.Blue.ToArgb()
                        },
                    };
                    landUseInfo.ConvertableInfos.Add(new StructLanduseInfo()
                    {
                        LandUseTypeName = "非城市", LandUseTypeValue = 0.0, LandUseTypeColor = Color.White.ToArgb()
                    });
                    landUseInfo.NullInfo = new StructLanduseInfo()
                    {
                        LandUseTypeName = "空值", LandUseTypeValue = -9999.0, LandUseTypeColor = Color.Transparent.ToArgb()
                    };
                    landUseInfo.UnConvertableInfos.Add(new StructLanduseInfo()
                    {
                        LandUseTypeName = "水体", LandUseTypeValue = 2.0, LandUseTypeColor = Color.Blue.ToArgb()
                    });
                    landUseInfo.UrbanInfos.Add(new StructLanduseInfo()
                    {
                        LandUseTypeName = "城市", LandUseTypeValue = 1.0, LandUseTypeColor = Color.Black.ToArgb()
                    });
                }

                // 初始化控制台

                // 初始化树
                var tree = new DecisionTreeCa(form.driveLayerNames, form.beginLayerName, form.endLayerName);

                // 注册事件
                tree.updateConsoleEvent += UpdateConsole;
                tree.updateImageEvent   += UpdateImage;
                tree.simulateEndEvent   += SimulateEnd;
                tree.updateChartEvent   += UpdateChart;
                // 设置参数
                tree.LandInfo   = landUseInfo;
                tree.SampleRate = form.RateOfSample;
                tree.EndCityCnt = form.EndCityCnt;
                // 显示模拟图像
                this.imageForm        = new ImageForm(tree.BeginBuffer, tree.Width, tree.Height, landUseInfo);
                this.imageForm.Width  = tree.Width;
                this.imageForm.Height = tree.Height;
                imageForm.Show();

                //// 线程池
                //Action<object> simulate = tree.Run;
                //simulate.BeginInvoke(form.NumOfSimulate, null, null);

                Thread threadSimulate = new Thread(new ParameterizedThreadStart(tree.Run));
                threadSimulate.IsBackground = true;
                threadSimulate.Start(form.NumOfSimulate);

                this.imageForm.ThreadSimulate = threadSimulate;
                this.imageForm.ActiveButton();
            }
        }
Exemple #23
0
        public override void Run()
        {
            var form = new AhpCaSetUpForm();

            form.ShowDialog();

            if (form.DialogResult != DialogResult.OK)
            {
            }
            else
            {
                // 初始化控制台
                this.consolePad = WorkbenchSingleton.Workbench.GetPad(typeof(ConsolePad)).PadContent.Control as GIS.Common.Dialogs.Console.Console;
                // 显示控制台
                WorkbenchSingleton.Workbench.GetPad(typeof(ConsolePad)).BringPadToFront();

                string        beginLayerName  = form.BeginLayerName; //"city2001_012"
                string        endLayerName    = form.EndLayerName;   //"city2006_012";
                List <string> driveLayerNames = form.DriveLayerNames;

                //= new List<string>()
                //{
                //    "distocity",
                //    "distohighway",
                //    "distorailway",
                //    "distoroad",
                //    "distotown"
                //};
                LandUseClassificationInfo landUseInfo = form.LandUseInfo;
                if (landUseInfo == null)
                {
                    landUseInfo          = new LandUseClassificationInfo();
                    landUseInfo.AllTypes = new List <StructLanduseInfo>()
                    {
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "城市", LandUseTypeValue = 1.0, LandUseTypeColor = Color.Black.ToArgb()
                        },
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "非城市", LandUseTypeValue = 0.0, LandUseTypeColor = Color.White.ToArgb()
                        },
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "水体", LandUseTypeValue = 2.0, LandUseTypeColor = Color.Blue.ToArgb()
                        },
                    };
                    landUseInfo.ConvertableInfos.Add(new StructLanduseInfo()
                    {
                        LandUseTypeName = "非城市", LandUseTypeValue = 0.0, LandUseTypeColor = Color.White.ToArgb()
                    });
                    landUseInfo.NullInfo = new StructLanduseInfo()
                    {
                        LandUseTypeName = "空值", LandUseTypeValue = -9999.0, LandUseTypeColor = Color.Transparent.ToArgb()
                    };
                    landUseInfo.UnConvertableInfos.Add(new StructLanduseInfo()
                    {
                        LandUseTypeName = "水体", LandUseTypeValue = 2.0, LandUseTypeColor = Color.Blue.ToArgb()
                    });
                    landUseInfo.UrbanInfos.Add(new StructLanduseInfo()
                    {
                        LandUseTypeName = "城市", LandUseTypeValue = 1.0, LandUseTypeColor = Color.Black.ToArgb()
                    });
                }

                float[] weights = form.Weights;
                if (weights == null)
                {
                    weights = new float[] { 0.35f, 0.13f, 0.13f, 0.13f, 0.25f };
                }
                int    sizeOfNeighbour = form.SizeOfNeighbour; //3;
                double globalFactor    = form.GlobalFactor;    //0.5;
                double localFactor     = form.LocalFactor;     //0.5;
                double alpha           = form.Alpha;           //1;
                int    countOfCity     = form.CountOfCity;     //200;

                var mce = new AhpCa(beginLayerName, endLayerName, driveLayerNames);
                mce.LandUseInfo         = landUseInfo;
                mce.Weights             = weights;
                mce.SizeOfNeighbour     = sizeOfNeighbour;
                mce.GlobalFactor        = globalFactor;
                mce.LocalFactor         = localFactor;
                mce.Alpha               = alpha;
                mce.CountOfCity         = countOfCity;
                mce.updateConsoleEvent += UpdateConsole;
                mce.updateImageEvent   += UpdateImage;

                this.imageForm = new ImageForm(mce.BeginBuffer, mce.Width, mce.Height, landUseInfo);
                this.imageForm.Show();

                Thread threadSimulate = new Thread(new ThreadStart(mce.simulate));
                threadSimulate.IsBackground = true;
                threadSimulate.Start();
            }
        }
Exemple #24
0
        /// <summary>
        /// 进行基于ANN的数据抽样。
        /// </summary>
        /// <param name="listSpatialVariables"></param>
        /// <param name="trainningStartImage"></param>
        /// <param name="trainningEndImage"></param>
        /// <param name="landuseClassificationInfo"></param>
        /// <param name="structRasterMetaData"></param>
        /// <param name="neiWindowSize"></param>
        /// <param name="listNotNullRows"></param>
        /// <param name="listNotNullColumns"></param>
        /// <param name="inputs"></param>
        /// <param name="outputs"></param>
        /// <param name="samplingCellsCount"></param>
        /// <param name="inputNeuronsCount"></param>
        /// <param name="outputNeuronsCount"></param>
        public void ANNSamplingData(List <float[, ]> listSpatialVariables, float[,] trainningStartImage, float[,] trainningEndImage,
                                    LandUseClassificationInfo landuseClassificationInfo, StructRasterMetaData structRasterMetaData, int neiWindowSize,
                                    List <int> listNotNullRows, List <int> listNotNullColumns, ref float[][] inputs, ref float[][] outputs,
                                    int samplingCellsCount, int inputNeuronsCount, int outputNeuronsCount)
        {
            float[]    tempInputsArray  = null;
            float[]    tempOutputsArray = null;
            List <int> listChoosen      = new List <int>();

            for (int z = 0; z < listNotNullRows.Count; z++)
            {
                listChoosen.Add(0);
            }
            int index, rowIndex, columnIndex;

            //在抽样时,目前是随机采样。可以考虑分层抽样,即发生变化的元胞取一半,未变化的取一半。
            try
            {
                for (int s = 0; s < samplingCellsCount; s++)
                {
                    index = random.Next(0, listNotNullRows.Count);
                    if (listChoosen[index] == 1)
                    {
                        s--;
                        continue;
                    }
                    rowIndex    = listNotNullRows[index];
                    columnIndex = listNotNullColumns[index];
                    if ((rowIndex >= structRasterMetaData.RowCount) || (columnIndex >= structRasterMetaData.ColumnCount))
                    {
                        s--;
                        continue;
                    }
                    if ((trainningStartImage[rowIndex, columnIndex] == -9999f) || (trainningEndImage[rowIndex, columnIndex] == -9999f))
                    {
                        s--;
                        continue;
                    }
                    tempInputsArray  = new float[inputNeuronsCount];
                    tempOutputsArray = new float[outputNeuronsCount];
                    //1.输入的列
                    //1.1先去各个空间变量获取
                    bool isNull = false;
                    for (int i = 0; i < listSpatialVariables.Count; i++)
                    {
                        tempInputsArray[i] = listSpatialVariables[i][rowIndex, columnIndex];
                        if (tempInputsArray[i] == -9999f)
                        {
                            isNull = true;
                            break;
                        }
                    }
                    if (isNull)
                    {
                        s--;
                        continue;
                    }
                    //1.2再去获取邻域信息
                    NeighbourOperator neighbourOperator = new NeighbourOperator();
                    List <float>      listLanduseValues = new List <float>();
                    for (int j = 0; j < landuseClassificationInfo.AllTypesCount; j++)
                    {
                        listLanduseValues.Add(landuseClassificationInfo.AllTypes[j].LanduseTypeValue);
                    }
                    float[] counts = neighbourOperator.GetNeighbourCount(trainningStartImage, rowIndex, columnIndex, neiWindowSize,
                                                                         structRasterMetaData.RowCount, structRasterMetaData.ColumnCount, landuseClassificationInfo.AllTypesCount, listLanduseValues);
                    for (int z = 0; z < counts.Length; z++)
                    {
                        tempInputsArray[listSpatialVariables.Count + z] = counts[z] / (neiWindowSize * neiWindowSize - 1);
                    }
                    //1.3最后获取土地利用类型
                    tempInputsArray[inputNeuronsCount - 1] = trainningStartImage[rowIndex, columnIndex];
                    inputs[s] = tempInputsArray;
                    //2.输出的列。是根据当前元胞在终止土地利用数据中是哪种土地利用类型值,从而形成0,1序列。0代表这种土地利用类型转换的概率为0。
                    for (int k = 0; k < landuseClassificationInfo.AllTypesCount; k++)
                    {
                        if (trainningEndImage[rowIndex, columnIndex] == landuseClassificationInfo.AllTypes[k].LanduseTypeValue)
                        {
                            tempOutputsArray[k] = 1.0f;
                            break;
                        }
                    }
                    outputs[s] = tempOutputsArray;

                    listChoosen[index] = 1;
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("ANNSamplingData: " + ex.Message);
            }
            ////输出抽样结果数据
            //GeneralOpertor.WriteDataFloat(@"C:\DanLi\Download\annSamplingData.txt", inputs, outputs, samplingCellsCount,
            //    inputNeuronsCount, outputNeuronsCount);
        }
Exemple #25
0
        public void Run()
        {
            var form = new LgCaSetUpForm();

            form.ShowDialog();

            if (form.DialogResult != DialogResult.OK)
            {
                return;
            }
            else
            {
                string                    beginLayerName  = form.BeginLayerName; //"city2001_012"
                string                    endLayerName    = form.EndLayerName;   //"city2006_012";
                List <string>             driveLayerNames = form.DriveLayerNames;
                LandUseClassificationInfo landUseInfo     = form.LandUseInfo;
                // 默认土地利用信息
                if (landUseInfo == null)
                {
                    landUseInfo          = new LandUseClassificationInfo();
                    landUseInfo.AllTypes = new List <StructLanduseInfo>()
                    {
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "城市", LandUseTypeValue = 1.0, LandUseTypeColor = Color.Black.ToArgb()
                        },
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "非城市", LandUseTypeValue = 0.0, LandUseTypeColor = Color.White.ToArgb()
                        },
                        new StructLanduseInfo()
                        {
                            LandUseTypeName = "水体", LandUseTypeValue = 2.0, LandUseTypeColor = Color.Blue.ToArgb()
                        },
                    };
                    landUseInfo.ConvertableInfos.Add(new StructLanduseInfo()
                    {
                        LandUseTypeName = "非城市", LandUseTypeValue = 0.0, LandUseTypeColor = Color.White.ToArgb()
                    });
                    landUseInfo.NullInfo = new StructLanduseInfo()
                    {
                        LandUseTypeName = "空值", LandUseTypeValue = -9999.0, LandUseTypeColor = Color.Transparent.ToArgb()
                    };
                    landUseInfo.UnConvertableInfos.Add(new StructLanduseInfo()
                    {
                        LandUseTypeName = "水体", LandUseTypeValue = 2.0, LandUseTypeColor = Color.Blue.ToArgb()
                    });
                    landUseInfo.UrbanInfos.Add(new StructLanduseInfo()
                    {
                        LandUseTypeName = "城市", LandUseTypeValue = 1.0, LandUseTypeColor = Color.Black.ToArgb()
                    });
                }

                // 从设置界面获得参数
                int    sizeOfNeighbour = form.SizeOfNeighbour; //3;
                double alpha           = form.Alpha;           //1;
                int    timeOfSimulate  = form.TimeOfSimulate;  //200;
                double threshold       = form.Threshold;
                int    numOfSample     = form.NumOfSample;
                var    ca = new LgCa(beginLayerName, endLayerName, driveLayerNames);
                ca.LandInfo            = landUseInfo;
                ca.Threshold           = threshold;
                ca.TimeOfSimulate      = timeOfSimulate;
                ca.SizeOfNeighbour     = sizeOfNeighbour;
                ca.NumOfSample         = numOfSample;
                ca.Alpha               = alpha;
                ca.EndCityCnt          = form.EndCityCnt;
                ca.updateConsoleEvent += this.UpdateConsole;
                ca.updateImageEvent   += this.UpdateImage;
                ca.simulateEndEvent   += this.SimulateEnd;
                ca.updateChartEvent   += this.UpdateChart;
                // 显示图像
                this.imageForm = new ImageForm(ca.BeginBuffer, ca.Width, ca.Height, landUseInfo);
                this.imageForm.Show();
                //Action simulate = ca.Simulate;
                //simulate.BeginInvoke(null, null);
                Thread threadSimulate = new Thread(new ThreadStart(ca.Simulate));
                threadSimulate.IsBackground = true;
                threadSimulate.Start();

                this.imageForm.ThreadSimulate = threadSimulate;
                this.imageForm.ActiveButton();
            }
        }
Exemple #26
0
 public TransformControlForm(LandUseClassificationInfo landUseInfo)
 {
     this.LandUseInfo = landUseInfo;
     InitializeComponent();
     InitializeMatrix();
 }
Exemple #27
0
        /// <summary>
        /// 根据模拟的结果和要进行对比的影像得到相关混淆矩阵信息。
        /// </summary>
        /// <param name="simulatedData"></param>
        /// <param name="observedData"></param>
        /// <param name="rowCount"></param>
        /// <param name="columnCount"></param>
        /// <returns></returns>
        public static StructBinaryConfusionMatrix GetBinaryAccuracy(float[,] simulatedData, float[,] observedData, int rowCount, int columnCount, LandUseClassificationInfo landUseClassificationInfo)
        {
            StructBinaryConfusionMatrix structConfusionMatrix = new StructBinaryConfusionMatrix();

            for (int i = 0; i < rowCount; i++)
            {
                for (int j = 0; j < columnCount; j++)
                {
                    //如果真实数据为城市用地。
                    if (landUseClassificationInfo.IsExistInUrbanValue(observedData[i, j]))
                    {
                        //如果模拟为城市用地
                        if (landUseClassificationInfo.IsExistInUrbanValue(simulatedData[i, j]))
                        {
                            structConfusionMatrix.Urban2UrbanCount += 1;
                        }
                        //如果模拟为非城市用地
                        else if (landUseClassificationInfo.NullValue.LanduseTypeValue != simulatedData[i, j])
                        {
                            structConfusionMatrix.Urban2NotUrbanCount += 1;
                        }
                    }
                    //如果真实数据为非城市用地。空值不进行统计。
                    else if (landUseClassificationInfo.NullValue.LanduseTypeValue != observedData[i, j])
                    {
                        //如果模拟为城市用地
                        if (landUseClassificationInfo.IsExistInUrbanValue(simulatedData[i, j]))
                        {
                            structConfusionMatrix.NotUrban2UrbanCount += 1;
                        }
                        //如果模拟为非城市用地
                        else if (landUseClassificationInfo.NullValue.LanduseTypeValue != simulatedData[i, j])
                        {
                            structConfusionMatrix.NotUrban2NotUrbanCount += 1;
                        }
                    }
                }
            }

            structConfusionMatrix.OverallObseredDataNotUrbanCount   = structConfusionMatrix.NotUrban2NotUrbanCount + structConfusionMatrix.NotUrban2UrbanCount;
            structConfusionMatrix.OverallObseredDataUrbanCount      = structConfusionMatrix.Urban2NotUrbanCount + structConfusionMatrix.Urban2UrbanCount;
            structConfusionMatrix.OverallSimulatedDataNotUrbanCount = structConfusionMatrix.Urban2NotUrbanCount + structConfusionMatrix.NotUrban2NotUrbanCount;
            structConfusionMatrix.OverallSimulatedDataUrbanCount    = structConfusionMatrix.Urban2UrbanCount + structConfusionMatrix.NotUrban2UrbanCount;

            structConfusionMatrix.NotUrbanCorrectPrecent = Convert.ToDouble(structConfusionMatrix.NotUrban2NotUrbanCount) /
                                                           (structConfusionMatrix.NotUrban2NotUrbanCount + structConfusionMatrix.NotUrban2UrbanCount);
            structConfusionMatrix.UrabanCorrectPrecent = Convert.ToDouble(structConfusionMatrix.Urban2UrbanCount) /
                                                         (structConfusionMatrix.Urban2UrbanCount + structConfusionMatrix.Urban2NotUrbanCount);
            structConfusionMatrix.OverallCorrectPrecent = Convert.ToDouble((structConfusionMatrix.Urban2UrbanCount +
                                                                            structConfusionMatrix.NotUrban2NotUrbanCount)) / (structConfusionMatrix.NotUrban2NotUrbanCount
                                                                                                                              + structConfusionMatrix.NotUrban2UrbanCount + structConfusionMatrix.Urban2UrbanCount
                                                                                                                              + structConfusionMatrix.Urban2NotUrbanCount);

            return(structConfusionMatrix);
        }
Exemple #28
0
 public static float[,] GetMooreNeighborInfo(float[,] landuseImage, int rowCount, int columnCount, int windowSize,
                                             LandUseClassificationInfo landUseClassificationInfo)
 {
     float[,] neighbor = new float[rowCount, columnCount];
     for (int x = 0; x < rowCount; x++)
     {
         for (int y = 0; y < columnCount; y++)
         {
             int   count        = 0;
             float landuseValue = -1;
             {
                 if ((x - windowSize) > 0 && (y - windowSize) > 0)
                 {
                     landuseValue = landuseImage[x - windowSize, y - windowSize];
                     for (int i = 0; i < landUseClassificationInfo.UrbanValues.Count; i++)
                     {
                         if (landUseClassificationInfo.UrbanValues[i].LanduseTypeValue == landuseValue)
                         {
                             count++;
                         }
                     }
                 }
                 if ((y - windowSize) > 0)
                 {
                     landuseValue = landuseImage[x, y - windowSize];
                     for (int i = 0; i < landUseClassificationInfo.UrbanValues.Count; i++)
                     {
                         if (landUseClassificationInfo.UrbanValues[i].LanduseTypeValue == landuseValue)
                         {
                             count++;
                         }
                     }
                 }
                 if ((x + windowSize) < rowCount && (y - windowSize) > 0)
                 {
                     landuseValue = landuseImage[x + windowSize, y - windowSize];
                     for (int i = 0; i < landUseClassificationInfo.UrbanValues.Count; i++)
                     {
                         if (landUseClassificationInfo.UrbanValues[i].LanduseTypeValue == landuseValue)
                         {
                             count++;
                         }
                     }
                 }
                 if ((x - windowSize) > 0)
                 {
                     landuseValue = landuseImage[x - windowSize, y];
                     for (int i = 0; i < landUseClassificationInfo.UrbanValues.Count; i++)
                     {
                         if (landUseClassificationInfo.UrbanValues[i].LanduseTypeValue == landuseValue)
                         {
                             count++;
                         }
                     }
                 }
                 if ((x + windowSize) < rowCount)
                 {
                     landuseValue = landuseImage[x + windowSize, y];
                     for (int i = 0; i < landUseClassificationInfo.UrbanValues.Count; i++)
                     {
                         if (landUseClassificationInfo.UrbanValues[i].LanduseTypeValue == landuseValue)
                         {
                             count++;
                         }
                     }
                 }
                 if ((x - windowSize) > 0 && (y + windowSize) < columnCount)
                 {
                     landuseValue = landuseImage[x - windowSize, y + windowSize];
                     for (int i = 0; i < landUseClassificationInfo.UrbanValues.Count; i++)
                     {
                         if (landUseClassificationInfo.UrbanValues[i].LanduseTypeValue == landuseValue)
                         {
                             count++;
                         }
                     }
                 }
                 if ((y + windowSize) < columnCount)
                 {
                     landuseValue = landuseImage[x, y + windowSize];
                     for (int i = 0; i < landUseClassificationInfo.UrbanValues.Count; i++)
                     {
                         if (landUseClassificationInfo.UrbanValues[i].LanduseTypeValue == landuseValue)
                         {
                             count++;
                         }
                     }
                 }
                 if ((x + windowSize) < rowCount && (y + windowSize) < columnCount)
                 {
                     landuseValue = landuseImage[x + windowSize, y + windowSize];
                     for (int i = 0; i < landUseClassificationInfo.UrbanValues.Count; i++)
                     {
                         if (landUseClassificationInfo.UrbanValues[i].LanduseTypeValue == landuseValue)
                         {
                             count++;
                         }
                     }
                 }
             }
             neighbor[x, y] = count;
         }
     }
     return(neighbor);
 }
        /// <summary>
        /// 当向导页要切换到下一页前可以做的该页检查工作,决定是否可以切换到下一页。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void wizardLogistcCA_BeforeSwitchPages(object sender, CristiPotlog.Controls.Wizard.BeforeSwitchPagesEventArgs e)
        {
            //从介绍页切换前,如果使用默认,则直接切换到摘要页
            if (e.OldIndex == 1 && e.NewIndex == 2)
            {
                if (isUsingDefault)
                {
                    e.NewIndex         = 8;
                    textBoxSummay.Text = WriteSummay();
                }
            }
            //训练数据设置页切换前的检查
            else if (e.OldIndex == 2 && e.NewIndex == 3)
            {
                StringBuilder sb = new StringBuilder();
                if (comboBoxTrainingStartImage.SelectedIndex == -1)
                {
                    sb.AppendLine(resourceManager.GetString("String3"));
                    sb.AppendLine();
                    e.Cancel = true;
                }
                if (comboBoxTrainingEndImage.SelectedIndex == -1)
                {
                    sb.AppendLine(resourceManager.GetString("String4"));
                    sb.AppendLine();
                    e.Cancel = true;
                }
                if (this.dataGridViewVariableDatas.Rows.Count == 0)
                {
                    sb.AppendLine(resourceManager.GetString("String5"));
                    e.Cancel = true;
                }
                else
                {
                    //还需要判断每行里是否有空值
                    if (dataGridViewVariableDatas.Rows[0].Cells[0].Value == null)
                    {
                        sb.AppendLine(resourceManager.GetString("String5"));
                        e.Cancel = true;
                    }
                }
                if (sb.Length > 0)
                {
                    MessageBox.Show(sb.ToString(), resourceManager.GetString("String2"), MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
            //土地利用类型设置页切换前的检查
            else if (e.OldIndex == 3 && e.NewIndex == 4)
            {
                for (int i = 0; i < dataGridViewLandUse.Rows.Count; i++)
                {
                    if (dataGridViewLandUse.Rows[i].Cells[2].Value == null)
                    {
                        MessageBox.Show(resourceManager.GetString("String10"),
                                        resourceManager.GetString("String2"), MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        e.Cancel = true;
                        break;
                    }
                }
            }
            //模拟数据设置页可以继续的条件
            else if (e.OldIndex == 6 && e.NewIndex == 7)
            {
                StringBuilder sb = new StringBuilder();
                if (this.comboBoxSimStartImage.Text == "")
                {
                    sb.AppendLine(resourceManager.GetString("String16"));
                    sb.AppendLine();
                    e.Cancel = true;
                }
                if (sb.Length > 0)
                {
                    MessageBox.Show(sb.ToString(), resourceManager.GetString("String2"), MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
            //如果欢迎页选择使用默认
            else if (e.OldIndex == 0)
            {
                isUsingDefault = checkBoxUseDefault.Checked;
                if (isUsingDefault)
                {
                    if (!application.Caption.Contains("LandUseChange_DongGuan"))
                    {
                        MessageBox.Show(resourceManager.GetString("String17"), resourceManager.GetString("String2"), MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        e.Cancel = true;
                    }
                    else
                    {
                        //如果不是第一次打开窗体,则再次读取地图数据
                        application             = ArcMap.Application;
                        document                = application.Document as IMxDocument;
                        map                     = document.FocusMap;
                        ArcGISOperator.FoucsMap = document.FocusMap;
                        //如果图层选择框为空
                        if (comboBoxTrainingStartImage.Items.Count == 0)
                        {
                            for (int i = 0; i < map.LayerCount; i++)
                            {
                                string layerName = map.get_Layer(i).Name;
                                comboBoxTrainingStartImage.Items.Add(layerName);
                                comboBoxTrainingEndImage.Items.Add(layerName);
                                comboBoxSimStartImage.Items.Add(layerName);
                                comboBoxSimEndImage.Items.Add(layerName);
                            }
                        }
                        for (int i = 0; i < comboBoxTrainingStartImage.Items.Count; i++)
                        {
                            if (comboBoxTrainingStartImage.Items[i].ToString() == "landuse2000")
                            {
                                comboBoxTrainingStartImage.SelectedIndex = i;
                                break;
                            }
                        }
                        for (int i = 0; i < comboBoxTrainingEndImage.Items.Count; i++)
                        {
                            if (comboBoxTrainingEndImage.Items[i].ToString() == "landuse2005")
                            {
                                comboBoxTrainingEndImage.SelectedIndex = i;
                                break;
                            }
                        }
                        for (int i = 0; i < comboBoxSimStartImage.Items.Count; i++)
                        {
                            if (comboBoxSimStartImage.Items[i].ToString() == "landuse2005")
                            {
                                comboBoxSimStartImage.SelectedIndex = i;
                                break;
                            }
                        }
                        for (int i = 0; i < comboBoxSimEndImage.Items.Count; i++)
                        {
                            if (comboBoxSimEndImage.Items[i].ToString() == "landuse2006")
                            {
                                comboBoxSimEndImage.SelectedIndex = i;
                                break;
                            }
                        }
                        //使用默认配置时未读取变量数据,需要在模拟前读取
                        listVariableLayersName.Clear();
                        listVariableLayersName.Add("dtroad");
                        listVariableLayersName.Add("dtrailway");
                        listVariableLayersName.Add("dtfreeway");
                        listVariableLayersName.Add("dtcity");

                        System.IO.StreamReader streamReader = new System.IO.StreamReader(GetMxdDocumentFolder() + @"\Config Files\DefaultLanduseInfo.xml");
                        System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(LandUseClassificationInfo));
                        landUseClassificationInfo = (LandUseClassificationInfo)xmlSerializer.Deserialize(streamReader);
                        streamReader.Close();

                        coef    = new double[5];
                        coef[0] = 0.061f;
                        coef[1] = 0.662f;
                        coef[2] = -1.329f;
                        coef[3] = -1.107f;
                        coef[4] = 1.729f;

                        outputFolder         = GetOutputFolder();
                        convertCount         = 19260;
                        simulationIterations = 100;
                        refreshInterval      = 10;
                        outputImageInterval  = 10;
                        delta = 3;
                        numericUpDownConvertCount.Value = 19260;
                        numericUpDownIterations.Value   = 100;
                        numericUpDownDelta.Value        = 3;
                        numericUpDownRefresh.Value      = 10;
                        numericUpDownOutputImage.Value  = 10;
                        isOutput = false;
                    }
                }
            }
            //如果欢迎页选择使用默认,则“上一步”直接回到介绍页。
            else if (e.NewIndex == 7 && e.OldIndex == 8)
            {
                if (isUsingDefault)
                {
                    e.NewIndex = 1;
                }
            }
        }
Exemple #30
0
        /// <summary>
        /// 获得多类模拟结果的精度和Kappa系数。
        /// </summary>
        /// <param name="dtMatrix"></param>
        /// <param name="overallAccuracy"></param>
        /// <param name="kappa"></param>
        /// <param name="landUseClassificationInfo"></param>
        public static void GetMultiTypesAccuracy(DataTable dtMatrix, ref double overallAccuracy, ref double kappa, LandUseClassificationInfo landUseClassificationInfo)
        {
            int    allTypesCount = landUseClassificationInfo.AllTypesCount;
            double sumNiiN       = 0;
            double sumNii        = 0;
            double n             = 0;

            for (int i = 0; i < allTypesCount; i++)
            {
                sumNiiN += Convert.ToDouble(dtMatrix.Rows[i][allTypesCount]) * Convert.ToDouble(dtMatrix.Rows[allTypesCount][i]);
            }
            for (int i = 0; i < allTypesCount; i++)
            {
                sumNii += Convert.ToDouble(dtMatrix.Rows[i][i]);
            }
            for (int i = 0; i < allTypesCount; i++)
            {
                n += Convert.ToDouble(dtMatrix.Rows[i][allTypesCount]);
            }
            overallAccuracy = sumNii / n;
            kappa           = (n * sumNii - sumNiiN) / (n * n - sumNiiN);
        }