Beispiel #1
0
        public static IRasterBand GetRasterBand(IWorkspace pSDEWorkspace, string strRasterDataset, string strBandName)
        {
            IEnumDataset          pEnumdataset          = pSDEWorkspace.get_Datasets(esriDatasetType.esriDTRasterDataset);
            IRasterBandCollection pRasterBandCollection = null;
            IEnumRasterBand       pEnumRasterBand       = null;
            IRasterBand           pRasterBand           = null;
            IDataset pDataset = pEnumdataset.Next();

            while (pDataset != null)
            {
                if (pDataset.Name == strRasterDataset)
                {
                    pRasterBandCollection = (IRasterBandCollection)pDataset;
                    pEnumRasterBand       = pRasterBandCollection.Bands;
                    pRasterBand           = pEnumRasterBand.Next();
                    while (pRasterBand != null)
                    {
                        if (pRasterBand.Bandname == strBandName)
                        {
                            return(pRasterBand);
                        }
                        pRasterBand = pEnumRasterBand.Next();
                    }
                }
                pDataset = pEnumdataset.Next();
            }
            pRasterBandCollection = null;
            pEnumRasterBand       = null;
            pRasterBand           = null;
            pEnumdataset          = null;
            pDataset = null;
            return(null);
        }
Beispiel #2
0
        private void 噪声分级_Load(object sender, EventArgs e)
        {
            //向图层comboBox1中预置噪音图层
            for (int i = 0; i < global.p2DMap.LayerCount; i++)
            {
                ILayer pLayer = global.p2DMap.get_Layer(i);
                if (pLayer != null)
                {
                    if (pLayer is IRasterLayer)
                    {
                        comboBox1.Items.Add(pLayer.Name);
                    }
                }
            }
            comboBox1.SelectedIndex = 0;

            //向分级数comBobox2中预置分级数,默认为5
            for (int i = 1; i < 7; i++)
            {
                comboBox2.Items.Add(i);
            }


            //栅格像元统计
            IRasterBandCollection bandCollection;
            ILayer         mlayer      = GetLayerByName(comboBox1.SelectedItem.ToString());
            IRasterLayer   rasterLayer = mlayer as IRasterLayer;
            IRaster2       raster      = rasterLayer.Raster as IRaster2;
            IRasterDataset rd          = raster.RasterDataset;

            bandCollection = rd as IRasterBandCollection;
            IEnumRasterBand enumband   = bandCollection.Bands;
            IRasterBand     rasterBand = enumband.Next();

            rasterStatic = null;
            if (rasterBand != null && rasterBand.Statistics != null)
            {
                rasterStatic = rasterBand.Statistics;
            }

            datatable1 = new DataTable();

            DataColumn datacolumn1 = new DataColumn("区间", System.Type.GetType("System.String"));
            DataColumn datacolumn2 = new DataColumn("值", System.Type.GetType("System.Int32"));

            datatable1.Columns.Add(datacolumn1);
            datatable1.Columns.Add(datacolumn2);
            comboBox2.SelectedIndex = 4;
            //for (int i = 0; i < 5; i++)
            //{
            //    DataRow datarow1 = datatable1.NewRow();
            //    datarow1[0] = ((rasterStatic.Maximum - rasterStatic.Minimum) * i / 5).ToString()+"-"+ ((rasterStatic.Maximum - rasterStatic.Minimum) * (i + 1) / 5).ToString();
            //    datarow1[1] = i + 1;
            //    datatable1.Rows.Add(datarow1);

            //}

            dataGridView1.DataSource = datatable1;
            textBox1.Text            = System.Environment.CurrentDirectory + "noiseclassification.tif";
        }
        private void method_0()
        {
            IRasterBandCollection raster = this.irasterLayer_0.Raster as IRasterBandCollection;

            if (raster.Count != this.irasterLayer_0.BandCount)
            {
                IName dataSourceName = (this.irasterLayer_0 as IDataLayer2).DataSourceName;
                if (dataSourceName != null)
                {
                    raster = dataSourceName.Open() as IRasterBandCollection;
                }
            }
            IEnumRasterBand bands = raster.Bands;

            bands.Reset();
            for (IRasterBand band2 = bands.Next(); band2 != null; band2 = bands.Next())
            {
                this.comboBox_0.Items.Add(new BandWrap(band2));
            }
            string[]       strArray = new string[] { "红色", raster.Item(this.irasterRGBRenderer_0.RedBandIndex).Bandname };
            EXListViewItem item     = new EXListViewItem(strArray);

            item.SubItems.Add(new EXBoolListViewSubItem(this.irasterRGBRenderer_0.UseRedBand));
            this.exListView1.Items.Add(item);
            strArray[0] = "绿色";
            strArray[1] = raster.Item(this.irasterRGBRenderer_0.GreenBandIndex).Bandname;
            item        = new EXListViewItem(strArray);
            item.SubItems.Add(new EXBoolListViewSubItem(this.irasterRGBRenderer_0.UseGreenBand));
            this.exListView1.Items.Add(item);
            strArray[0] = "蓝色";
            strArray[1] = raster.Item(this.irasterRGBRenderer_0.BlueBandIndex).Bandname;
            item        = new EXListViewItem(strArray);
            item.SubItems.Add(new EXBoolListViewSubItem(this.irasterRGBRenderer_0.UseBlueBand));
            this.exListView1.Items.Add(item);
            IColor backgroundColor = (this.irasterRGBRenderer_0 as IRasterStretch2).BackgroundColor;

            if (backgroundColor != null)
            {
                this.method_1(this.colorEdit1, backgroundColor);
            }
            backgroundColor = (this.irasterRGBRenderer_0 as IRasterDisplayProps).NoDataColor;
            if (backgroundColor != null)
            {
                this.method_1(this.colorEdit2, backgroundColor);
            }
            object backgroundValue = (this.irasterRGBRenderer_0 as IRasterStretch2).BackgroundValue;

            this.chkShowBackground.Checked = (this.irasterRGBRenderer_0 as IRasterStretch2).Background;
            this.txtBackgroundR.Enabled    = this.chkShowBackground.Checked;
            this.txtBackgroundG.Enabled    = this.chkShowBackground.Checked;
            this.txtBackgroundB.Enabled    = this.chkShowBackground.Checked;
            double[] numArray = backgroundValue as double[];
            this.txtBackgroundR.Text = numArray[0].ToString();
            this.txtBackgroundG.Text = numArray[1].ToString();
            this.txtBackgroundB.Text = numArray[2].ToString();
        }
Beispiel #4
0
        private void method_0()
        {
            IRasterBandCollection raster = this.irasterLayer_0.Raster as IRasterBandCollection;

            if (this.irasterLayer_0.BandCount == 1)
            {
                this.lblBand.Visible = false;
                this.cboBand.Visible = false;
                this.cboBand.Items.Add(new BandWrap(raster.Item(0)));
            }
            else
            {
                if (raster.Count != this.irasterLayer_0.BandCount)
                {
                    IName dataSourceName = (this.irasterLayer_0 as IDataLayer2).DataSourceName;
                    if (dataSourceName != null)
                    {
                        raster = dataSourceName.Open() as IRasterBandCollection;
                    }
                }
                IEnumRasterBand bands = raster.Bands;
                bands.Reset();
                for (IRasterBand band2 = bands.Next(); band2 != null; band2 = bands.Next())
                {
                    this.cboBand.Items.Add(new BandWrap(band2));
                }
            }
            this.cboBand.SelectedIndex = this.irasterStretchColorRampRenderer_0.BandIndex;
            IColor backgroundColor = (this.irasterStretchColorRampRenderer_0 as IRasterStretch2).BackgroundColor;

            if (backgroundColor != null)
            {
                this.method_1(this.colorEdit1, backgroundColor);
            }
            backgroundColor = (this.irasterStretchColorRampRenderer_0 as IRasterDisplayProps).NoDataColor;
            if (backgroundColor != null)
            {
                this.method_1(this.colorEdit2, backgroundColor);
            }
            this.lblHight.Text =
                (this.irasterStretchColorRampRenderer_0 as IRasterStretchMinMax).CustomStretchMax.ToString("0.###");
            this.lblLow.Text =
                (this.irasterStretchColorRampRenderer_0 as IRasterStretchMinMax).CustomStretchMin.ToString("0.###");
            this.chkHillshade.Checked      = (this.irasterStretchColorRampRenderer_0 as IHillShadeInfo).UseHillShade;
            this.txtZFactor.Text           = (this.irasterStretchColorRampRenderer_0 as IHillShadeInfo).ZScale.ToString();
            this.txtHeight.Text            = this.irasterStretchColorRampRenderer_0.LabelHigh;
            this.txtLow.Text               = this.irasterStretchColorRampRenderer_0.LabelLow;
            this.txtMedium.Text            = this.irasterStretchColorRampRenderer_0.LabelMedium;
            this.lblZFactor.Enabled        = this.chkHillshade.Checked;
            this.txtZFactor.Enabled        = this.chkHillshade.Checked;
            this.chkShowBackground.Checked = (this.irasterStretchColorRampRenderer_0 as IRasterStretch2).Background;
            this.txtBackground.Enabled     = this.chkShowBackground.Checked;
            this.txtBackground.Text        =
                (this.irasterStretchColorRampRenderer_0 as IRasterStretch2).BackgroundValue.ToString();
        }
Beispiel #5
0
        private void frm_Stretch_Load(object sender, EventArgs e)
        {
            int          j            = 1;
            IRasterLayer pRasterLayer = raster_layer;

            filepath = pRasterLayer.FilePath;
            if (pRasterLayer.BandCount != 0)
            {
                IRasterBandCollection collection = pRasterLayer.Raster as IRasterBandCollection;
                IEnumRasterBand       rasterband = collection.Bands;
                IRasterBand           band       = rasterband.Next();
                while (band != null)
                {
                    //绑定波段数
                    cmbLayerBand.Items.Add("band " + j);
                    j++;
                    band = rasterband.Next();
                }
                axMapControl1.Map.AddLayer(pRasterLayer);
                axMapControl1.Refresh();
            }
        }
Beispiel #6
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        ///

        public string RasterStistics(IRasterLayer rLayer)
        {
            IRaster2              r2            = rLayer.Raster as IRaster2;
            IRasterDataset        rasterDataset = r2.RasterDataset;
            IRasterBandCollection rasterBands   =
                (IRasterBandCollection)rasterDataset;
            IEnumRasterBand enumRasterBand        = rasterBands.Bands;
            string          sRasterStisticsResult = "Raster Statistics Result:\n";
            IRasterBand     rasterBand            = enumRasterBand.Next();

            while (rasterBand != null)
            {
                bool tmpBool;
                rasterBand.HasStatistics(out tmpBool);
                if (!tmpBool)
                {
                    rasterBand.ComputeStatsAndHist();
                }
                sRasterStisticsResult += GetRasterStistics(rasterBand);
                rasterBand             = enumRasterBand.Next();
            }
            return(sRasterStisticsResult);
        }
        // Function with arguments that have been passed from each sensor.
        public void BandCounts(GUI_AddRaster theGUI)
        {
            try
            {
                // Folder path only.
                string rasterFolderPath = Path.GetDirectoryName(theGUI.textBox_PathURL.Text);

                // Image file name only.
                string rasterFileName = Path.GetFileName(theGUI.textBox_PathURL.Text);

                // Needed for working with rasters.
                IWorkspaceFactory wSF = new RasterWorkspaceFactoryClass();

                // Set the raster image workspace.
                IWorkspace wS = wSF.OpenFromFile(rasterFolderPath, ArcMap.Application.hWnd);

                // Prepare the raster workspace.
                IRasterWorkspace rasterWS = wS as IRasterWorkspace;

                IRasterDataset rasterDataset;

                try
                {
                    // Open the raster image.
                    rasterDataset = rasterWS.OpenRasterDataset(rasterFileName);
                }
                catch
                {
                    // If the raster image is invalid with no bands to count,
                    // catch the error and display this message.
                    MessageBox.Show("Invalid raster. No bands to be counted.");
                    return;
                }

                // Prepare raster image as raster layer.
                IRasterLayer rasterLayer = new RasterLayerClass();

                // Create the raster layer from raster image.
                rasterLayer.CreateFromDataset(rasterDataset);

                // Access band total for image.
                IRasterBandCollection rasterBC        = rasterDataset as IRasterBandCollection;
                IEnumRasterBand       pEnumRasterBand = rasterBC.Bands;
                totalBands = rasterBC.Count;

                // The following code is for accessing individual band names, if needed.
                // These are unused for the code in its current format.
                //int curBandCount = rasterBC.Count;
                //IRasterBand pRasterBand;
                //string bandName;
                //while (curBandCount > 0)
                //{
                //pRasterBand = pEnumRasterBand.Next();
                //bandName = pRasterBand.Bandname.ToString();
                //curBandCount = curBandCount - 1;
                //}
            }

            catch (Exception exc)
            {
                // Catch any exception found and display a message box.
                MessageBox.Show("Exception caught: " + nL + exc.Message + nL + exc.StackTrace);
                return;
            }
        }