zoukankan      html  css  js  c++  java
  • 打开栅格目录中的一个数据 创建栅格数据集

    打开栅格目录中的一个数据
     
                  IRasterDataset GetRasterCatalogItem(IRasterCatalog pCatalog, int pObjectID)
            {
                //栅格目录继承了IFeatureClass
                IFeatureClass pFeatureClass = (IFeatureClass)pCatalog;
                IRasterCatalogItem pRasterCatalogItem =
    (IRasterCatalogItem)pFeatureClass.GetFeature(pObjectID);
                return pRasterCatalogItem.RasterDataset;
            }

    创建栅格数据集
     
                  public IRasterDataset CreateRasterDataset(string pRasterFolderPath, string
    pFileName,string pRasterType,ISpatialReference pSpr )
                  {
                      
                          IRasterWorkspace2 pRasterWs = GetRasterWorkspace(pRasterFolderPath) as
    IRasterWorkspace2;
                          
                          
                          IPoint pPoint = new PointClass();
                          pPoint.PutCoords(15.0, 15.0); //设置想,x,y坐标
                          
                          int pWidth = 300; 
                          int pHeight = 300; 
                          double xCell = 30; 
                          double yCell = 30; 
                          int NumBand = 1;
     
                          IRasterDataset pRasterDataset = pRasterWs.CreateRasterDataset(pFileName,
    pRasterType, pPoint, pWidth, pHeight, xCell, yCell, NumBand, rstPixelType.PT_UCHAR, pSpr,true); 
            IRasterBandCollection pRasterBands =(IRasterBandCollection)pRasterDataset;

             IRasterBand pRasterBand = pRasterBands.Item(0);
            IRasterProps  pRasterProps = (IRasterProps)pRasterBand;
           
            pRasterProps.NoDataValue = 255;
            
            IRaster pRaster = pRasterDataset.CreateDefaultRaster();
         
            IPnt pPnt = new PntClass();
            pPnt.SetCoords(30, 30);
            IRaster2 pRaster2 = pRaster as IRaster2;
            IRasterEdit pRasterEdit = (IRasterEdit)pRaster2;
            IRasterCursor pRasterCursor = pRaster2.CreateCursorEx(pPnt);
            do
            {
                IPixelBlock3 pPixelblock = pRasterCursor.PixelBlock as IPixelBlock3;
                System.Array pixels = (System.Array)pPixelblock.get_PixelData(0);
                for (int i = 0; i < pPixelblock.Width; i++)
                    for (int j = 0; j < pPixelblock.Height; j++)
                        if (i == j)
                            pixels.SetValue(Convert.ToByte(255), i, j);
                        else
                            pixels.SetValue(Convert.ToByte((i * j + 30) / 255), i, j);
                pPixelblock.set_PixelData(0, (System.Array)pixels);

          IPnt pUpperLeft = pRasterCursor.TopLeft;
          pRasterEdit.Write(pUpperLeft, (IPixelBlock)pPixelblock);
      } while (pRasterCursor.Next());
      System.Runtime.InteropServices.Marshal.ReleaseComObject(pRasterEdit);
      
      return pRasterDataset;

    }

  • 相关阅读:
    【CodeForces 611C】New Year and Domino
    【HDU 1003】 Max Sum
    【ZOJ 3502】Contest
    【LightOJ 1422】Halloween Costumes(区间DP)
    【ZOJ 3609】Modular Inverse
    乘法逆元及其应用
    除法和取余的运算时间
    HUD3689 Infinite monkey theorem
    POJ2185 Milking Grid
    1355: [Baltic2009]Radio Transmission[循环节]
  • 原文地址:https://www.cnblogs.com/qiushuixizhao/p/3243334.html
Copyright © 2011-2022 走看看