默认头像
路人甲
路人甲
  • 注册日期2004-12-16
  • 发帖数2
  • QQ
  • 铜币116枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1097回复:1

Tin转Raster的问题,现贴出函数望大侠指错,不胜感激

楼主#
更多 发布于:2006-07-04 11:40

向各为大侠请教一下Tin转Raster的问题,下面是我用C#写的函数,转出来的Raster高程值不知为何老是范围巨大无比,完全是错误的,哎```希望有大侠能给我指出错误所在,不胜感激。

public void TintoRaster(ITinAdvanced ipT)
 {
     IGeoDataset pInTin = (IGeoDataset)ipT;
  IEnvelope pExtent;
           pExtent = pInTin.Extent;

  IPoint pOrigin;
           pOrigin = pExtent.LowerLeft;
  double x,y;
           x = pOrigin.X;
  y = pOrigin.Y;
           pOrigin.X = x - edit_viewshedCellsize * 0.5;
           pOrigin.Y = y - edit_viewshedCellsize * 0.5;

  int nCol,nRow;
  double width,height;
  width = pExtent.Width;
  height = pExtent.Height;
  nCol = (int)Math.Round((width / edit_viewshedCellsize) + 1);
  nRow = (int)Math.Round((height / edit_viewshedCellsize) + 1);

  ISpatialReference2 pSR;
  pSR = (ISpatialReference2)pInTin.SpatialReference;

  IRasterDataset pRDS;
  IWorkspaceFactory rWksFac = new RasterWorkspaceFactoryClass();
  IWorkspace wks;
  wks = rWksFac.OpenFromFile(m_OutputPath,0);

  IRasterWorkspace2 rWks = (IRasterWorkspace2)wks;

  int numbands = 1;
  //try
  //{
  pRDS = rWks.CreateRasterDataset("tempTtoR","GRID",pOrigin,nCol,nRow,edit_viewshedCellsize,edit_viewshedCellsize,numbands,rstPixelType.PT_LONG,pSR,true);
  //}
  //catch
  //{
      //return;
  //}

  //下面是调用GetRawPixels函数
  IRasterBandCollection pBandCollection = (IRasterBandCollection)pRDS;
  IRasterBand pRasterBand;
           pRasterBand = pBandCollection.Item(0);
  IRawPixels pRawPixels = (IRawPixels)pRasterBand;

  object pCache;
  pCache = pRawPixels.AcquireCache();

  ITinSurface pTinSurf = (ITinSurface)ipT;
  IRasterProps pRasterProps = (IRasterProps)pRawPixels;

  object nodataInt;
  nodataInt = pRasterProps.NoDataValue;

//   object nodataFloat;
//   double dZMin;
//   dZMin = pExtent.ZMin;
//   float a;
//   a = (float)(dZMin - 1);
//            nodataFloat = (object)a;
//            pRasterProps.NoDataValue = nodataFloat;

  int mxblk_x = 2048;
  int mxblk_y = 2048;

  if(nCol < mxblk_x) mxblk_x = nCol;
  if(nRow < mxblk_y) mxblk_y = nRow;

  IPnt pBlockSize = new DblPntClass();
  IPnt pOffset = new DblPntClass();
           pBlockSize.X = mxblk_x;
  pBlockSize.Y = mxblk_y;

  IPixelBlock3 pPixelBlock;
           pPixelBlock = (IPixelBlock3)pRawPixels.CreatePixelBlock(pBlockSize);
           
  object blockArray;
  //blockArray = pPixelBlock.get_SafeArray(0);
  blockArray = pPixelBlock.get_PixelDataByRef(0);
 
           IPoint blkOrigin = new PointClass();
  int iRowOffset;
  int iColOffset;
 
  for(iRowOffset = 0;iRowOffset < nRow;iRowOffset += mxblk_y)
  {
   for(iColOffset = 0;iColOffset < nCol;iColOffset += mxblk_x)
   {
    if((nCol - iColOffset) < mxblk_x)
    {
        pBlockSize.X = nCol - iColOffset;
                       pPixelBlock = (IPixelBlock3)pRawPixels.CreatePixelBlock(pBlockSize);
     blockArray = pPixelBlock.get_PixelDataByRef(0);
    }
                   blkOrigin.X = pOrigin.X + iColOffset * edit_viewshedCellsize + edit_viewshedCellsize * 0.5;
                   blkOrigin.Y = pOrigin.Y + (nRow - iRowOffset) * edit_viewshedCellsize - edit_viewshedCellsize * 0.5;
                   pTinSurf.QueryPixelBlock(blkOrigin.X,blkOrigin.Y,edit_viewshedCellsize,edit_viewshedCellsize,esriRasterizationType.esriElevationAsRaster,nodataInt,blockArray);
                   pOffset.X = iColOffset;
                   pOffset.Y = iRowOffset;
                   pRawPixels.Write(pOffset,(IPixelBlock)pPixelBlock);
   }
   bool reset = false;
   if(pBlockSize.X != mxblk_x)
   {
       pBlockSize.X = mxblk_x;
    reset = true;
   }
   if((nRow - iRowOffset) < mxblk_y)
   {
       pBlockSize.Y = nRow - iRowOffset;
                   reset = true;
   }
   if(reset)
   {
    pPixelBlock = (IPixelBlock3)pRawPixels.CreatePixelBlock(pBlockSize);
    blockArray = pPixelBlock.get_PixelDataByRef(0);
   }
  }
  //x = pOrigin.X;
  //y = pOrigin.Y;
           //pOrigin.X = x + edit_viewshedCellsize * 0.5;
           //pOrigin.Y = y + edit_viewshedCellsize * nRow - edit_viewshedCellsize * 0.5;

  //x = pOrigin.X;
  //y = pOrigin.Y;
           //pTinSurf.QueryPixelBlock(x,y,edit_viewshedCellsize,edit_viewshedCellsize,esriRasterizationType.esriElevationAsRaster,nodataFloat,val);

  //IPnt pOffset = new DblPntClass();
           //pOffset.X = 0;
  //pOffset.Y = 0;
           //pRawPixels.Write(pOffset,pPixelBlock);
           pRawPixels.ReturnCache(pCache);
  pCache = null;


 }

喜欢0 评分0
默认头像
路人甲
路人甲
  • 注册日期2004-07-08
  • 发帖数11
  • QQ101
  • 铜币222枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2007-03-26 14:03

有没有结果阿,那个巨大的value的应该是double float的值,可能根本就没有得到像素值吧

asdfdf
举报 回复(0) 喜欢(0)     评分
默认头像

返回顶部