コード例 #1
0
        private void layerpath_SelectedIndexChanged(object sender, EventArgs e)
        {
            double       Tmpincrement;
            IRasterLayer pLayer;
            int          selindex = -1;

            for (int i = 0; i < mainfrm.mainMap.LayerCount; i++)
            {
                if (mainfrm.mainMap.get_Layer(i).Name == layerpath.Text)
                {
                    selindex = i;
                }
            }
            if (selindex == -1)
            {
                return;
            }
            pLayer = (IRasterLayer)mainfrm.mainMap.get_Layer(selindex);

            try
            {
                pRster = pLayer.Raster;
                IRasterBandCollection pRasterBandCol;
                pRasterBandCol = (IRasterBandCollection)pRster;

                IRasterBand pRasterBand;
                pRasterBand = pRasterBandCol.Item(0);
                pRasterBand.ComputeStatsAndHist();
                IRasterStatistics pRasterStatistic;
                pRasterStatistic = pRasterBand.Statistics;
                maxValue         = (float)pRasterStatistic.Maximum;
                minValue         = (float)pRasterStatistic.Minimum;

                //先求每个等分间距
                DataRow FilterRow;
                Tmpincrement = (maxValue - minValue) / Convert.ToInt16(CmbLineCount.Text);
                FilterDataTable.Rows.Clear();
                for (int i = 1; i <= Convert.ToInt16(CmbLineCount.Text); i++)
                {
                    FilterRow    = FilterDataTable.NewRow();
                    FilterRow[0] = Convert.ToString(minValue + Tmpincrement * (i - 1)) + "-" + Convert.ToString(minValue + Tmpincrement * i);
                    FilterRow[1] = i;
                    FilterDataTable.Rows.Add(FilterRow);
                }
                DataGridFilterData.DataSource = FilterDataTable;
                DataGridFilterData.Refresh();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }
コード例 #2
0
        private void Reclassfy_Load(object sender, EventArgs e)
        {
            List <string> layerpathList = new List <string>();

            layerpathList = GetLayerPath();
            if (layerpathList == null)
            {
                return;
            }
            foreach (string item in layerpathList)
            {
                layerpath.Items.Add(item);
                //selectcomboBox.Items.Add(item);
            }
            DataRow    FilterRow;
            DataColumn ContourLineOldValue = new DataColumn("旧值", System.Type.GetType("System.String"));
            DataColumn ContourLineNewValue = new DataColumn("新值", System.Type.GetType("System.Int32"));



            try
            {
                FilterDataTable.Columns.Add(ContourLineOldValue);
                FilterDataTable.Columns.Add(ContourLineNewValue);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            DataGridFilterData.DataSource = FilterDataTable;
            DataGridFilterData.Refresh();
            FilterDataTable.Rows.Clear();
            for (int i = 0; i < FilterDataTable.Rows.Count; i++)
            {
                FilterDataTable.Rows[i].Delete();// 'RemoveAt(i)
            }
            CmbLineCount.Text = "5";
            FilterDataTable.Rows.Clear();

            //ComboBoxInLayer.Items.Clear();
            //for (int i = 0; i < FrmGISMain.m_mapControl.LayerCount; i++)
            //{
            //    ILayer pLayer;
            //    pLayer = FrmGISMain.m_mapControl.get_Layer(i);
            //    if (pLayer is IRasterLayer)
            //    {
            //        ComboBoxInLayer.Items.Add(pLayer.Name);
            //    }
            //}
        }
コード例 #3
0
 private void CmbLineCount_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (layerpath.Text.Length > 0)
     {
         //先求每个等分间距
         float   Tmpincrement;
         DataRow FilterRow;
         Tmpincrement = (maxValue - minValue) / Convert.ToInt16(CmbLineCount.Text);
         FilterDataTable.Rows.Clear();
         for (int i = 1; i <= Convert.ToInt16(CmbLineCount.Text); i++)
         {
             FilterRow    = FilterDataTable.NewRow();
             FilterRow[0] = Convert.ToString(minValue + Tmpincrement * (i - 1)) + "~" + Convert.ToString(minValue + Tmpincrement * i);
             FilterRow[1] = i;
             FilterDataTable.Rows.Add(FilterRow);
         }
         DataGridFilterData.DataSource = FilterDataTable;
         DataGridFilterData.Refresh();
     }
 }
コード例 #4
0
ファイル: frmReclass.cs プロジェクト: zyhgis/firstwork
        public void Reclassify()
        {
            InitColorRamp();
            IRasterWorkspace  pRWS;
            IWorkspaceFactory pWorkspaceFactory;

            pWorkspaceFactory = new RasterWorkspaceFactory();
            String wsp;
            int    r;
            int    l;

            r    = ComboBoxInLayer.Text.LastIndexOf("\\");
            l    = ComboBoxInLayer.Text.LastIndexOf(".");
            wsp  = ComboBoxInLayer.Text.Substring(0, r);
            pRWS = (IRasterWorkspace)pWorkspaceFactory.OpenFromFile(wsp, 0);
            try
            {
                string ws  = System.IO.Path.GetDirectoryName(ComboBoxInLayer.Text);
                string fbs = System.IO.Path.GetFileName(ComboBoxInLayer.Text);

                IWorkspaceFactory pWork     = new RasterWorkspaceFactory();
                IRasterWorkspace  pRasterWs = pWork.OpenFromFile(ws, 0) as IRasterWorkspace;
                pRster = pRasterWs.OpenRasterDataset(fbs).CreateDefaultRaster();



                IRasterBandCollection pRasterBandCol;
                pRasterBandCol = (IRasterBandCollection)pRster;


                IRawPixels pRawpixel;
                pRawpixel = (IRawPixels)pRasterBandCol.Item(0);
                IRasterProps pRasterProps;
                pRasterProps = (IRasterProps)pRawpixel;
                IPnt pSize;
                pSize = new DblPnt();
                pSize.SetCoords(pRasterProps.Width, pRasterProps.Height);
                IPixelBlock pPixelBlock;
                pPixelBlock = pRawpixel.CreatePixelBlock(pSize);
                IPnt pPnt;
                pPnt   = new DblPnt();
                pPnt.X = 0; //the origin (top left corner) of the PixelBlock
                pPnt.Y = 0;
                pRawpixel.Read(pPnt, pPixelBlock);
                float PixelValue;

                minValue = 10000000;
                maxValue = 0;
                List <double> allValue = new List <double>();
                for (int i = 0; i < pPixelBlock.Width; i++)
                {
                    for (int j = 0; j < pPixelBlock.Height; j++)
                    {
                        PixelValue = (float)pPixelBlock.GetVal(0, i, j);
                        allValue.Add(PixelValue);
                        if (PixelValue != null)
                        {
                            if (PixelValue > maxValue)
                            {
                                maxValue = PixelValue;
                            }
                            if (PixelValue < minValue)
                            {
                                minValue = PixelValue;
                            }
                        }
                    }
                }

                IRasterBand pRasterBand = new RasterBand();
                pRasterBand = pRasterBandCol.Item(0);
                pRasterBand.ComputeStatsAndHist();

                IRasterStatistics pRasterStatistic;
                //double[] amount = pRasterBand.Histogram.Counts;
                pRasterStatistic = pRasterBand.Statistics;
                maxValue         = (float)pRasterStatistic.Maximum;
                minValue         = (float)pRasterStatistic.Minimum;

                //if (comboBox1.Text.Trim() == "等间隔")
                //{//先求每个等分间距
                float   Tmpincrement;
                DataRow FilterRow;
                Tmpincrement = (maxValue - minValue) / Convert.ToInt16(CmbLineCount.Text);
                FilterDataTable.Rows.Clear();
                for (int i = 1; i <= Convert.ToInt16(CmbLineCount.Text); i++)
                {
                    FilterRow    = FilterDataTable.NewRow();
                    FilterRow[0] = Convert.ToString(minValue + Tmpincrement * (i - 1)) + "~" + Convert.ToString(minValue + Tmpincrement * i);
                    FilterRow[1] = i;
                    FilterRow[2] = i;
                    FilterDataTable.Rows.Add(FilterRow);
                }
                DataGridFilterData.DataSource = FilterDataTable;
                DataGridFilterData.Refresh();
                // }
//else
                // {
                ////allValue.Sort();
                ////List<double> valuesort = new List<double>();
                ////valuesort = BublleSort(allValue);
                //allValue.Sort();
                //int amount = pPixelBlock.Width * pPixelBlock.Height;
                //int Tmpincrement;
                //DataRow FilterRow;
                //Tmpincrement = (amount) / Convert.ToInt16(CmbLineCount.Text);
                //FilterDataTable.Rows.Clear();
                //for (int i = 1; i < Convert.ToInt16(CmbLineCount.Text); i++)
                //{
                //    FilterRow = FilterDataTable.NewRow();
                //    if (allValue[Tmpincrement * (i - 1)] == allValue[Tmpincrement * (i)])
                //        break;
                //    FilterRow[0] = Convert.ToString(allValue[Tmpincrement * (i - 1)]) + "~" + Convert.ToString(allValue[Tmpincrement * (i)]);
                //    FilterRow[1] = i;
                //    FilterDataTable.Rows.Add(FilterRow);
                //}
                //if (allValue[Tmpincrement * Convert.ToInt16(CmbLineCount.Text)] != maxValue)
                //{
                //    FilterRow = FilterDataTable.NewRow();
                //    FilterRow[0] = Convert.ToString(allValue[Tmpincrement * Convert.ToInt16(CmbLineCount.Text)]) + "~" + Convert.ToString(maxValue);
                //    FilterRow[1] = Convert.ToInt16(CmbLineCount.Text);
                //    FilterDataTable.Rows.Add(FilterRow);
                //}
                //DataGridFilterData.DataSource = FilterDataTable;
                //DataGridFilterData.Refresh();
                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }
コード例 #5
0
        private void BtnInput_Click(object sender, EventArgs e)
        {
            OpenFileDialog OpenFileDlg = new OpenFileDialog();
            String         strPath; //  '文件名

            OpenFileDlg.FileName    = "";
            OpenFileDlg.Filter      = "tif files (*.tif)|*.tif|All files (*.*)|*.*"; //过滤文件类型
            OpenFileDlg.FilterIndex = 2;
            OpenFileDlg.ShowDialog();


            strPath = OpenFileDlg.FileName.Trim();


            layerpath.Text = strPath;
            //获取图层的栅格信息
            IRasterWorkspace  pRWS;
            IWorkspaceFactory pWorkspaceFactory;

            pWorkspaceFactory = new RasterWorkspaceFactory();
            String wsp;
            int    r;
            int    l;

            r    = layerpath.Text.LastIndexOf("\\");
            l    = layerpath.Text.LastIndexOf(".");
            wsp  = layerpath.Text.Substring(0, r);
            pRWS = (IRasterWorkspace)pWorkspaceFactory.OpenFromFile(wsp, 0);

            try
            {
                string ws  = Path.GetDirectoryName(layerpath.Text);
                string fbs = Path.GetFileName(layerpath.Text);

                IWorkspaceFactory pWork     = new RasterWorkspaceFactory();
                IRasterWorkspace  pRasterWs = pWork.OpenFromFile(ws, 0) as IRasterWorkspace;
                pRster = pRasterWs.OpenRasterDataset(fbs).CreateDefaultRaster();


                //pRster = pRWS.OpenRasterDataset(sp)
                IRasterBandCollection pRasterBandCol;
                pRasterBandCol = (IRasterBandCollection)pRster;


                IRawPixels pRawpixel;
                pRawpixel = (IRawPixels)pRasterBandCol.Item(0);
                IRasterProps pRasterProps;
                pRasterProps = (IRasterProps)pRawpixel;
                IPnt pSize;
                pSize = new DblPnt();
                pSize.SetCoords(pRasterProps.Width, pRasterProps.Height);
                IPixelBlock pPixelBlock;
                pPixelBlock = pRawpixel.CreatePixelBlock(pSize);
                IPnt pPnt;
                pPnt   = new DblPnt();
                pPnt.X = 0; //the origin (top left corner) of the PixelBlock
                pPnt.Y = 0;
                pRawpixel.Read(pPnt, pPixelBlock);
                float PixelValue;

                minValue = 10000000;
                maxValue = 0;
                for (int i = 0; i < pPixelBlock.Width; i++)
                {
                    for (int j = 0; j < pPixelBlock.Height; j++)
                    {
                        PixelValue = (float)pPixelBlock.GetVal(0, i, j);
                        if (PixelValue != null)
                        {
                            if (PixelValue > maxValue)
                            {
                                maxValue = PixelValue;
                            }
                            if (PixelValue < minValue)
                            {
                                minValue = PixelValue;
                            }
                        }
                    }
                }

                IRasterBand pRasterBand;
                pRasterBand = pRasterBandCol.Item(0);
                pRasterBand.ComputeStatsAndHist();
                IRasterStatistics pRasterStatistic;
                pRasterStatistic = pRasterBand.Statistics;
                maxValue         = (float)pRasterStatistic.Maximum;
                minValue         = (float)pRasterStatistic.Minimum;

                //先求每个等分间距
                float   Tmpincrement;
                DataRow FilterRow;
                Tmpincrement = (maxValue - minValue) / Convert.ToInt16(CmbLineCount.Text);
                FilterDataTable.Rows.Clear();
                for (int i = 1; i < Convert.ToInt16(CmbLineCount.Text); i++)
                {
                    FilterRow    = FilterDataTable.NewRow();
                    FilterRow[0] = Convert.ToString(minValue + Tmpincrement * (i - 1)) + "~" + Convert.ToString(minValue + Tmpincrement * i);
                    FilterRow[1] = i;
                    FilterDataTable.Rows.Add(FilterRow);
                }
                DataGridFilterData.DataSource = FilterDataTable;
                DataGridFilterData.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }