コード例 #1
0
ファイル: Aspect.cs プロジェクト: dearLhz/MyDatapreMenu
        private void btnGO_Click(object sender, EventArgs e)
        {
            string strInFileName;
            string strOutFileName;
            int    startX, endX;
            string strOutDir;

            try
            {
                if (bDataPath == true)
                {
                    strInFileName  = txtOutPath.Text;
                    strOutDir      = strInFileName.Substring(0, strInFileName.LastIndexOf("\\"));
                    startX         = strInFileName.LastIndexOf("\\");
                    endX           = strInFileName.Length;
                    strOutFileName = strInFileName.Substring(startX + 1, endX - startX - 1);
                }
                else
                {
                    strOutDir      = txtOutPath.Text;
                    strOutFileName = "aspect";
                }
                if (File.Exists(strOutDir + "\\" + strOutFileName + ".aux") == true)
                {
                    MessageBox.Show("文件" + strOutFileName + "已经存在,请重新命名!");
                    return;
                }
                if (m_pRasterLyr != null)
                {
                    double       dCellSize        = Convert.ToDouble(txtCellSize.Text);
                    ISurfaceOp   pRasterSurfaceOp = new RasterSurfaceOpClass();
                    IRaster      pInRaster        = m_pRasterLyr.Raster;
                    IRaster      pOutRaster       = null;
                    IRasterLayer pRasterLayer     = new RasterLayerClass();
                    IGeoDataset  pGeoDs           = pRasterSurfaceOp.Aspect(pInRaster as IGeoDataset);
                    pOutRaster = pGeoDs as IRaster;
                    IRasterLayer pOutRasterLayer = new RasterLayerClass();
                    pOutRasterLayer.CreateFromRaster(pOutRaster);
                    pOutRasterLayer.Name = strOutFileName;
                    IWorkspaceFactory     pWSF        = new RasterWorkspaceFactoryClass();
                    IWorkspace            pRWS        = pWSF.OpenFromFile(strOutDir, 0);
                    IRasterBandCollection pRasBandCol = (IRasterBandCollection)pGeoDs;
                    pRasBandCol.SaveAs(strOutFileName, pRWS, "GRID");//"IMAGINE Image"
                    pOutRasterLayer      = UtilityFunction.SetStretchRenderer(pOutRasterLayer.Raster);
                    pOutRasterLayer.Name = strOutFileName;
                    pMap.AddLayer(pOutRasterLayer);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }