AE遍歷某個範圍內的柵格值(高程值)
阿新 • • 發佈:2019-01-05
IRasterLayer pDEMRLayer = axMapControl1.get_Layer(1) as IRasterLayer; IRaster pDEMR = pDEMRLayer.Raster; IRasterProps pRasterProps = (IRasterProps)(pDEMRLayer.Raster); //儲存每個柵格的X座標和Y座標 double blockX = pRasterProps.MeanCellSize().X; double blockY = pRasterProps.MeanCellSize().Y; //柵格資料左上角柵格的空間座標 double Xm = pRasterProps.Extent.XMin + blockX / 2; double Ym = pRasterProps.Extent.YMin + blockX / 2; int dHeight = pRasterProps.Height;//當前柵格資料集的行數 int dWidth = pRasterProps.Width; //當前柵格資料集的列數 IPnt pnt = new PntClass(); //讀取柵格資訊 pnt.SetCoords(0, 0);//0,0取值視窗的起始位置在原柵格資料上的位置 IPnt pntSize = new PntClass(); pntSize.SetCoords(dWidth, dHeight);//設定取值視窗的行列,注意這裡是先列後行 IPixelBlock pixelBlock = pDEMR.CreatePixelBlock(pntSize);//生成畫素塊 pDEMR.Read(pnt, pixelBlock); List<IPoint> depthList = new List<IPoint>(); for (int i = 0; i < dHeight; i++) for (int j = 0; j < dWidth; j++) { object obj = Convert.ToDouble(pixelBlock.GetVal(0, i, j)); }