ArcGIS Engine 10 开发手册(4-14)创建栅格数据集

本文目录
  • 正文

在ArcGIS Engine中可以直接创建栅格数据集。这里做为示例,也封装了一个方法,代码如下:

创建栅格数据集代码

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

  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 & lt; pPixelblock.Width; i++)

      for (int j = 0; j & lt; 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;
}

运行结果

ArcGIS Engine 10 开发手册全集

ArcGIS Engine 10 开发手册全集: ArcGIS Engine 10 开发手册

如您有疑问,可在文末留言,或到QQ群提问。

本站QQ群:291616564 麻辣GIS

微信公众号:malagis,扫描右边二维码直接关注。

微信捐助麻辣GIS 支付宝捐助麻辣GIS

如果本文对您有所帮助,欢迎对我们团队进行打赏捐助,让我们在传播3S的路上可以走得更远。


作者:,GIS爱好者。
分享本文,请您带上本文链接

发表评论