程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> Arcgis中將柵格數據導出成Txt格式

Arcgis中將柵格數據導出成Txt格式

編輯:C#入門知識

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


        }

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved