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();
The cropping code is as follows, where envelope is the IGeometry generated by the RubberBand tool
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);
At first I tried to use RasterLayerExport to export the raster of a specific area, and found that the original float value became the int
api.
quote
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
Hehe, how to remove the raster renderer, I don't make it clear... bad review