麻辣GIS微信平台

更多 GIS 干货

微信关注不错过

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 开发手册

相关阅读

麻辣GIS-Sailor

作者:

GIS爱好者,学GIS,更爱玩GIS。

声明

1.本文所分享的所有需要用户下载使用的内容(包括但不限于软件、数据、图片)来自于网络或者麻辣GIS粉丝自行分享,版权归该下载资源的合法拥有者所有,如有侵权请第一时间联系本站删除。

2.下载内容仅限个人学习使用,请切勿用作商用等其他用途,否则后果自负。

手机阅读
公众号关注
知识星球
手机阅读
麻辣GIS微信公众号关注
最新GIS干货
关注麻辣GIS知识星球
私享圈子

留言板(小编看到第一时间回复)