Beispiel #1
0
        public IRasterLayer RasterRenderedLayer(IRasterLayer pRL, bool renderType, int grayBandIndex, int[] rgbBandIndex)
        {
            //实例新的栅格图层
            IRasterLayer   rlayer        = new RasterLayerClass();
            string         fullPath      = pRL.FilePath;
            IRasterDataset rasterDataset = OpenFileRasterDataset(fullPath);

            //单波段
            if (rgbBandIndex == null)
            {
                //如果grayBandIndex=-1
                try
                {
                    //定义拉伸颜色条
                    IRgbColor pFromColor = new RgbColorClass();
                    pFromColor.Red   = this.userControl_Color1.FromColor.R;
                    pFromColor.Green = this.userControl_Color1.FromColor.G;
                    pFromColor.Blue  = this.userControl_Color1.FromColor.B;
                    IRgbColor pToColor = new RgbColorClass();
                    pToColor.Red   = this.userControl_Color1.ToColor.R;
                    pToColor.Green = this.userControl_Color1.ToColor.G;
                    pToColor.Blue  = this.userControl_Color1.ToColor.B;
                    IRasterRenderer render = null;
                    render = BandCombinationShow.StretchRenderer(rasterDataset, grayBandIndex, this.stretchType, pFromColor, pToColor);
                    rlayer.CreateFromDataset(rasterDataset);
                    rlayer.Renderer = render as IRasterRenderer;
                    return(rlayer);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return(null);
                }
            }
            else//多波段显示
            {
                try
                {
                    //设置彩色合成顺序 生成新的渲染模式
                    IRasterRGBRenderer render = new RasterRGBRendererClass();
                    render.RedBandIndex   = rgbBandIndex[0];
                    render.GreenBandIndex = rgbBandIndex[1];
                    render.BlueBandIndex  = rgbBandIndex[2];

                    IRasterStretch stretchType = (IRasterStretch)render;
                    stretchType.StretchType             = this.stretchType;
                    stretchType.StandardDeviationsParam = 2;


                    rlayer.CreateFromDataset(rasterDataset);
                    rlayer.Renderer = render as IRasterRenderer;
                    return(rlayer);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return(null);
                }
            }
        }
Beispiel #2
0
        private void DrawRaster(string file)
        {
            try
            {
                Logger.Debug("Start drawing tile" + file + "...");
                IRasterLayer rl = new RasterLayerClass();
                rl.CreateFromFilePath(file);
                var props = (IRasterProps)rl.Raster;
                props.SpatialReference = _dataSpatialReference;

                if (_needReproject)
                {
                    IRasterGeometryProc rasterGeometryProc = new RasterGeometryProcClass();
                    var missing = Type.Missing;
                    rasterGeometryProc.ProjectFast(_layerSpatialReference, rstResamplingTypes.RSP_NearestNeighbor, ref missing, rl.Raster);
                }

                // Fix for issue "Each 256x256 tile rendering differently causing blockly effect."
                // In 10.1 the StrecthType for rasters seems to have changed from esriRasterStretch_NONE to "Percent Clip",
                // giving color problems with 24 or 32 bits tiles.
                // http://arcbrutile.codeplex.com/workitem/11207
                var image  = new Bitmap(file, true);
                var format = image.PixelFormat;
                if (format == PixelFormat.Format24bppRgb || format == PixelFormat.Format32bppArgb || format == PixelFormat.Format32bppRgb)
                {
                    var rasterRGBRenderer = new RasterRGBRendererClass();
                    ((IRasterStretch2)rasterRGBRenderer).StretchType = esriRasterStretchTypesEnum.esriRasterStretch_NONE;
                    rl.Renderer = rasterRGBRenderer;
                }

                rl.Renderer.ResamplingType = rstResamplingTypes.RSP_BilinearInterpolation;
                // Now set the spatial reference to the dataframe spatial reference!
                // Do not remove this line...
                rl.SpatialReference = _layerSpatialReference;
                //rl.Draw(ESRI.ArcGIS.esriSystem.esriDrawPhase.esriDPGeography, (IDisplay)activeView.ScreenDisplay, null);
                rl.Draw(esriDrawPhase.esriDPGeography, _display, null);
                //activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, trackCancel, env);
                Logger.Debug("End drawing tile.");
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch (Exception)
            {
                // what to do now...
                // just try to load next tile...
            }
        }
Beispiel #3
0
        public override void Draw(esriDrawPhase drawPhase, IDisplay display, ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel)
        {
            var file = @"D:\aaa\strava_issue\2016_1350.png";

            var rl = new RasterLayerClass();

            rl.CreateFromFilePath(file);
            var props = (IRasterProps)rl.Raster;

            props.SpatialReference = new SpatialReferences().GetSpatialReference("urn: ogc:def: crs:EPSG: 6.18.3:3857");
            IRasterGeometryProc3 rasterGeometryProc = new RasterGeometryProcClass();
            var missing = Type.Missing;
            var layerSpatialReference = sp;

            rasterGeometryProc.ProjectFast(layerSpatialReference, rstResamplingTypes.RSP_NearestNeighbor, ref missing, rl.Raster);

            // fix 9/10/2015: with projected tiles color changes and transparency is ignored.
            var image = new Bitmap(file, true);
            // image.MakeTransparent(Color.White);
            //image.Save(@"D:\aaa\strava_issue\2018_1350.png");
            var format = image.PixelFormat;

            if (format == PixelFormat.Format24bppRgb | format == PixelFormat.Format32bppArgb)
            {
                var rasterRgbRenderer = new RasterRGBRendererClass();
                ((IRasterStretch2)rasterRgbRenderer).StretchType = esriRasterStretchTypesEnum.esriRasterStretch_NONE;
                // ((IRasterStretch3)rasterRgbRenderer).UseGamma = true;
                ((IRasterStretch2)rasterRgbRenderer).Background = true;
                ((IRasterStretch3)rasterRgbRenderer).UseGamma   = true;
                var r = new RgbColorClass();
                r.Red   = 49;
                r.Green = 0;
                r.Blue  = 38;
                ((IRasterStretch2)rasterRgbRenderer).BackgroundColor = r;
                //((IRasterStretch2)rasterRgbRenderer).BackgroundColor = r;

                rl.Renderer = rasterRgbRenderer;
            }
            // end fix 9/10/2015: with projected tiles color changes and transparency is ignored.

            rl.Draw(esriDrawPhase.esriDPGeography, display, null);
        }
        /// <summary>
        /// 通过给定的图层名称和波段设置显示影像
        /// </summary>
        /// <param name="selectLayerName">图层名</param>
        /// <param name="bandSet">要显示的波段数组</param>
        public void SetImgBand(string selectLayerName, int[] bandSet)
        {
            int    layerCount  = _pMap.LayerCount;
            ILayer selectLayer = null;
            IMap   pMap        = _pMap;


            //get Selected layer
            for (int i = 0; i < layerCount; i++)
            {
                if (selectLayerName == pMap.Layer[i].Name)
                {
                    selectLayer = pMap.Layer[i];
                }
            }

            IRasterLayer pRasterLayer = selectLayer as IRasterLayer;

            if (pRasterLayer != null && pRasterLayer.BandCount > 3)
            {
                //初始化RGB渲染
                IRasterRGBRenderer2 rasterRgbRenderer2 = new RasterRGBRendererClass();
                IRasterRenderer     rasterRenderer     = (IRasterRenderer)rasterRgbRenderer2;
                rasterRenderer.Raster = pRasterLayer.Raster;

                //设置RGB波段
                rasterRgbRenderer2.SetBandIndices(bandSet[0], bandSet[1], bandSet[2]);
                rasterRenderer.Update();

                //刷新地图
                pRasterLayer.Renderer = (IRasterRenderer)rasterRgbRenderer2;
                IActiveView pActiveView = pMap as IActiveView;
                if (pActiveView != null)
                {
                    pActiveView.Refresh();
                }
            }
        }
        private void DrawRaster(string file, IDisplay display)
        {
            try
            {
                var rl = new RasterLayerClass();
                rl.CreateFromFilePath(file);
                var props = (IRasterProps)rl.Raster;
                props.SpatialReference = _dataSpatialReference;

                // Fix for issue "Each 256x256 tile rendering differently causing blockly effect."
                // In 10.1 the StrecthType for rasters seems to have changed from esriRasterStretch_NONE to "Percent Clip",
                // giving color problems with 24 or 32 bits tiles.
                // http://arcbrutile.codeplex.com/workitem/11207
                var image = new Bitmap(file, true);
                var format = image.PixelFormat;
                if (format == PixelFormat.Format24bppRgb || format == PixelFormat.Format32bppArgb || format == PixelFormat.Format32bppRgb)
                {
                    var rasterRGBRenderer = new RasterRGBRendererClass();
                    ((IRasterStretch2)rasterRGBRenderer).StretchType = esriRasterStretchTypesEnum.esriRasterStretch_NONE;
                    rl.Renderer = rasterRGBRenderer;
                }

                rl.Renderer.ResamplingType = rstResamplingTypes.RSP_BilinearInterpolation;
                // Now set the spatial reference to the dataframe spatial reference!
                // Do not remove this line...
                rl.SpatialReference = SpatialReference;
                //rl.Draw(ESRI.ArcGIS.esriSystem.esriDrawPhase.esriDPGeography, (IDisplay)activeView.ScreenDisplay, null);
                rl.Draw(esriDrawPhase.esriDPGeography, display, null);
                //Logger.Debug("End drawing tile.");

            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch (Exception)
            {
                // what to do now...
                // just try to load next tile...
            }
        }
Beispiel #6
0
        /// <summary>
        ///对Raster根据数据行进行渲染,可以渲染成单通道灰度显示和RGB合成显示
        /// </summary>
        /// <param name="renderType">渲染方式调节</param>
        /// <returns></returns>
        public IRasterLayer RasterRenderedLayer(IRasterLayer pRL, bool renderType, int grayBandIndex, int[] rgbBandIndex)
        {
            //实例新的栅格图层
            IRasterLayer rlayer = new RasterLayerClass();

            string         fullPath      = pRL.FilePath;
            IRasterDataset rasterDataset = OpenFileRasterDataset(fullPath);


            //单波段
            if (rgbBandIndex == null)
            {
                //如果grayBandIndex=-1
                try
                {
                    IRasterRenderer render = null;
                    render = BandCombinationShow.StretchRenderer(rasterDataset, grayBandIndex);
                    rlayer.CreateFromDataset(rasterDataset);
                    rlayer.Renderer = render as IRasterRenderer;
                    return(rlayer);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return(null);
                }
            }
            else//多波段显示
            {
                try
                {
                    if (!renderType)
                    {
                        IRasterRenderer render = BandCombinationShow.StretchRenderer(rasterDataset, grayPos);
                        rlayer.CreateFromDataset(rasterDataset);
                        rlayer.Renderer = render as IRasterRenderer;
                    }
                    else
                    {
                        //设置彩色合成顺序 生成新的渲染模式
                        IRasterRGBRenderer render = new RasterRGBRendererClass();
                        render.RedBandIndex   = rgbBandIndex[0];
                        render.GreenBandIndex = rgbBandIndex[1];
                        render.BlueBandIndex  = rgbBandIndex[2];

                        IRasterStretch stretchType = (IRasterStretch)render;
                        stretchType.StretchType             = esriRasterStretchTypesEnum.esriRasterStretch_StandardDeviations;
                        stretchType.StandardDeviationsParam = 2;


                        rlayer.CreateFromDataset(rasterDataset);
                        rlayer.Renderer = render as IRasterRenderer;
                    }

                    return(rlayer);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return(null);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// 得到Renderer从数据库中
        /// </summary>
        /// <returns></returns>
        public static object GetRendererFromBlob(string sql, IWorkspace pConfigWks)
        {
            Exception err = null;

            SysCommon.Gis.IGisTable pGISTable = new SysCommon.Gis.SysGisTable(pConfigWks);

            //获取Renderer
            byte[] renderByte = pGISTable.GetFieldValue("Render", "Render", sql, out err) as byte[];

            //是否得到了序列化的blob,没得到,则返回NULL
            if (renderByte == null)
            {
                return(null);
            }

            IMemoryBlobStreamVariant pMemoryBlobStreamVariant = new MemoryBlobStreamClass();

            pMemoryBlobStreamVariant.ImportFromVariant((object)renderByte);
            IStream pStream = pMemoryBlobStreamVariant as IStream;

            //从数据库中得到符号的类型  shduan 20110721 增加RasterRenderer
            string strRenderType = pGISTable.GetFieldValue("Render", "RenderType", sql, out err).ToString();
            string strLyrType    = pGISTable.GetFieldValue("Render", "LayerType", sql, out err).ToString();

            if (strLyrType == "RasterLayer")
            {
                IRasterRenderer pRRenderer = null;
                switch (strRenderType)
                {
                case "RasterClassifyColorRampRenderer":
                    pRRenderer = new RasterClassifyColorRampRendererClass();
                    break;

                case "RasterUniqueValueRenderer":
                    pRRenderer = new RasterUniqueValueRendererClass();
                    break;

                case "RasterDiscreteColorRenderer":
                    pRRenderer = new RasterDiscreteColorRendererClass();
                    break;

                case "RasterRGBRenderer":
                    pRRenderer = new RasterRGBRendererClass();
                    break;

                case "RasterStretchColorRampRenderer":
                    pRRenderer = new RasterStretchColorRampRendererClass();
                    break;
                }
                IPersistStream pPersistStream = pRRenderer as IPersistStream;
                pPersistStream.Load(pStream);
                //pRRenderer = pPersistStream as IRasterRenderer;

                return(pRRenderer);
            }
            else
            {
                IFeatureRenderer pFRenderer = null;
                switch (strRenderType)
                {
                case "AnnoColor":
                    string sAnnoColor = Encoding.Default.GetString(renderByte);
                    return((object)sAnnoColor);

                case "SimpleRenderer":
                    pFRenderer = new SimpleRendererClass();
                    break;

                case "UniqueValueRenderer":
                    pFRenderer = new UniqueValueRendererClass();
                    break;

                case "ClassBreaksRenderer":
                    pFRenderer = new ClassBreaksRendererClass();
                    break;

                case "ProportionalSymbolRenderer":
                    pFRenderer = new ProportionalSymbolRendererClass();
                    break;

                case "ChartRenderer":
                    pFRenderer = new ChartRendererClass();
                    break;
                }
                IPersistStream pPersistStream = pFRenderer as IPersistStream;
                pPersistStream.Load(pStream);
                pFRenderer = pPersistStream as IFeatureRenderer;

                return(pFRenderer);
            }
        }
Beispiel #8
0
        /// <summary>
        ///对Raster根据数据行进行渲染,可以渲染成单通道灰度显示和RGB合成显示
        /// </summary>
        /// <param name="renderType">渲染方式调节</param>
        /// <returns></returns>
        public IRasterLayer RasterRenderedLayer(IRasterLayer pRL, bool renderType, int grayBandIndex, int[] rgbBandIndex)
        {
            //实例新的栅格图层
            IRasterLayer rlayer = new RasterLayerClass();

            string fullPath = pRL.FilePath;
            IRasterDataset rasterDataset = OpenFileRasterDataset(fullPath);

            //单波段
            if (rgbBandIndex == null)
            {
                //如果grayBandIndex=-1
                try
                {
                    IRasterRenderer render = null;
                    render = BandCombinationShow.StretchRenderer(rasterDataset, grayBandIndex);
                    rlayer.CreateFromDataset(rasterDataset);
                    rlayer.Renderer = render as IRasterRenderer;
                    return rlayer;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return null;
                }
            }
            else//多波段显示
            {

                try
                {
                    if (!renderType)
                    {
                        IRasterRenderer render = BandCombinationShow.StretchRenderer(rasterDataset, grayPos);
                        rlayer.CreateFromDataset(rasterDataset);
                        rlayer.Renderer = render as IRasterRenderer;
                    }
                    else
                    {
                        //设置彩色合成顺序 生成新的渲染模式
                        IRasterRGBRenderer render = new RasterRGBRendererClass();
                        render.RedBandIndex = rgbBandIndex[0];
                        render.GreenBandIndex = rgbBandIndex[1];
                        render.BlueBandIndex = rgbBandIndex[2];

                        IRasterStretch stretchType = (IRasterStretch)render;
                        stretchType.StretchType = esriRasterStretchTypesEnum.esriRasterStretch_StandardDeviations;
                        stretchType.StandardDeviationsParam = 2;

                        rlayer.CreateFromDataset(rasterDataset);
                        rlayer.Renderer = render as IRasterRenderer;

                    }

                    return rlayer;

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return null;
                }
            }
        }
        private static void DrawRaster(string file)
        {
            try{
                Stopwatch timer = new Stopwatch();
                timer.Start();
                IRasterLayer rl;
                if (!layers.ContainsKey(file)){

                    Logger.Debug("Start drawing tile" + file + "...");
                    rl = new RasterLayerClass();

                    rl.CreateFromFilePath(file);
                    var props = (IRasterProps) rl.Raster;
                    props.SpatialReference = _dataSpatialReference;

                    if (_needReproject){
                        IRasterGeometryProc rasterGeometryProc = new RasterGeometryProcClass();
                        var missing = Type.Missing;
                        rasterGeometryProc.ProjectFast(_layerSpatialReference, rstResamplingTypes.RSP_NearestNeighbor,
                                                       ref missing, rl.Raster);
                    }

                    // Fix for issue "Each 256x256 tile rendering differently causing blockly effect."
                    // In 10.1 the StrecthType for rasters seems to have changed from esriRasterStretch_NONE to "Percent Clip",
                    // giving color problems with 24 or 32 bits tiles.
                    // http://arcbrutile.codeplex.com/workitem/11207
                    var image = new Bitmap(file, true);
                    var format = image.PixelFormat;
                    if (format == PixelFormat.Format24bppRgb || format == PixelFormat.Format32bppRgb){
                        var rasterRGBRenderer = new RasterRGBRendererClass();
                        ((IRasterStretch2) rasterRGBRenderer).StretchType =
                            esriRasterStretchTypesEnum.esriRasterStretch_NONE;
                        rl.Renderer = rasterRGBRenderer;
                    }

                    rl.Renderer.ResamplingType = rstResamplingTypes.RSP_BilinearInterpolation;
                    // Now set the spatial reference to the dataframe spatial reference!
                    // Do not remove this line...
                    rl.SpatialReference = _layerSpatialReference;

                    timer.Stop();
                    Logger.Debug(file + "读取花费时间:" + timer.Elapsed.Milliseconds);
                    layers.Add(file,rl);
                    layerNames.Enqueue(file);
                    if (layerNames.Count > 100){
                        string tempname = layerNames.Dequeue();
                        layers.Remove(tempname);
                    }
                }
                else{
                    layers.TryGetValue(file, out rl);
                    timer.Stop();
                    Logger.Debug(file+"查询花费时间:" + timer.Elapsed.Milliseconds);
                }
                timer.Reset();

                //rl.Draw(ESRI.ArcGIS.esriSystem.esriDrawPhase.esriDPGeography, (IDisplay)activeView.ScreenDisplay, null);
                rl.Draw(esriDrawPhase.esriDPGeography, _display, null);
                //activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, trackCancel, env);
                timer.Stop();
                Logger.Debug(file + "绘制花费时间:" + timer.Elapsed.Milliseconds);
                //Logger.Debug("End drawing tile.");

            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch (Exception)
            {
                // what to do now...
                // just try to load next tile...
            }
        }
Beispiel #10
0
        private void DrawRasterNew(string file, TileInfo tileInfo)
        {
            if (_needReproject)
            {
                var rl = new RasterLayerClass();
                rl.CreateFromFilePath(file);
                var props = (IRasterProps)rl.Raster;
                props.SpatialReference = _dataSpatialReference;
                var rasterGeometryProc = new RasterGeometryProcClass();
                var missing            = Type.Missing;
                rasterGeometryProc.ProjectFast(_layerSpatialReference, rstResamplingTypes.RSP_NearestNeighbor, ref missing, rl.Raster);

                // fix 9/10/2015: with projected tiles color changes and transparency is ignored.
                var image  = new Bitmap(file, true);
                var format = image.PixelFormat;
                if (format == PixelFormat.Format24bppRgb | format == PixelFormat.Format32bppArgb)
                {
                    var rasterRgbRenderer = new RasterRGBRendererClass();
                    ((IRasterStretch2)rasterRgbRenderer).StretchType = esriRasterStretchTypesEnum.esriRasterStretch_NONE;
                    ((IRasterStretch2)rasterRgbRenderer).Background  = true;
                    rl.Renderer = rasterRgbRenderer;
                }
                // end fix 9/10/2015: with projected tiles color changes and transparency is ignored.

                rl.Draw(esriDrawPhase.esriDPGeography, _display, null);
            }
            else
            {
                using (var fs = new System.IO.FileStream(file, FileMode.Open, FileAccess.Read))
                {
                    if (fs.Length > 100)
                    {
                        var img1 = Image.FromStream(fs, true);
                        {
                            // add check if tile needs to be clipped
                            if (ClipTilesEnvelope != null)
                            {
                                if (tileInfo.Extent.MinX <ClipTilesEnvelope.XMin |
                                                          tileInfo.Extent.MaxX> ClipTilesEnvelope.XMax |
                                    tileInfo.Extent.MinY <ClipTilesEnvelope.YMin |
                                                          tileInfo.Extent.MaxY> ClipTilesEnvelope.YMax)
                                {
                                    img1 = ImageProcessor.CropImage(img1, tileInfo, ClipTilesEnvelope);
                                }
                            }

                            if (img1 != null)
                            {
                                var ms = new MemoryStream();
                                img1.Save(ms, ImageFormat.Png);
                                var bytes1 = ms.ToArray();
                                var ul     = new PointClass()
                                {
                                    X = tileInfo.Extent.MinX, Y = tileInfo.Extent.MaxY
                                };
                                var lr = new PointClass()
                                {
                                    X = tileInfo.Extent.MaxX, Y = tileInfo.Extent.MinY
                                };
                                ImageDrawer.Draw(_display, bytes1, ul, lr);
                                img1.Dispose();
                            }
                        }
                    }
                }
            }
        }
        // Function with arguments that have been passed from each sensor.
        public void bandCombination(GUI_AddRaster theGUI, int int_RedBandIndex, int int_GreenBandIndex, int int_BlueBandIndex)
        {
            try
            {
                // Folder path only.
                string rasterFolderPath = System.IO.Path.GetDirectoryName(theGUI.textBox_PathURL.Text);

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

                // Map document.
                IMxDocument mxDoc = ArcMap.Application.Document as IMxDocument;

                // 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;

                // Open the raster image.
                IRasterDataset rasterDataset = rasterWS.OpenRasterDataset(rasterFileName);

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

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

                // Add raster layer to map.
                mxDoc.AddLayer(rasterLayer);

                // Required for displaying raster layer with specific band combinations (the renderer).
                IRasterRGBRenderer2 rgbRen = new RasterRGBRendererClass();
                IRasterRenderer     rasRen = rgbRen as IRasterRenderer;

                // Assign band combination based on parameters that were fed into the function.
                rgbRen.RedBandIndex   = int_RedBandIndex;
                rgbRen.GreenBandIndex = int_GreenBandIndex;
                rgbRen.BlueBandIndex  = int_BlueBandIndex;

                // Rename the raster layer to sensor type + study type + image name, with spaces and file extension removed.
                rasterLayer.Name = theGUI.combo_SensorType.SelectedItem.ToString().Replace(" ", string.Empty) + "_" +
                                   theGUI.combo_StudyType.SelectedItem.ToString().Replace(" ", string.Empty) + "__" +
                                   System.IO.Path.GetFileNameWithoutExtension(rasterFileName).Replace(" ", string.Empty);

                // Update the renderer with band combinations.
                rasterLayer.Renderer = rasRen;
                rasRen.Update();

                if (theGUI.checkBox_RasterExtent.Checked)
                {
                    // Zoom to raster image extent if the checkbox is checked.
                    mxDoc.ActiveView.Extent = rasterLayer.AreaOfInterest;
                }

                // Refresh the map and update the table of contents.
                mxDoc.ActiveView.Refresh();
                mxDoc.UpdateContents();
            }

            catch (Exception exc)
            {
                // Catch any exception found and display a message box.
                MessageBox.Show("Exception caught: " + nL + exc.Message + nL + exc.StackTrace);
                return;
            }
        }
Beispiel #12
0
        private void bt_ok_Click(object sender, EventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            if (comboBoxSelect.SelectedItem == null)
            {
                MessageBox.Show("图层不能为空");
                return;
            }
            if (comboBoxRed.SelectedItem == null || comboBoxGreen.SelectedItem == null || comboBoxBlue.SelectedItem == null)
            {
                MessageBox.Show("波段不能为空!");
                return;
            }
            if (textBoxOutPut.Text == "")
            {
                MessageBox.Show("存储路径不能为空!");
                return;
            }
            IRasterLayer pRasterLayer = new RasterLayerClass();

            pRasterLayer.CreateFromDataset(m_pRasterDataset);
            IRasterRGBRenderer pRasterRGBRen = new RasterRGBRendererClass();
            IRasterRenderer    pRasterRen    = (IRasterRenderer)pRasterRGBRen;

            pRasterRen.Raster            = pRasterLayer.Raster;
            pRasterRGBRen.RedBandIndex   = comboBoxRed.SelectedIndex;
            pRasterRGBRen.GreenBandIndex = comboBoxGreen.SelectedIndex;
            pRasterRGBRen.BlueBandIndex  = comboBoxBlue.SelectedIndex;
            pRasterRen.Update();
            pRasterLayer.Renderer = (IRasterRenderer)pRasterRGBRen;
            IRaster pRaster = pRasterLayer.Raster;

            if (pRaster != null)
            {
                IWorkspaceFactory WF       = new RasterWorkspaceFactoryClass();
                string            filename = textBoxOutPut.Text;
                string            filepath = System.IO.Path.GetDirectoryName(filename);
                string            name     = System.IO.Path.GetFileName(filename);
                try
                {
                    IWorkspace rasterWorkspace = WF.OpenFromFile(filepath, 0);
                    ISaveAs    saveAs          = (ISaveAs)pRaster;
                    saveAs.SaveAs(name, rasterWorkspace, "");
                    if (MessageBox.Show("保存成功,是否打开图层?") == DialogResult.OK)
                    {
                        pRasterLayer.Name = name;
                        m_mapControl.AddLayer(pRasterLayer);
                        m_mapControl.Extent = pRasterLayer.AreaOfInterest;
                        m_mapControl.ActiveView.Refresh();
                        m_mapControl.Refresh();
                        m_mapControl.Update();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
            }
            splashScreenManager1.CloseWaitForm();
            this.Close();
        }
Beispiel #13
0
        private void btnuse_Click(object sender, EventArgs e)
        {
            if (treeshow.SelectedIndex == 1)
            {
                IRasterRGBRenderer2 pRRGBRenderUse = new RasterRGBRendererClass();
                if ((bool)gridsymbol.Rows[0].Cells[0].Value == true)
                {
                    pRRGBRenderUse.UseRedBand = true;
                }
                else
                {
                    pRRGBRenderUse.UseRedBand = false;
                }

                if ((bool)gridsymbol.Rows[1].Cells[0].Value == true)
                {
                    pRRGBRenderUse.UseGreenBand = true;
                }
                else
                {
                    pRRGBRenderUse.UseGreenBand = false;
                }
                if ((bool)gridsymbol.Rows[2].Cells[0].Value == true)
                {
                    pRRGBRenderUse.UseBlueBand = true;
                }
                else
                {
                    pRRGBRenderUse.UseBlueBand = false;
                }
                if ((bool)gridsymbol.Rows[3].Cells[0].Value == true)
                {
                    pRRGBRenderUse.UseAlphaBand = true;
                }
                else
                {
                    pRRGBRenderUse.UseAlphaBand = false;
                }

                pRRGBRenderUse.RedBandIndex   = cmbred.SelectedIndex;
                pRRGBRenderUse.GreenBandIndex = cmbgreen.SelectedIndex;
                pRRGBRenderUse.BlueBandIndex  = cmbblue.SelectedIndex;
                pRRGBRenderUse.AlphaBandIndex = cmbalpha.SelectedIndex;

                pRLayer.Renderer = (IRasterRenderer)pRRGBRenderUse;
            }
            else
            {
                if (pRStretch.StretchType == esriRasterStretchTypesEnum.esriRasterStretch_MinimumMaximum)
                {
                    if (txtmin.Text == "" && txtmax.Text != "")
                    {
                        MessageBox.Show("请设置拉伸的最小值", "提示", MessageBoxButtons.OK);
                    }
                    else if (txtmax.Text == "" && txtmin.Text != "")
                    {
                        MessageBox.Show("请设置拉伸的最大值", "提示", MessageBoxButtons.OK);
                    }
                    else if (txtmax.Text == "" && txtmin.Text == "")
                    {
                        MessageBox.Show("请设置拉伸的最大值以及最小值", "提示", MessageBoxButtons.OK);
                    }
                    else
                    {
                        pRasterStretchMinMax = (IRasterStretchMinMax)pRStretch;
                        pRasterStretchMinMax.UseCustomStretchMinMax = true;
                        pRasterStretchMinMax.CustomStretchMin       = double.Parse(txtmin.Text);
                        pRasterStretchMinMax.CustomStretchMax       = double.Parse(txtmax.Text);
                        pRStretch             = (IRasterStretch)pRasterStretchMinMax;
                        pRStretch.StretchType = esriRasterStretchTypesEnum.esriRasterStretch_MinimumMaximum;
                    }
                }

                if (chkdisplay.Checked == true)
                {
                    pRStretch.Background      = true;
                    pRStretch.BackgroundColor = ClsGDBDataCommon.ColorToIColor(colbackg.SelectedColor);
                    pRStretch.set_BackgroundValues(Convert.ToDouble(backvalue.Text));
                }
                else
                {
                    pRStretch.Background = false;
                }

                IRasterStretchColorRampRenderer pStretchColorRasterRenderer = (IRasterStretchColorRampRenderer)pRStretch;;
                IRasterRenderer pRasterRenderer = pStretchColorRasterRenderer as IRasterRenderer;
                pRasterRenderer.Raster = pRLayer.Raster;
                pRasterRenderer.Update();

                pStretchColorRasterRenderer.BandIndex = cmbBand.SelectedIndex;
                pStretchColorRasterRenderer.ColorRamp = PColorramp as IColorRamp;
                pRasterRenderer.Update();
                pRLayer.Renderer = pStretchColorRasterRenderer as IRasterRenderer;
            }


            if (pTocContral.Buddy == pMapContral.Object)
            {
                pTocContral.SetBuddyControl(pMapContral);
                pMapContral.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                pTocContral.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
            else if (pTocContral.Buddy.Equals(pSceneControl.Object))
            {
                pTocContral.SetBuddyControl(pSceneControl);
                IActiveView pActiveView = pSceneControl.Scene as IActiveView;
                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, pRLayer, null);
                pTocContral.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
        }