Print? IWorkspaceFactory wf = new RasterWorkspaceFactory ();
IWorkspace ws = wf. OpenFromFile (path, 0 );
IRasterWorkspace rastWork = (IRasterWorkspace) ws;
IRasterDataset3 rds = (IRasterDataset3) rastWork. OpenRasterDataset (tmp + "2.img ");
IRasterBandCollection rasterbands = (IRasterBandCollection) rds;
IRaster raster = rds. CreateFullRaster ();
RasterToText2 (raster, path + "\ 123.txt ");
Private void RasterToText2 (IRaster raster, string txtFile)
{
Var datas = RasterArray (raster );
StreamWriter sw = new StreamWriter (txtFile, false, Encoding. UTF8 );
For (int I = 0; I <datas. GetLength (0); I ++)
{
For (int j = 0; j <datas. GetLength (1); j ++)
{
Sw. Write (datas. GetValue (I, j). ToString () + "");
}
Sw. WriteLine ();
}
Sw. Close ();
}
Public static System. Array RasterArray (IRaster raster)
{
IRasterProps props = (IRasterProps) raster;
// Novalue = props. NoDataValue;
IPnt pBlockSize = new PntClass ();
PBlockSize. SetCoords (double) props. Width, (double) props. Height );
IRaster2 raster2 = (IRaster2) raster;
IPixelBlock pixelBlock = raster2.CreateCursorEx (pBlockSize). PixelBlock;
PBlockSize. SetCoords (0.0, 0.0 );
Raster. Read (pBlockSize, pixelBlock );
IPixelBlock3 block2 = (IPixelBlock3) pixelBlock;
Return (System. Array) block2.get _ PixelData (0 );
}
IWorkspaceFactory wf = new RasterWorkspaceFactory ();
IWorkspace ws = wf. OpenFromFile (path, 0 );
IRasterWorkspace rastWork = (IRasterWorkspace) ws;
IRasterDataset3 rds = (IRasterDataset3) rastWork. OpenRasterDataset (tmp + "2.img ");
IRasterBandCollection rasterbands = (IRasterBandCollection) rds;
IRaster raster = rds. CreateFullRaster ();
RasterToText2 (raster, path + "\ 123.txt ");
Private void RasterToText2 (IRaster raster, string txtFile)
{
Var datas = RasterArray (raster );
StreamWriter sw = new StreamWriter (txtFile, false, Encoding. UTF8 );
For (int I = 0; I <datas. GetLength (0); I ++)
{
For (int j = 0; j <datas. GetLength (1); j ++)
{
Sw. Write (datas. GetValue (I, j). ToString () + "");
}
Sw. WriteLine ();
}
Sw. Close ();
}
Public static System. Array RasterArray (IRaster raster)
{
IRasterProps props = (IRasterProps) raster;
// Novalue = props. NoDataValue;
IPnt pBlockSize = new PntClass ();
PBlockSize. SetCoords (double) props. Width, (double) props. Height );
IRaster2 raster2 = (IRaster2) raster;
IPixelBlock pixelBlock = raster2.CreateCursorEx (pBlockSize). PixelBlock;
PBlockSize. SetCoords (0.0, 0.0 );
Raster. Read (pBlockSize, pixelBlock );
IPixelBlock3 block2 = (IPixelBlock3) pixelBlock;
Return (System. Array) block2.get _ PixelData (0 );
}