예제 #1
0
 private void btnRasterOK_Click_1(object sender, EventArgs e)
 {
     try
     {
         IRasterStretchColorRampRenderer rasStreRen = new RasterStretchColorRampRendererClass();
         IRasterRenderer rasRen = rasStreRen as IRasterRenderer;
         rasRen.Raster = rasterlayer.Raster;
         rasRen.Update();
         rasStreRen.BandIndex = cmbBand.SelectedIndex;
         pListRamp            = style.pListRamp;
         rasStreRen.ColorRamp = (IColorRamp)pListRamp[cmbsymRaster.SelectedIndex];
         rasRen.Update();
         rasterlayer.Renderer = rasStreRen as IRasterRenderer;
         IRasterStretch2 stretch = rasStreRen as IRasterStretch2;
         stretch.BackgroundValue = 0;
         stretch.Background      = true;
         stretch.BackgroundColor = RasterRender.GET(255, 255, 255) as IColor;
         //axmapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
         axmapcontrol.Refresh();
         axtoccontrol.Update();
         axmapcontrol.Extent = rasterlayer.AreaOfInterest;
     }
     catch (Exception ec)
     {
         MessageBox.Show(ec.Message);
     }
 }
예제 #2
0
 private void btn_OkStretch_Click(object sender, EventArgs e)
 {
     try
     {
         string RasterName = cbb_RasterLayersStretch.SelectedItem.ToString();
         rasterlayer = GetRasterLayer(RasterName);
         IRasterStretchColorRampRenderer rasStreRen = new RasterStretchColorRampRendererClass();
         IRasterRenderer rasRen = rasStreRen as IRasterRenderer;
         rasRen.Raster = rasterlayer.Raster;
         rasRen.Update();
         rasStreRen.BandIndex = cbb_BandStretch.SelectedIndex;
         pListRamp            = style.pListRamp;
         rasStreRen.ColorRamp = (IColorRamp)pListRamp[cbbs_ColorStretch.SelectedIndex];
         rasRen.Update();
         rasterlayer.Renderer = rasStreRen as IRasterRenderer;
         IRasterStretch2 stretch = rasStreRen as IRasterStretch2;
         stretch.BackgroundValue = 0;
         stretch.Background      = true;
         stretch.BackgroundColor = RasterRender.GET(255, 255, 255) as IColor;
         axmapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
         axtoccontrol.Update();
         axmapcontrol.Extent = rasterlayer.AreaOfInterest;
         this.Close();
     }
     catch (Exception ec)
     {
         MessageBox.Show(ec.Message);
     }
 }
예제 #3
0
 public static bool LoadRasterData(string filePath, AxMapControl mapControl)
 {
     try
     {
         var factory = new RasterWorkspaceFactory();
         IRasterWorkspace rasterWorkspace = factory.OpenFromFile(System.IO.Path.GetDirectoryName(filePath), 0) as IRasterWorkspace;
         var            fileName          = System.IO.Path.GetFileName(filePath);
         IRasterDataset rasterDataset     = rasterWorkspace.OpenRasterDataset(fileName);
         if (rasterDataset == null)
         {
             return(false);
         }
         IRasterLayer rasterLayer = new RasterLayer();
         rasterLayer.CreateFromDataset(rasterDataset);
         #region  影像去黑边
         IRasterRGBRenderer2 rasterRGBRender = rasterLayer.Renderer as IRasterRGBRenderer2;
         IRasterStretch2     pRasterStretch2 = rasterRGBRender as IRasterStretch2;
         double[]            value           = new double[3] {
             0.0, 0.0, 0.0
         };
         pRasterStretch2.BackgroundValue = value;
         pRasterStretch2.Background      = true;
         #endregion
         mapControl.AddLayer(rasterLayer, mapControl.LayerCount);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
예제 #4
0
        private void btnRasterOK_Click(object sender, EventArgs e)
        {
            switch (tabControl1.SelectedIndex)
            {
            case 0:
                try
                {
                    IRasterStretchColorRampRenderer rasStreRen = new RasterStretchColorRampRendererClass();
                    IRasterRenderer rasRen = rasStreRen as IRasterRenderer;
                    rasRen.Raster = rasterlayer.Raster;
                    rasRen.Update();
                    rasStreRen.BandIndex = cmbBand.SelectedIndex;
                    pListRamp            = style.pListRamp;
                    rasStreRen.ColorRamp = (IColorRamp)pListRamp[cmbsymRaster.SelectedIndex];
                    rasRen.Update();
                    rasterlayer.Renderer = rasStreRen as IRasterRenderer;
                    IRasterStretch2 stretch = rasStreRen as IRasterStretch2;
                    stretch.BackgroundValue = 0;
                    stretch.Background      = true;
                    stretch.BackgroundColor = RasterRender.GET(255, 255, 255) as IColor;
                    axmapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                    axtoccontrol.Update();
                    axmapcontrol.Extent = rasterlayer.AreaOfInterest;
                    this.Close();
                }
                catch (Exception ec)
                {
                    MessageBox.Show(ec.Message);
                }
                break;

            case 1:
                RasterRender render = new RasterRender();
                pListRamp = style.pListRamp;
                render.RasterClassify(rasterlayer, cmbClassifyMethod.SelectedValue.ToString(), Convert.ToInt32(cmbClassifyCount.SelectedValue), (IColorRamp)pListRamp[cmbSymClassify.SelectedIndex]);
                axmapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                axtoccontrol.Update();
                axmapcontrol.Extent = rasterlayer.AreaOfInterest;
                break;
            }
        }
예제 #5
0
        public static IRasterRenderer CreateESRIDefinedContinuousRenderer(GCDConsoleLib.Raster gRaster, int iClassCount, string sColorRampName, bool bInvert = false)
        {
            try
            {
                gRaster.ComputeStatistics();
                decimal maxValue        = gRaster.GetStatistics()["max"];
                int     iRound          = GetMagnitude(maxValue);
                double  maxValueRounded = Math.Round((double)maxValue, Math.Abs(iRound));

                RasterStretchColorRampRenderer stretchRenderer = new RasterStretchColorRampRendererClass();
                IRasterRenderer rasterRenderer = (IRasterRenderer)stretchRenderer;
                IRasterDataset  rasterDataset  = ArcMapUtilities.GetRasterDataset(gRaster);
                IRaster         raster         = rasterDataset.CreateDefaultRaster();
                rasterRenderer.Raster = raster;
                IColorRamp               pColorRamp       = null;
                IStyleGalleryItem        pStyleItem       = GetESRIStyleColorRamp(out pColorRamp, sColorRampName);
                IRasterRendererColorRamp pRenderColorRamp = (IRasterRendererColorRamp)rasterRenderer;
                pRenderColorRamp.ColorScheme = pStyleItem.Name;
                IRasterStretchMinMax pStretchInfo = (IRasterStretchMinMax)stretchRenderer;
                pStretchInfo.CustomStretchMin       = 0;
                pStretchInfo.CustomStretchMax       = maxValueRounded;
                pStretchInfo.UseCustomStretchMinMax = true;
                stretchRenderer.LabelHigh           = maxValueRounded.ToString();
                stretchRenderer.LabelLow            = "0.0";
                if (bInvert)
                {
                    IRasterStretch2 pStretch = (IRasterStretch2)stretchRenderer;
                    pStretch.Invert = true;
                }

                rasterRenderer.Update();
                return(rasterRenderer);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }
예제 #6
0
        public static IRasterRenderer CreateContinuousRenderer(Raster gRaster, IColorRamp pColorRamp, bool bInvert = false)
        {
            try
            {
                gRaster.ComputeStatistics();
                Dictionary <string, decimal> stats = gRaster.GetStatistics();
                double rMin = (double)stats["min"];
                double rMax = (double)stats["max"];

                RasterStretchColorRampRenderer stretchRenderer = new RasterStretchColorRampRenderer();
                IRasterRenderer rasterRenderer = (IRasterRenderer)stretchRenderer;
                IRasterDataset  rasterDataset  = ArcMapUtilities.GetRasterDataset(gRaster);
                IRaster         raster         = rasterDataset.CreateDefaultRaster();
                rasterRenderer.Raster = raster;

                IRasterRendererColorRamp pRenderColorRamp = (IRasterRendererColorRamp)rasterRenderer;
                pRenderColorRamp.ColorRamp = pColorRamp;
                int iRound = GetMagnitude(rMin);
                stretchRenderer.LabelHigh = Math.Round(rMax, Math.Abs(iRound)).ToString();
                stretchRenderer.LabelLow  = Math.Round(rMin, Math.Abs(iRound)).ToString();

                if (bInvert)
                {
                    IRasterStretch2 pStretch = (IRasterStretch2)stretchRenderer;
                    pStretch.Invert = true;
                }

                rasterRenderer.Update();
                return(rasterRenderer);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }