static void LoadDirToRasterDataset(string outRasterDataset, string inputDir)
        {
            try
            {
                //Initialize GeoProcessor
                Geoprocessor geoProcessor = new Geoprocessor();

                //Mosaic the works
                WorkspaceToRasterDataset wsToRasDs = new WorkspaceToRasterDataset();

                //Set input folder
                wsToRasDs.in_workspace = inputDir;

                //Set target GDB raster dataset
                wsToRasDs.in_raster_dataset = outRasterDataset;

                //Include rasters in the subdirectories
                wsToRasDs.include_subdirectories = "INCLUDE_SUBDIRECTORIES";

                //Set mosaic mode
                wsToRasDs.mosaic_type = "LAST";

                //Set colormap mode
                wsToRasDs.colormap = "MATCH";

                //Set background value
                wsToRasDs.background_value = 0;

                //Execute the tool to load rasters in the directory to raster dataset
                geoProcessor.Execute(wsToRasDs, null);
                ReturnMessages(geoProcessor);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }
        }
        static void LoadDirToRasterDataset(string outRasterDataset, string inputDir)
        {
            try
            {
                //Initialize GeoProcessor
                Geoprocessor geoProcessor = new Geoprocessor();

                //Mosaic the works
                WorkspaceToRasterDataset wsToRasDs = new WorkspaceToRasterDataset();

                //Set input folder
                wsToRasDs.in_workspace = inputDir;

                //Set target GDB raster dataset
                wsToRasDs.in_raster_dataset = outRasterDataset;

                //Include rasters in the subdirectories
                wsToRasDs.include_subdirectories = "INCLUDE_SUBDIRECTORIES";

                //Set mosaic mode
                wsToRasDs.mosaic_type = "LAST";

                //Set colormap mode
                wsToRasDs.colormap = "MATCH";

                //Set background value
                wsToRasDs.background_value = 0;

                //Execute the tool to load rasters in the directory to raster dataset
                geoProcessor.Execute(wsToRasDs, null);
                ReturnMessages(geoProcessor);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }
        }
        private string ExportPages(IActiveView docActiveView, int iDPI, string filename, enumExportType exportType, double paperWidth, double paperHeight, int blockCount)
        {
            string filepath = filename.Substring(0, filename.LastIndexOf("\\"));
            string NameExt = System.IO.Path.GetFileName(filename);
            if (docActiveView is IPageLayout)
            {
            double width = 0, height = 0;   //实际长宽
            //计算分页地图大小 paperWidth,paperHeight
            //分块数量 blockCount
            //计算分页图片大小 iWidth,iHeight
            #region 计算出图参数
            var pPageLayout = docActiveView as IPageLayout;
            pPageLayout.Page.QuerySize(out width, out height);
            IUnitConverter pUnitCon = new UnitConverterClass();
            switch (exportType)
            {
                case enumExportType.byPaperSize:
                    if (paperWidth <= 0 || paperHeight <= 0)
                    { paperWidth = 210; paperHeight = 297; }
                    paperWidth = pUnitCon.ConvertUnits(paperWidth, esriUnits.esriMillimeters, pPageLayout.Page.Units);
                    paperHeight = pUnitCon.ConvertUnits(paperHeight, esriUnits.esriMillimeters, pPageLayout.Page.Units);
                    bool bW = (width > paperWidth + 0.001) ? true : false;
                    bool bH = (height > paperHeight + 0.001) ? true : false;
                    blockCount = (bW && bH) ? 4 : 1;
                    break;
                case enumExportType.byBlockCount:
                default:
                    if (blockCount < 1) blockCount = 1;
                    paperWidth = width / blockCount;
                    paperHeight = height / blockCount;
                    break;
            }
            int iWidth = (int)(pUnitCon.ConvertUnits(paperWidth, pPageLayout.Page.Units, esriUnits.esriInches) * iDPI);
            int iHeight = (int)(pUnitCon.ConvertUnits(paperHeight, pPageLayout.Page.Units, esriUnits.esriInches) * iDPI);
            #endregion

            if (System.IO.File.Exists(filename))
            {
                var pWS = OpenWorkspace(filename, enumWsFactoryType.Raster) as IRasterWorkspace;
                var pRDs = pWS.OpenRasterDataset(NameExt);
                var pDS = pRDs as IDataset;
                pDS.Delete();
            }

            if (blockCount > 1)
            {
                #region 创建子目录,获得扩展名
                string NameNoExt = System.IO.Path.GetFileNameWithoutExtension(filename);
                string sExt = System.IO.Path.GetExtension(filename).ToLower();
                //创建子目录
                string subPath = filename.Substring(0, filename.LastIndexOf("."));
                if (System.IO.Directory.Exists(subPath))
                {
                    System.IO.Directory.Delete(subPath, true);
                }
                try
                {
                    System.IO.Directory.CreateDirectory(subPath);
                    if (!System.IO.Directory.Exists(subPath))
                    {
                        subPath = subPath + "_1";
                        System.IO.Directory.CreateDirectory(subPath);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    subPath = subPath + "_1";
                    System.IO.Directory.CreateDirectory(subPath);
                }

                //worldfile扩展名
                string worldfileExt = "." + sExt[1].ToString() + sExt[sExt.Length - 1].ToString() + "w";
                #endregion

                #region 分页输出
                int index = 0;
                int minX = 0, maxY = iHeight;
                double w, h = 0;
                string t_name = subPath + @"\" + NameNoExt + "_";
                IExport docExport = CreateExport(filename, 1);
                IEnvelope pEnv1 = new EnvelopeClass();
                while (h < height - 0.0001)
                {
                    w = 0;
                    minX = 0;
                    while (w < width - 0.0001)
                    {
                        pEnv1.XMin = w;
                        pEnv1.YMin = h;
                        pEnv1.XMax = w + paperWidth;
                        pEnv1.YMax = h + paperHeight;
                        index++;

                        label1.Text += ".";
                        Application.DoEvents();

                        //output输出
                        ActiveViewOutput(docActiveView, iDPI, iWidth, iHeight, pEnv1, t_name + index.ToString() + sExt, docExport);
                        //写入worldfile
                        WriteWorldfile(t_name + index.ToString() + worldfileExt, 1, 0, 0, -1, minX, maxY);
                        w += paperWidth;
                        minX += iWidth;
                    }
                    h += paperHeight;
                    maxY += iHeight;
                }
                #endregion

                #region 合并栅格
                //设置坐标参考
                var pRasterWS = OpenWorkspace(subPath, enumWsFactoryType.Raster);
                ISpatialReferenceFactory2 pSrF = new SpatialReferenceEnvironmentClass();
                var pSR = pSrF.CreateSpatialReference(3857);
                var pEnumDS = pRasterWS.get_Datasets(esriDatasetType.esriDTRasterDataset);
                var pDS = pEnumDS.Next();
                while (pDS != null)
                {
                    var GeoSchEdit = pDS as IGeoDatasetSchemaEdit;
                    if (GeoSchEdit.CanAlterSpatialReference)
                        GeoSchEdit.AlterSpatialReference(pSR);
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(pDS);
                    pDS = pEnumDS.Next();
                }
                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(pRasterWS);

                //saveas时占用很大内存且不释放,使用GP工具
                //怎么不创建金字塔和头文件??
                Geoprocessor geoprocessor = new Geoprocessor();
                try
                {
                    CreateRasterDataset createRD = new CreateRasterDataset();
                    createRD.cellsize = 1;
                    createRD.number_of_bands = 3;
                    createRD.out_path = filepath;
                    createRD.out_name = NameExt;
                    createRD.pyramids = "NONE";
                    createRD.compression = "NONE";
                    geoprocessor.Execute(createRD, null);

                    WorkspaceToRasterDataset MosaicToRaster = new WorkspaceToRasterDataset();
                    MosaicToRaster.in_workspace = subPath;
                    MosaicToRaster.in_raster_dataset = filename;
                    geoprocessor.Execute(MosaicToRaster, null);
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc.Message);
                    for (int i = 0; i < geoprocessor.MessageCount; i++)
                    {
                        string abc = geoprocessor.GetMessage(i);
                        Console.WriteLine(abc);
                    }

                }
                #endregion

                return subPath;
            }
            else
            {
                Export10Plus(docActiveView, filename, iDPI, 0, 0, null);
                return "";
            }
            }
            else      //map
            {
            return "";
            }
        }