コード例 #1
0
ファイル: frmReclass.cs プロジェクト: zyhgis/firstwork
        private void BtnOK_Click(object sender, EventArgs e)
        {
            IReclassOp reCla;

            reCla = new RasterReclassOp() as IReclassOp;
            //为分类着色用
            IRemap       pRemap;
            INumberRemap pSRemap;

            pSRemap = new NumberRemap() as INumberRemap;

            for (int i = 1; i <= Convert.ToInt32(DataGridFilterData.VisibleRowCount - 1); i++)
            {
                String str;
                //DataGridFilterData.ce
                str = DataGridFilterData[i - 1, 0].ToString();

                float fvalue, tvalue;
                int   p;
                p      = str.LastIndexOf("~");
                fvalue = Convert.ToSingle(str.Substring(0, p));
                tvalue = Convert.ToSingle(str.Substring(p + 1, str.Length - p - 1));
                pSRemap.MapRange(fvalue, tvalue, i);
            }

            // pSRemap.MapValueToNoData(-9999)
            pRemap = (IRemap)pSRemap;

            IGeoDataset pOutputRaster = null;

            try
            {
                pOutputRaster = reCla.ReclassByRemap((IGeoDataset)pRster, pRemap, true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            IRasterLayer pRlayer;

            pRlayer = new RasterLayer();
            pRlayer.CreateFromRaster((IRaster)pOutputRaster);
            pRlayer.Name = Name + "Reclass";
            IRaster ds;

            ds = (IRaster)pOutputRaster;
            IRasterLayer pla;

            pla = SetStretchRenderer(ds);
            IColorRamp pRamp;
            //获得色带
            int index = imgCmbSingleClassify.SelectedIndex;

            pRamp = AlgorithmicColorRamp(index, DataGridFilterData.VisibleRowCount - 1);
            //分级色带渲染
            SingleClassifyRender(pRlayer, DataGridFilterData.VisibleRowCount - 1, pRamp);
            FrmGISMain.mainMap.AddLayer(pRlayer, 0);
            //FrmGISMain.mainMap.AddLayer(pRlayer, 0);
            Oput(pRlayer);
            //Output(pRlayer);
        }
コード例 #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            IReclassOp reCla;

            reCla = new RasterReclassOp() as IReclassOp;
            //符号化
            IRemap       pRemap;
            INumberRemap pSRemap;

            pSRemap = new NumberRemap() as INumberRemap;
            for (int i = 1; i <= Convert.ToInt32(comboBox2.SelectedItem.ToString()); i++)
            {
                try
                {
                    string str;
                    str = dataGridView1.Rows[i - 1].Cells[0].Value.ToString();
                    float fValue, tValue;
                    int   p;
                    p = str.LastIndexOf("-");

                    fValue = Convert.ToSingle(str.Substring(0, p));
                    tValue = Convert.ToSingle(str.Substring(p + 1, str.Length - p - 1));
                    pSRemap.MapRange(fValue, tValue, Convert.ToInt32(dataGridView1.Rows[i - 1].Cells[1].Value));
                }
                catch
                {
                    MessageBox.Show("Error!");
                    return;
                }
            }
            pRemap = (IRemap)pSRemap;

            //获取栅格图层
            IRasterLayer play          = (IRasterLayer)GetLayerByName(comboBox1.SelectedItem.ToString());
            IRaster      pRster        = play.Raster;
            IGeoDataset  pOutputRaster = null;

            try
            {
                pOutputRaster = reCla.ReclassByRemap((IGeoDataset)pRster, pRemap, true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            try
            {
                IWorkspaceFactory pWKSF      = new RasterWorkspaceFactoryClass();
                IWorkspace        pWorkspace = pWKSF.OpenFromFile(System.IO.Path.GetDirectoryName(textBox1.Text), 0);
                ISaveAs           pSaveAs    = pOutputRaster as ISaveAs;
                pSaveAs.SaveAs(System.IO.Path.GetFileName(textBox1.Text), pWorkspace, "TIFF");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            IRasterLayer pRlayer = new RasterLayer();

            pRlayer.CreateFromRaster((IRaster)pOutputRaster);
            pRlayer.Name = System.IO.Path.GetFileName(textBox1.Text);
            global.p2DMap.AddLayer(pRlayer);
            global.p3DMap.Scene.AddLayer(pRlayer);
            mainForm.axTOCControl1.Update();
            mainForm.axTOCControl2.Update();
        }