Exemple #1
0
        private void OpenRaster(string rasterFileName)
        {
            //文件名处理

            string ws = System.IO.Path.GetDirectoryName(rasterFileName);

            string fbs = System.IO.Path.GetFileName(rasterFileName);

            //创建工作空间

            IWorkspaceFactory pWork = new RasterWorkspaceFactoryClass();

            //打开工作空间路径,工作空间的参数是目录,不是具体的文件名

            IRasterWorkspace pRasterWS = (IRasterWorkspace)pWork.OpenFromFile(ws, 0);

            //打开工作空间下的文件,

            IRasterDataset pRasterDataset = pRasterWS.OpenRasterDataset(fbs);


            IRasterLayer pRasterLayer = new RasterLayerClass();

            pRasterLayer.CreateFromDataset(pRasterDataset);

            //添加到图层控制中
            IRaster pRaster = pRasterLayer.Raster;

            IGeoDataset           pGeodataset = pRaster as IGeoDataset;
            IRasterBandCollection pRsBandCol  = pGeodataset as IRasterBandCollection;
            int bandCount;

            bandCount = pRsBandCol.Count;
            if (bandCount == 1)
            {
                IRasterBand pRasterBand1 = pRsBandCol.Item(0);
                pRasterBand1.ComputeStatsAndHist();
            }
            if (bandCount > 1)
            {
                IRasterBand pRasterBand1 = pRsBandCol.Item(0);
                pRasterBand1.ComputeStatsAndHist();
                IRasterBand pRasterBand2 = pRsBandCol.Item(1);
                pRasterBand2.ComputeStatsAndHist();
                IRasterBand pRasterBand3 = pRsBandCol.Item(2);
                pRasterBand3.ComputeStatsAndHist();
            }


            IRasterDataset pRasterDataset2 = pRasterWS.OpenRasterDataset(fbs);
            IRasterLayer   pRasterLayer2   = new RasterLayerClass();

            pRasterLayer2.CreateFromDataset(pRasterDataset2);

            //添加到图层控制中

            pMap.AddLayer(pRasterLayer2 as ILayer);
        }
        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();
        }
Exemple #3
0
        public IRasterRenderer CreateDefaultRasterRenderer(IRaster raster)
        {
            //Get raster dataset
            IRasterBandCollection rasterBandCollection = (IRasterBandCollection)raster;
            IRasterBand           rasterBand           = rasterBandCollection.Item(0);
            IRasterDataset        rasterDataset        = (IRasterDataset)rasterBand;

            //Check for TIFF format
            string format_Renamed = rasterDataset.Format;

            if (format_Renamed.Substring(0, 4) != "TIFF")
            {
                return(null);
            }

            //check for bit depth
            IRasterProps rasterProps = (IRasterProps)rasterBand;

            if (rasterProps.PixelType != rstPixelType.PT_U1)
            {
                return(null);
            }

            //create renderer for 1 bit raster
            //Create a unique value renderer and associate it with raster
            IRasterUniqueValueRenderer rasterUniqueValueRenderer = new RasterUniqueValueRendererClass();
            IRasterRenderer            rasterRenderer            = (IRasterRenderer)rasterUniqueValueRenderer;

            rasterRenderer.Raster = raster;
            rasterRenderer.Update();

            //Define the renderer
            rasterUniqueValueRenderer.HeadingCount = 1;
            rasterUniqueValueRenderer.set_Heading(0, "");
            rasterUniqueValueRenderer.set_ClassCount(0, 2);
            rasterUniqueValueRenderer.Field = "VALUE";
            rasterUniqueValueRenderer.AddValue(0, 0, 0);
            rasterUniqueValueRenderer.AddValue(0, 1, 1);
            rasterUniqueValueRenderer.set_Label(0, 0, "0");
            rasterUniqueValueRenderer.set_Label(0, 1, "1");

            // Define symbology for rendering value 0
            IColor color1 = (IColor)(CreateRGBColor(200, 50, 0)); //Brown color

            ISimpleFillSymbol simpleFillSymbol1 = new SimpleFillSymbolClass();

            simpleFillSymbol1.Color = color1;
            rasterUniqueValueRenderer.set_Symbol(0, 0, (ISymbol)simpleFillSymbol1);

            IColor color2 = new RgbColorClass();

            color2.NullColor = true;

            ISimpleFillSymbol simpleFillSymbol2 = new SimpleFillSymbolClass();

            simpleFillSymbol2.Color = color2;

            rasterUniqueValueRenderer.set_Symbol(0, 1, (ISymbol)simpleFillSymbol2);
            return(rasterRenderer);
        }
        private void Btn_RasterStatistic_Click(object sender, EventArgs e)
        {
            IRasterLayer pTargetRasterLayer = m_selectedLayer as IRasterLayer;

            if (pTargetRasterLayer == null)
            {
                MessageBox.Show("非栅格图层");
                return;
            }
            IRaster pTargetRaster = pTargetRasterLayer.Raster;
            IRasterBandCollection pTargetRasterBandCollection = pTargetRaster as IRasterBandCollection;

            string strReport = "";

            for (int index = 0; index < pTargetRasterBandCollection.Count; index++)
            {
                IRasterBand pTarRasterBand = pTargetRasterBandCollection.Item(index);
                pTarRasterBand.HasStatistics(out bool bHasStat);
                if (!bHasStat)
                {
                    pTarRasterBand.ComputeStatsAndHist();
                }
                IRasterStatistics pRStatistic = pTarRasterBand.Statistics;
                strReport += String.Format("Band{0}\n  Maximum:{1}\n  Mean:{2}\n  Median:{3}\n  Minimum{4}\n  Mode:{5}\n  StandardDeviation:{6}\n",
                                           index, pRStatistic.Maximum, pRStatistic.Mean, pRStatistic.Median, pRStatistic.Minimum, pRStatistic.Mode, pRStatistic.StandardDeviation);
            }
            MessageBox.Show(strReport, m_selectedLayer.Name + "栅格信息统计");
        }
        /// <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);
        }
        /// <summary>
        /// 获取栅格波段中的属性表
        /// </summary>
        /// <param name="raster"></param>
        /// <returns></returns>
        private static ITable GetRasterBandAttributeTable(IRaster raster)
        {
            IRasterBandCollection rasterBands = (IRasterBandCollection)raster;
            IRasterBand           rasterBand  = rasterBands.Item(0);

            return(rasterBand.AttributeTable);
        }
Exemple #7
0
        private void getRasterBandItem(DevComponents.AdvTree.Node parentNode, string dataType)
        {
            //获取当前的栅格文件
            FileInfo       file     = (FileInfo)parentNode.Tag;
            string         dataPath = file.FullName;
            IRasterDataset pRasterDataset;

            pRasterDataset = GetRasterDataset(file.FullName, dataType);
            IRasterLayer pRasterLayer = new RasterLayerClass();

            pRasterLayer.CreateFromDataset(pRasterDataset);
            IRaster pRaster = pRasterLayer.Raster;
            IRasterBandCollection pRasterBandCol = (IRasterBandCollection)pRaster;

            IRasterBand pRasterBand = null;

            for (int i = 0; i < pRasterBandCol.Count; i++)
            {
                pRasterBand = pRasterBandCol.Item(i);
                ListViewItem item = new ListViewItem();
                item.Tag        = pRasterBand;
                item.Name       = pRasterBand.Bandname;
                item.Text       = pRasterBand.Bandname;
                item.ImageIndex = 14;
                lvwData.Items.Add(item);
            }
        }
        //图层Plus计算后的包含关系数值判断
        public static bool containCorrRel(IGeoDataset pGeodataset, int chkVal1, int chkVal2)
        {
            bool containRel = true;
            //利用栅格图层的属性表实验
            IRaster pRaster = pGeodataset as IRaster;
            IRasterBandCollection pRasterBandCollection = pRaster as IRasterBandCollection;
            IRasterBand           pRasterBand           = pRasterBandCollection.Item(0);
            ITable       pTabel       = pRasterBand.AttributeTable;
            IQueryFilter pQueryfilter = new QueryFilterClass();

            pQueryfilter.WhereClause = "";
            ICursor pCursor = pTabel.Search(pQueryfilter, false);
            IRow    pRow    = pCursor.NextRow();

            while (pRow != null)
            {
                long type = Convert.ToInt64(pRow.get_Value(pTabel.Fields.FindField("Value")));
                if (type != chkVal1 && type != chkVal2)
                {
                    containRel = false;
                    break;
                }
                pRow = pCursor.NextRow();
            }
            return(containRel);
        }
Exemple #9
0
        private void SetMeanCellSize()
        {
            if (chkSocCellSize.Checked)
            {
                IRasterBandCollection rasterBands = m_pRaster.RasterDataset as IRasterBandCollection;
                if (rasterBands.Count < 1)
                {
                    return;
                }
                IRasterProps props = rasterBands.Item(0) as IRasterProps;

                //更改分辨率首先要修改图层范围
                if (SetLayerExtent(props.MeanCellSize().X, props.MeanCellSize().Y))
                {
                    txtCellSizeX.Text = props.MeanCellSize().X.ToString();
                    txtCellSizeY.Text = props.MeanCellSize().Y.ToString();
                }
            }
            else
            {
                if (SetLayerExtent(m_pRasterProps.MeanCellSize().X, m_pRasterProps.MeanCellSize().Y))
                {
                    txtCellSizeX.Text = m_pRasterProps.MeanCellSize().X.ToString();
                    txtCellSizeY.Text = m_pRasterProps.MeanCellSize().Y.ToString();
                }
            }
        }
Exemple #10
0
        public void Write(float?[,] rasterValue, string format)
        {
            FileHelper.DeleteFile(_workSpace, _fileName, ".tif", ".tfw", ".tif.aux");
            IRasterWorkspace2 rasterWs = OpenRasterWorkspace();

            if (rasterWs == null)
            {
                throw new NullReferenceException("栅格文件打开失败");
            }
            IRasterDataset rasterDataset = rasterWs.CreateRasterDataset(_fileName + ".tif",
                                                                        format, RasterInfo.OriginPoint, RasterInfo.Width, RasterInfo.Height,
                                                                        RasterInfo.XCellSize, RasterInfo.YCellSize, 1, rstPixelType.PT_FLOAT,
                                                                        RasterInfo.SpatialReference, true);
            IRasterBandCollection rasterBands = (IRasterBandCollection)rasterDataset;
            var rasterBand  = rasterBands.Item(0);
            var rasterProps = (IRasterProps)rasterBand;

            //Set NoData if necessary. For a multiband image, NoData value needs to be set for each band.
            rasterProps.NoDataValue = -1;
            //Create a raster from the dataset.
            IRaster raster = rasterDataset.CreateDefaultRaster();

            //Create a pixel block.
            IPnt blocksize = new PntClass();

            blocksize.SetCoords(RasterInfo.Width, RasterInfo.Height);
            IPixelBlock3 pixelblock = raster.CreatePixelBlock(blocksize) as IPixelBlock3;
            //Populate some pixel values to the pixel block.
            var pixels = (Array)pixelblock.get_PixelData(0);

            for (int i = 0; i < RasterInfo.Width; i++)
            {
                for (int j = 0; j < RasterInfo.Height; j++)
                {
                    if (rasterValue[i, j].HasValue)
                    {
                        pixels.SetValue((float)rasterValue[i, j], i, j);
                    }
                    else
                    {
                        pixels.SetValue(-1, i, j);
                    }
                }
            }

            pixelblock.set_PixelData(0, pixels);

            //Define the location that the upper left corner of the pixel block is to write.
            IPnt upperLeft = new PntClass();

            upperLeft.SetCoords(0, 0);

            //Write the pixel block.
            IRasterEdit rasterEdit = (IRasterEdit)raster;

            rasterEdit.Write(upperLeft, (IPixelBlock)pixelblock);

            //Release rasterEdit explicitly.
            Marshal.ReleaseComObject(rasterEdit);
        }
Exemple #11
0
        /// <summary>
        /// 计算信息熵阈值
        /// </summary>
        public bool CalEntropyMean(out string msg)
        {
            IRasterDataset pRasterDataset = null;

            try
            {
                pRasterDataset = EngineAPI.OpenRasterFile(_Hyper_Entropy);
                IRasterBandCollection pRasterBandCollection = pRasterDataset as IRasterBandCollection;
                IRasterBand           pRasterBand           = pRasterBandCollection.Item(0);
                bool hasSta = false;
                pRasterBand.HasStatistics(out hasSta);
                if (!hasSta)
                {
                    pRasterBand.ComputeStatsAndHist();
                }
                IRasterStatistics pRasterStatistics = pRasterBand.Statistics;
                _Hyper_Entropy_T = pRasterStatistics.Mean;
                msg = "";
                return(true);
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                return(false);
            }
            finally
            {
                if (pRasterDataset != null)
                {
                    Marshal.ReleaseComObject(pRasterDataset);
                }
            }
        }
Exemple #12
0
        //分级渲染函数
        private void RasterClassifyRender(IRasterLayer pRasterLayer)
        {
            try
            {
                IColorRamp pColorRamp = (IColorRamp)EnumStyleItem[comboBoxColor.SelectedIndex];

                IRasterClassifyColorRampRenderer pRClassRend = new RasterClassifyColorRampRenderer() as IRasterClassifyColorRampRenderer;
                IRasterRenderer pRRend = pRClassRend as IRasterRenderer;

                IRaster pRaster = pRasterLayer.Raster;
                IRasterBandCollection pRBandCol = pRaster as IRasterBandCollection;
                IRasterBand           pRBand    = pRBandCol.Item(0);
                if (pRBand.Histogram == null)
                {
                    pRBand.ComputeStatsAndHist();
                }
                pRRend.Raster = pRaster;

                pRRend.Update();

                IRgbColor pFromColor = new RgbColor() as IRgbColor;
                pFromColor.Red   = 255;
                pFromColor.Green = 0;
                pFromColor.Blue  = 0;
                IRgbColor pToColor = new RgbColor() as IRgbColor;
                pToColor.Red   = 0;
                pToColor.Green = 0;
                pToColor.Blue  = 255;

                IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRamp() as IAlgorithmicColorRamp;

                //colorRamp = pColorRamp as IAlgorithmicColorRamp;///////
                colorRamp.Size = comboBoxClassValue.SelectedIndex + 1;

                //colorRamp.FromColor = pFromColor;
                //colorRamp.ToColor = pToColor;
                int nClass = comboBoxClassValue.SelectedIndex + 1;
                colorRamp.FromColor = pColorRamp.get_Color(0);
                colorRamp.ToColor   = pColorRamp.get_Color(nClass - 1);
                bool createColorRamp;


                colorRamp.CreateRamp(out createColorRamp);

                IFillSymbol fillSymbol = new SimpleFillSymbol() as IFillSymbol;

                for (int i = 0; i < nClass; i++)
                {
                    fillSymbol.Color = colorRamp.get_Color(i);
                    pRClassRend.set_Symbol(i, fillSymbol as ISymbol);
                    pRClassRend.set_Label(i, pRClassRend.get_Break(i).ToString("0.00"));
                }
                pRasterLayer.Renderer = pRRend;
                m_mapControl.Refresh();
            }
            catch (Exception e)
            {
                MessageBox.Show("创建失败!");
            }
        }
Exemple #13
0
        private IRasterDataset OpenRasterDataset(string inFile, int bandIndex)
        {
            IRasterDataset rasterDataset = null;

            IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactory();;
            IRasterWorkspace  rasterWorkspace;
            int    Index    = inFile.LastIndexOf("\\");
            string filePath = inFile.Substring(0, Index);
            string fileName = inFile.Substring(Index + 1);

            try
            {
                if (!File.Exists(inFile))
                {
                    throw new Exception("文件不存在," + inFile);
                }
                rasterWorkspace = (IRasterWorkspace)pWorkspaceFactory.OpenFromFile(filePath, 0);
                rasterDataset   = rasterWorkspace.OpenRasterDataset(fileName);
                if (bandIndex > 0)
                {
                    IRasterBandCollection pRasterBandCollection = rasterDataset as IRasterBandCollection;
                    IRasterBand           pBand = pRasterBandCollection.Item(bandIndex - 1);
                    rasterDataset = pBand as IRasterDataset;
                }
            }
            catch (Exception ex)
            {
                //Console.WriteLine("Failed in Opening RasterDataset. " + ex.InnerException.ToString());
                Log.WriteLog(typeof(RasterMapAlgebraOp), ex);
                throw ex;
            }

            return(rasterDataset);
        }
        public ISurface GetSurfaceFromLayer(ILayer ilayer_0)
        {
            ISurface surface = null;

            if (ilayer_0 == null)
            {
                surface = null;
            }
            else if (ilayer_0 is ITinLayer)
            {
                ITinLayer tinLayer = ilayer_0 as ITinLayer;
                surface = (tinLayer.Dataset as ISurface);
            }
            else if (ilayer_0 is IRasterLayer)
            {
                IRasterLayer rasterLayer = ilayer_0 as IRasterLayer;
                if (surface == null)
                {
                    IRasterBandCollection rasterBandCollection = rasterLayer.Raster as IRasterBandCollection;
                    IRasterBand           rasterBand           = rasterBandCollection.Item(0);
                    surface = (new RasterSurface
                    {
                        RasterBand = rasterBand
                    } as ISurface);
                }
            }
            return(surface);
        }
Exemple #15
0
        internal static Dictionary <string, double> SummariseRasterStatistically(IGeoDataset pRasterGeoDataset)
        {
            IRasterBandCollection tClippedAsBandCollection = pRasterGeoDataset as IRasterBandCollection;
            IRasterBand           tClippedBand             = tClippedAsBandCollection.Item(0);

            logger.LogMessage(ServerLogger.msgType.debug, "SummariseContinuousRaster", 99, "Continuous raster clipped, checking stats...");
            bool tHasStatistics;

            tClippedBand.HasStatistics(out tHasStatistics);
            // what on earth? why not just have a bool return type to the HasStatistics method??!
            if (!tHasStatistics)
            {
                tClippedBand.ComputeStatsAndHist();
            }
            IRasterStatistics tClippedStats = tClippedBand.Statistics;

            //tClippedStats.Recalculate();
            logger.LogMessage(ServerLogger.msgType.debug, "SummariseContinuousRaster", 99, "Continuous raster stats made, recording info...");
            Dictionary <string, double> tResults = new Dictionary <string, double>();

            tResults["Mean"] = tClippedStats.Mean;
            tResults["Max"]  = tClippedStats.Maximum;
            tResults["Min"]  = tClippedStats.Minimum;
            //NB Median isn't available with floating data. (Neither are majority,minority,variety). Would need
            //to e.g. convert to int by multiplying raster first.
            //tResults["Median"] = tClippedStats.Median;
            return(tResults);
        }
        /// <summary>
        /// 基于给定的波段索引,获取栅格波段
        /// </summary>
        /// <param name="inFile">输入栅格文件</param>
        /// <param name="bandIndex">波段索引</param>
        /// <returns></returns>
        public static IRasterBand GetRasterBandAt(string inFile, int bandIndex = 0)
        {
            IRaster raster = GetRaster(inFile);
            IRasterBandCollection rasterBandCollection = raster as IRasterBandCollection;

            return(rasterBandCollection == null ? null : rasterBandCollection.Item(bandIndex));
        }
Exemple #17
0
        public static void GetCurrentSurfaceMax(ILayer ilayer_0, out double double_0, out double double_1)
        {
            ISurface surfaceFromLayer = SurfaceInfo.GetSurfaceFromLayer(ilayer_0);

            if (surfaceFromLayer != null)
            {
                if (surfaceFromLayer is ITinAdvanced)
                {
                    ITinAdvanced tinAdvanced = surfaceFromLayer as ITinAdvanced;
                    IEnvelope    extent      = tinAdvanced.Extent;
                    double_0 = ((extent.Width > extent.Height) ? extent.Width : extent.Height);
                    double_1 = extent.ZMax;
                }
                else
                {
                    IRasterSurface rasterSurface = surfaceFromLayer as IRasterSurface;
                    IRasterProps   rasterProps   = rasterSurface.Raster as IRasterProps;
                    IEnvelope      extent        = rasterProps.Extent;
                    double_0 = ((extent.Width > extent.Height) ? extent.Width : extent.Height);
                    IRasterBandCollection rasterBandCollection = rasterProps as IRasterBandCollection;
                    IRasterBand           rasterBand           = rasterBandCollection.Item(0);
                    IRasterStatistics     statistics           = rasterBand.Statistics;
                    double_1 = statistics.Maximum;
                }
            }
            else
            {
                double_0 = 0.0;
                double_1 = 0.0;
            }
        }
Exemple #18
0
        private void frmSelectBand_Load(object sender, EventArgs e)
        {
            this.comboBox1.Items.Clear();
            IDataLayer2 dataLayer = m_rasLayer as IDataLayer2;
            string dataSource = dataLayer.DataSourceName.NameString;
            if (dataSource.Contains("RASTER")) //�ļ�
            {
                string path = dataSource.Substring(dataSource.IndexOf('=') + 1, dataSource.IndexOf(';') - dataSource.IndexOf('=') - 2);
                string name = dataSource.Substring(dataSource.LastIndexOf('=') + 1, dataSource.LastIndexOf(';') - dataSource.LastIndexOf('=') - 1);
                IWorkspaceFactory m_workspaceFactory = new RasterWorkspaceFactoryClass();
                IRasterWorkspace rasterWorkspce = m_workspaceFactory.OpenFromFile(path.Trim(), 0) as IRasterWorkspace;
                IRasterDataset rasDataset = rasterWorkspce.OpenRasterDataset(name.Trim());
                m_rc = rasDataset as IRasterBandCollection;
                for (int i = 0; i < m_rc.Count; i++)
                {
                    this.comboBox1.Items.Add(m_rc.Item(i).Bandname.ToString());
                }
            }
            else
            {
                string name = dataSource;
                IRasterWorkspaceEx rasterWorkspce = m_workSpace as IRasterWorkspaceEx;
                IRasterDataset rasDataset = rasterWorkspce.OpenRasterDataset(name);
                m_rc = rasDataset as IRasterBandCollection;
                for (int i = 0; i < m_rc.Count; i++)
                {
                    this.comboBox1.Items.Add(m_rc.Item(i).Bandname.ToString());
                }

            }
        }
Exemple #19
0
        private int GetMaxBandCount()
        {
            int[] max = new int[m_selband.Length];
            for (int i = 0; i < m_selband.Length; i++)
            {
                IRaster2              raster2     = m_rstlayer.Raster as IRaster2;
                IRasterDataset        rstDataset  = raster2.RasterDataset;
                IRasterBandCollection rstBandColl = rstDataset as IRasterBandCollection;
                IRasterBand           rasterBand  = rstBandColl.Item(i);
                //获取每个像元值的统计个数
                double[] histo = rasterBand.Histogram.Counts as double[];
                //计算最大像元数
                int maxCount = (int)histo[0];
                for (int j = 0; j < histo.Length; j++)
                {
                    if (maxCount < histo[j])
                    {
                        maxCount = (int)histo[j];
                    }
                }
                //记录下该波段的最大像元数
                max[i] = maxCount;
            }
            //计算所有波段的最大像元数
            int maxst = max[0];

            for (int k = 0; k < max.Length; k++)
            {
                if (maxst < max[k])
                {
                    maxst = (int)max[k];
                }
            }
            return(maxst);
        }
Exemple #20
0
        private void frmSelectBand_Load(object sender, EventArgs e)
        {
            this.comboBox1.Items.Clear();
            IDataLayer2 dataLayer  = m_rasLayer as IDataLayer2;
            string      dataSource = dataLayer.DataSourceName.NameString;

            if (dataSource.Contains("RASTER")) //Îļþ
            {
                string            path = dataSource.Substring(dataSource.IndexOf('=') + 1, dataSource.IndexOf(';') - dataSource.IndexOf('=') - 2);
                string            name = dataSource.Substring(dataSource.LastIndexOf('=') + 1, dataSource.LastIndexOf(';') - dataSource.LastIndexOf('=') - 1);
                IWorkspaceFactory m_workspaceFactory = new RasterWorkspaceFactoryClass();
                IRasterWorkspace  rasterWorkspce     = m_workspaceFactory.OpenFromFile(path.Trim(), 0) as IRasterWorkspace;
                IRasterDataset    rasDataset         = rasterWorkspce.OpenRasterDataset(name.Trim());
                m_rc = rasDataset as IRasterBandCollection;
                for (int i = 0; i < m_rc.Count; i++)
                {
                    this.comboBox1.Items.Add(m_rc.Item(i).Bandname.ToString());
                }
            }
            else
            {
                string             name           = dataSource;
                IRasterWorkspaceEx rasterWorkspce = m_workSpace as IRasterWorkspaceEx;
                IRasterDataset     rasDataset     = rasterWorkspce.OpenRasterDataset(name);
                m_rc = rasDataset as IRasterBandCollection;
                for (int i = 0; i < m_rc.Count; i++)
                {
                    this.comboBox1.Items.Add(m_rc.Item(i).Bandname.ToString());
                }
            }
        }
        private void Btn_ApplyRasterBaseSurface_Click(object sender, EventArgs e)
        {
            ILayer                pBaseLayer                = m_pTarScene.Layer[CbBoxBaseLayer.SelectedIndex];
            ILayer                pDisplayLayer             = m_pTarLayer;
            IRasterSurface        pBaseSurfaceRaster        = new RasterSurface();
            IRasterLayer          pBaseRasterLayer          = pBaseLayer as IRasterLayer;
            IRaster               pBaseRaster               = (IRaster)pBaseRasterLayer.Raster;
            IRasterBandCollection pBaseRasterBandCollection = pBaseRaster as IRasterBandCollection;
            IRasterBand           pBaseRasterBand           = pBaseRasterBandCollection.Item(0);

            pBaseSurfaceRaster.RasterBand = pBaseRasterBand;
            ISurface         pBaseSurface     = pBaseSurfaceRaster as ISurface;
            ILayerExtensions pLayerExtensions = pDisplayLayer as ILayerExtensions;
            I3DProperties    p3DProperties    = null;

            for (int i = 0; i < pLayerExtensions.ExtensionCount; i++)
            {
                object pCurExtension = pLayerExtensions.get_Extension(i);
                if (pCurExtension != null)
                {
                    p3DProperties = (I3DProperties)pCurExtension;
                    break;
                }
            }

            p3DProperties.BaseOption  = esriBaseOption.esriBaseSurface;
            p3DProperties.BaseSurface = pBaseSurface;
            p3DProperties.Apply3DProperties(pDisplayLayer);
            p3DProperties.ZFactor = 1;

            m_pTarScene.SceneGraph.RefreshViewers();
        }
Exemple #22
0
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster.
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         // Call Read method of the Raster Function Helper object.
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         int  pBHeight = pPixelBlock.Height;
         int  pBWidth  = pPixelBlock.Width;
         IPnt pbSize   = new PntClass();
         pbSize.SetCoords(pBWidth, pBHeight);
         //IPixelBlock3 inVlsPb = (IPixelBlock3)myFunctionHelperCoef.Raster.CreatePixelBlock(pbSize);
         //myFunctionHelperCoef.Read(pTlc,null,myFunctionHelperCoef.Raster, (IPixelBlock)inVlsPb);
         IPixelBlock3          outPixelBlock = (IPixelBlock3)pPixelBlock;
         System.Array          outArr        = (System.Array)outPixelBlock.get_PixelData(0);
         System.Array[]        inArr         = new System.Array[inrs.RasterInfo.BandCount];
         IRasterBandCollection rsBc          = (IRasterBandCollection)inrs;
         for (int b = 0; b < inrs.RasterInfo.BandCount; b++)
         {
             IRasterBand rsB  = rsBc.Item(b);
             IRawPixels  rPix = (IRawPixels)rsB;
             IPixelBlock pb   = rPix.CreatePixelBlock(pbSize);
             rPix.Read(pTlc, pb);
             inArr[b] = (System.Array)pb.get_SafeArray(b);
         }
         updateOutArr(outPixelBlock, inArr, outArr);
         outPixelBlock.set_PixelData(0, outArr);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
 }
Exemple #23
0
 private void tabControl1_SelectedIndexChanged(object sender, System.EventArgs e)
 {
     if (tabControl1.SelectedIndex == 1)
     {
         if (m_layer is IRasterLayer)
         {
             panel1.Visible         = false;
             panel2.Visible         = true;
             listBox1.SelectedIndex = 0;
             panel3.Visible         = true;
         }
         else
         {
             panel1.Visible = true;
             panel2.Visible = false;
         }
     }
     if (panel3.Visible == true)
     {
         //加载波段
         comboBoxBand.Items.Clear();
         string strFilepath = GetFileNameByLayer.GetRasterFileName(m_layer);
         m_pRasterDataset        = OpenFileRasterDataset(strFilepath);
         m_pRasterBandCollection = (IRasterBandCollection)m_pRasterDataset;
         int BandCount = m_pRasterBandCollection.Count;
         for (int i = 0; i < BandCount; i++)
         {
             IRasterBand band = m_pRasterBandCollection.Item(i);
             comboBoxBand.Items.Add(band.Bandname);
         }
         comboBoxBand.SelectedIndex = 0;
     }
 }
Exemple #24
0
        public void Init()
        {
            try
            {
                //根据选择的矢量文件的路径打开工作空间
                string   fileN    = panImage;
                FileInfo fileInfo = new FileInfo(fileN);
                string   filePath = fileInfo.DirectoryName;
                string   fileName = fileInfo.Name;

                IWorkspaceFactory wsf        = new RasterWorkspaceFactory();
                IWorkspace        wp         = wsf.OpenFromFile(filePath, 0);
                IRasterWorkspace  rw         = (IRasterWorkspace)wp;
                IRasterDataset    panDataset = rw.OpenRasterDataset(fileName);

                IRaster2       multiRaster2 = m_raster as IRaster2;
                IRasterDataset multiDataset = multiRaster2.RasterDataset;
                //默认波段顺序,RGB和近红外
                //创建全色和多光谱栅格数据集的full栅格对象
                IRaster panRaster   = ((IRasterDataset2)panDataset).CreateFullRaster();
                IRaster multiRaster = ((IRasterDataset2)multiDataset).CreateFullRaster();
                //设置红外波段
                IRasterBandCollection rasterbandCol = (IRasterBandCollection)multiRaster;
                IRasterBandCollection infredRaster  = new RasterClass();
                infredRaster.AppendBand(rasterbandCol.Item(3));

                //设置全色波段的属性
                IRasterProps panSharpenRasterProps = (IRasterProps)multiRaster;
                IRasterProps panRasterProps        = (IRasterProps)panRaster;
                panSharpenRasterProps.Width  = panRasterProps.Width;
                panSharpenRasterProps.Height = panRasterProps.Height;
                panSharpenRasterProps.Extent = panRasterProps.Extent;
                multiRaster.ResampleMethod   = rstResamplingTypes.RSP_BilinearInterpolationPlus;

                //创建全色锐化过滤器和设置其参数
                IPansharpeningFilter pansharpenFilter = new PansharpeningFilterClass();
                pansharpenFilter.InfraredImage     = (IRaster)infredRaster;
                pansharpenFilter.PanImage          = (IRaster)panRaster;
                pansharpenFilter.PansharpeningType = esriPansharpeningType.esriPansharpeningESRI;
                pansharpenFilter.PutWeights(red, green, blue, infra);

                //将全色锐化过滤器设置于多光谱栅格对象上
                IPixelOperation pixeOperation = (IPixelOperation)multiRaster;
                pixeOperation.PixelFilter = (IPixelFilter)pansharpenFilter;

                //保存结果数据集,并加载显示
                //加载显示裁剪结果图像

                /*IRasterLayer panSharpenLayer = new RasterLayerClass();
                 * panSharpenLayer.CreateFromRaster(multiRaster);
                 * panSharpenLayer.Name = "panSharpen_Result";
                 * panSharpenLayer.SpatialReference = ((IGeoDataset)multiRaster).SpatialReference;
                 * return panSharpenLayer;*/
                m_raster = multiRaster;
            }
            catch (System.Exception ex)//异常处理,输出错误信息
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public static void setNoDataValueForASpecificBand(IRasterDataset rasterDataset)
        {
            IRasterBandCollection rasterBandCollection = (IRasterBandCollection)rasterDataset;
            IRasterBand           rasterBand           = rasterBandCollection.Item(0);
            IRasterProps          rasterProps          = (IRasterProps)rasterBand;

            rasterProps.NoDataValue = 15;
        }
        // Hämtar maxvärdet i rasterlager.
        public double rasterStatMax(IRaster inputRaster)
        {
            IRasterBandCollection bands      = (IRasterBandCollection)inputRaster;
            IRasterBand           rasterBand = bands.Item(0);
            IRasterStatistics     rs         = rasterBand.Statistics;

            return(rs.Maximum);
        }
        //
        //创建RGB波段组合菜单项
        //
        private void AddPopMenuRGBItem(object obj, IRasterLayer rasterLayer)
        {
            ItemClickEventHandler itemClickEventHandler = null;

            GFSApplication.RGBBandMtch bandMatch = new GFSApplication.RGBBandMtch();
            bandMatch._rasterLayer      = rasterLayer;
            bandMatch._applicationClass = this;
            bandMatch._rasterRGBRender  = bandMatch._rasterLayer.Renderer as IRasterRGBRenderer;
            this._popMenuRGB.ClearLinks();
            List <BarCheckItem> list = new List <BarCheckItem>();

            bandMatch._bandIndex    = (int)obj;
            bandMatch._barCheckItem = new BarCheckItem();
            list.Add(bandMatch._barCheckItem);
            bandMatch._barCheckItem.Caption = "可见";
            this.GetUseBand(bandMatch._rasterRGBRender, bandMatch._bandIndex, bandMatch._barCheckItem);
            this._popMenuRGB.AddItem(bandMatch._barCheckItem);
            IRasterBandCollection rasterBandCollection = (bandMatch._rasterLayer.Raster as IRaster2).RasterDataset as IRasterBandCollection;

            for (int i = 0; i < rasterBandCollection.Count; i++)
            {
                IRasterBand  rasterBand   = rasterBandCollection.Item(i);
                BarCheckItem barCheckItem = new BarCheckItem();
                list.Add(barCheckItem);
                barCheckItem.GroupIndex = 8;
                barCheckItem.Caption    = rasterBand.Bandname;
                barCheckItem.Tag        = i;
                int num = -1;
                switch (bandMatch._bandIndex)
                {
                case 0:
                    num = bandMatch._rasterRGBRender.RedBandIndex;
                    break;

                case 1:
                    num = bandMatch._rasterRGBRender.GreenBandIndex;
                    break;

                case 2:
                    num = bandMatch._rasterRGBRender.BlueBandIndex;
                    break;
                }
                if (i == num)
                {
                    barCheckItem.Checked = true;
                }
                this._popMenuRGB.AddItem(barCheckItem);
            }
            foreach (BarCheckItem barCheckItem in list)
            {
                if (itemClickEventHandler == null)
                {
                    itemClickEventHandler = new ItemClickEventHandler(bandMatch.BarItem_Click);
                }
                barCheckItem.CheckedChanged += itemClickEventHandler;
            }
            this._popMenuRGB.ShowPopup(System.Windows.Forms.Control.MousePosition);
        }
Exemple #28
0
        public void createSSTrst(ILayer layer)
        {
            IRasterClassifyColorRampRenderer pRClassRend  = new RasterClassifyColorRampRenderer() as IRasterClassifyColorRampRenderer;
                        IRasterRenderer      pRRend       = pRClassRend as IRasterRenderer;

            IRasterLayer rstLayer = layer as IRasterLayer;
             
                        IRaster pRaster = rstLayer.Raster;
                        IRasterBandCollection pRBandCol = pRaster as IRasterBandCollection;
                        IRasterBand           pRBand    = pRBandCol.Item(0);

                        if(pRBand.Histogram == null)
                         {
                                pRBand.ComputeStatsAndHist();
                            
            }
                        pRRend.Raster          = pRaster;
                        pRClassRend.ClassCount = 10;
                        pRRend.Update();
             
                        IRgbColor pFromColor = new RgbColor() as IRgbColor;

                        pFromColor.Red   = 0;
                        pFromColor.Green = 0;
                        pFromColor.Blue  = 255;
                        IRgbColor pToColor = new RgbColor() as IRgbColor;

                        pToColor.Red   = 255;
                        pToColor.Green = 0;
                        pToColor.Blue  = 0;
             
                        IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRamp() as IAlgorithmicColorRamp;

                        colorRamp.Size      = 10;
                        colorRamp.FromColor = pFromColor;
                        colorRamp.ToColor   = pToColor;          
                        bool createColorRamp;
             
                        colorRamp.CreateRamp(out createColorRamp);

             
                        IFillSymbol fillSymbol = new SimpleFillSymbol() as IFillSymbol;

                        for(int i = 0; i < pRClassRend.ClassCount; i++)
                         {
                                fillSymbol.Color = colorRamp.get_Color(i);
                                pRClassRend.set_Symbol(i, fillSymbol as ISymbol);
                                pRClassRend.set_Label(i, pRClassRend.get_Break(i).ToString("0.00"));
                            
            }
                        rstLayer.Renderer = pRRend;

            axMapControl1.AddLayer(rstLayer);

            this.axMapControl1.ActiveView.Refresh();
            this.axTOCControl1.Update();
        }
        private void SetRepresentationType(IRaster raster, rstRepresentationType rasterRepresentationType)
        {
            IRasterBandCollection rasterBandCollection = (raster as IRaster2).RasterDataset as IRasterBandCollection;

            for (int i = 0; i < rasterBandCollection.Count; i++)
            {
                rasterBandCollection.Item(i).RepresentationType = rasterRepresentationType;
            }
        }
Exemple #30
0
        public IRawPixels GetRawPixels(IRasterDataset pRDS, int band)
        {
            IRawPixels            pRP;
            IRasterBandCollection pBandCollection = pRDS as IRasterBandCollection;

            IRasterBand pRasterBand = pBandCollection.Item(band);

            pRP = pRasterBand as IRawPixels;
            return(pRP);
        }
Exemple #31
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();
        }