`
kabike
  • 浏览: 598017 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

arcgis engine C#中在地图上绘制矩形并裁切

    博客分类:
  • GIS
 
阅读更多
绘制矩形需要用到橡皮条工具 RubberBand

            ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay;

            // Constant.
            screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)
              ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit cast.
            ESRI.ArcGIS.Display.IRgbColor rgbColor = new
              ESRI.ArcGIS.Display.RgbColorClass();
            rgbColor.Red = 255;

            ESRI.ArcGIS.Display.IColor color = rgbColor; // Implicit cast.
            ESRI.ArcGIS.Display.ISimpleFillSymbol simpleFillSymbol = new
              ESRI.ArcGIS.Display.SimpleFillSymbolClass();
            simpleFillSymbol.Color = color;

            ESRI.ArcGIS.Display.ISymbol symbol = simpleFillSymbol as
              ESRI.ArcGIS.Display.ISymbol; // Dynamic cast.
            ESRI.ArcGIS.Display.IRubberBand rubberBand = new
              ESRI.ArcGIS.Display.RubberEnvelopeClass();
            ESRI.ArcGIS.Geometry.IGeometry geometry = rubberBand.TrackNew(screenDisplay,
              symbol);
            screenDisplay.SetSymbol(symbol);
            screenDisplay.DrawRectangle(geometry as ESRI.ArcGIS.Geometry.IEnvelope);
            // Dynamic cast.
            screenDisplay.FinishDrawing();


裁切代码如下,其中envelope是RubberBand工具产生的IGeometry

            String tempDirName = @"E:\tmp\ttt\bar";
            String tempFileName = Guid.NewGuid().ToString() + ".tif";
            String tempFullName = tempDirName + @"\" + tempFileName;
            ILayer pLayer = axMapControl1.get_Layer(0);
            IRasterLayer rasterLayer = (IRasterLayer)pLayer;

            IRaster pRaster = rasterLayer.Raster;

            //Initialize the Clip tool class.
            Clip clip = new Clip();
            //Set the parameters.
            clip.in_raster = pRaster;
            clip.out_raster = tempFullName;

            //The clipping envelope.
            //Comment this line out if clipping with a given dataset.
            clip.rectangle = String.Format("{0} {1} {2} {3}", envelope.XMin, envelope.YMin, envelope.XMax, envelope.YMax);

            //Initialize the geoprocessor and execute the Clip tool.
            Geoprocessor geoprocessor = new Geoprocessor();
            object outRaster = geoprocessor.Execute(clip, null);


一开始尝试使用RasterLayerExport导出特定区域的栅格,结果发现原来float型的值成了int
api上信誓旦旦说
引用
The RasterLayer property is used to set the input RasterLayer to the RasterLayerExport object; this is a required property. Normally, a raster layer is associated with a raster renderer by default. You can change the raster renderer to what you need. If you don't want to use the raster renderer to filter the pixel values during the export, remove the raster renderer from the raster layer before passing it to the RasterLayerExport object


呵呵,怎么remove the raster renderer啊,也不说清楚...差评
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics