/// <summary>
 /// 根据指定的影像路径显示影像
 /// </summary>
 /// <param name="imgPath">影像路径</param>
 public void DisplayImg(string imgPath)
 {
     if (File.Exists(imgPath))
     {
         //获取文件路径和文件名
         string imgDirectory = Path.GetDirectoryName(imgPath);
         string imgFileName  = Path.GetFileName(imgPath);
         //
         IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactoryClass();
         IRasterWorkspace  pRasterWorkspace  = pWorkspaceFactory.OpenFromFile(imgDirectory, 0) as IRasterWorkspace;
         if (pRasterWorkspace != null)
         {
             IRasterDataset  pRasterDataset = pRasterWorkspace.OpenRasterDataset(imgFileName);
             IRasterPyramid3 prPyramid3     = pRasterDataset as IRasterPyramid3;
             if (prPyramid3 != null && !prPyramid3.Present)
             {
                 //进度条怎么写
                 MessageBox.Show("正在建立金字塔!");
                 prPyramid3.BuildPyramid(5, rstResamplingTypes.RSP_BilinearInterpolation);
                 MessageBox.Show("完成建立金字塔!");
             }
             IRasterLayer rasterLayer = new RasterLayerClass();
             rasterLayer.CreateFromDataset(pRasterDataset);
             rasterLayer.Name = Path.GetFileNameWithoutExtension(imgPath);
             this._pMap.AddLayer(rasterLayer);
         }
     }
     else
     {
         MessageBox.Show("指定的影像路径" + imgPath + "无效!");
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 加载数据集
        /// </summary>
        /// <param name="workspace">数据集所在工作空间</param>
        /// <param name="mapControl">要加载的地图控件</param>
        public void AddAllDataset(IWorkspace workspace, AxMapControl mapControl)
        {
            IEnumDataset enumDataset = workspace.get_Datasets(esriDatasetType.esriDTAny);

            enumDataset.Reset();
            IDataset dataset;

            while ((dataset = enumDataset.Next()) != null)
            {
                if (dataset is IFeatureDataset)     //要素数据集
                {
                    IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
                    IFeatureDataset   featureDataset   = featureWorkspace.OpenFeatureDataset(dataset.Name);
                    IEnumDataset      enumDatasetSub   = featureDataset.Subsets;
                    enumDatasetSub.Reset();
                    IDataset datasetSub;
                    while ((datasetSub = enumDatasetSub.Next()) != null)
                    {
                        if (datasetSub is FeatureClass)
                        {
                            IFeatureLayer featureLayer = new FeatureLayerClass();
                            featureLayer.FeatureClass = featureWorkspace.OpenFeatureClass(datasetSub.Name);
                            if (featureLayer.FeatureClass != null)
                            {
                                featureLayer.Name = featureLayer.FeatureClass.AliasName;
                                mapControl.AddLayer(featureLayer);
                            }
                        }
                    }
                }
                else if (dataset is IFeatureClass)  //要素类
                {
                    IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
                    IFeatureClass     featureClass     = featureWorkspace.OpenFeatureClass(dataset.Name);
                    IFeatureLayer     featureLayer     = new FeatureLayerClass();
                    featureLayer.FeatureClass = featureClass;
                    featureLayer.Name         = featureClass.AliasName;
                    mapControl.AddLayer(featureLayer);
                }
                else if (dataset is IRasterDataset) //栅格数据集
                {
                    IRasterWorkspaceEx rasterWorkspace = (IRasterWorkspaceEx)workspace;
                    IRasterDataset     rasterDataset   = rasterWorkspace.OpenRasterDataset(dataset.Name);
                    IRasterPyramid3    rasPyramid      = rasterDataset as IRasterPyramid3;
                    if (rasPyramid != null)
                    {
                        if (!rasPyramid.Present)
                        {
                            rasPyramid.Create();
                        }
                    }
                    IRasterLayer rasterLayer = new RasterLayerClass();
                    rasterLayer.CreateFromDataset(rasterDataset);
                    ILayer layer = rasterLayer as ILayer;
                    mapControl.AddLayer(layer, 0);
                }
            }
            mapControl.ActiveView.Refresh();
        }
Esempio n. 3
0
        public override void OnDblClick()
        {
            IMapControl3 pMapCtrl = ClsGlobal.GetMapControl(m_hookHelper);

            if (pMapCtrl == null)
            {
                if (m_NewPolygonFeedback != null)
                {
                    m_NewPolygonFeedback.Stop();
                    m_NewPolygonFeedback = null;
                    return;
                }
            }
            IGeometry pGeometry = m_NewPolygonFeedback.Stop();

            m_NewPolygonFeedback = null;
            if (pGeometry == null)
            {
                return;
            }

            m_pClipPolygon = pGeometry as IPolygon;
            double dbNoDataValue = m_pFrmSetRasterNoDataValue.NoDataValue;

            //获取到无效值区域、无效值、栅格数据之后,开始设置
            ClsSetRasterRegionToDataValue pSetRasterToNoDataValue = new ClsSetRasterRegionToDataValue(m_pRasterLayer.Raster, m_pClipPolygon, dbNoDataValue);

            if (!pSetRasterToNoDataValue.SetRegionToNoDataValue())
            {
                MessageBox.Show("设置无效值出错!");
            }
            else
            {
                //MessageBox.Show("设置无效值成功!");
                //重新加载栅格数据
                try
                {
                    IRaster2        pSrcRaster2        = m_pRasterLayer.Raster as IRaster2;
                    IRasterDataset  pDstRasterDataset  = pSrcRaster2.RasterDataset;
                    IRasterPyramid3 pDstRasterPyramid3 = pDstRasterDataset as IRasterPyramid3;
                    if (pDstRasterPyramid3.Present)
                    {
                        IDataLayer2 pDataLayer = m_pRasterLayer as IDataLayer2;
                        pDataLayer.Disconnect();
                        pDstRasterPyramid3.DeletePyramid();
                        pDstRasterPyramid3.Create();
                        m_pRasterLayer.CreateFromDataset(pDstRasterDataset);
                    }

                    IMapControl3 pMapControl3 = ClsGlobal.GetMapControl(m_hookHelper);
                    pMapControl3.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            base.OnDblClick();
        }
Esempio n. 4
0
        /// <summary>
        /// 是否存在金字塔
        /// </summary>
        /// <param name="rasterFilePath">栅格文件路径</param>
        /// <returns></returns>
        public static bool IsExistRasterPyramid(string rasterFilePath)
        {
            IRasterDataset pRasterDataset = GetRasterDataset(rasterFilePath);
            //影像金字塔判断与创建
            IRasterPyramid3 pRasPyrmid = pRasterDataset as IRasterPyramid3;

            if (pRasPyrmid == null)
            {
                return(false);
            }
            return(pRasPyrmid.Present);
        }
Esempio n. 5
0
        private void button2_Click(object sender, EventArgs e)
        {
            //打开矢量文件
            OpenFileDialog openfiledialog = new OpenFileDialog();

            openfiledialog.CheckFileExists = true;
            openfiledialog.Title           = "打开文件";
            openfiledialog.Filter          = "文件(*.*)|*.bmp;*.tif;*jpg;*.img|(*.bmp)|*.bmp|(*.tif)|*.tif|(*.jpg)|*.jpg|(*.img)|*.img|(*.shp)|*.shp";
            openfiledialog.ShowDialog();

            String fullpath = openfiledialog.FileName;

            if (fullpath == "")
            {
                return;
            }
            String path = System.IO.Path.GetDirectoryName(fullpath);
            //获取文件名
            String filename = System.IO.Path.GetFileName(fullpath);
            //文件名之前的路径名
            int    index        = fullpath.LastIndexOf("\\");
            string filePathName = fullpath.Substring(0, index);
            //获取后缀名
            string aLastName = fullpath.Substring(fullpath.LastIndexOf(".") + 1, (fullpath.Length - fullpath.LastIndexOf(".") - 1));

            if (aLastName == "shp")
            {
                axMapControl1.AddShapeFile(filePathName, filename);
                axMapControl1.ActiveView.Refresh();
            }
            else
            {
                //打开栅格文件
                IWorkspaceFactory pWorkspacefactory = new RasterWorkspaceFactory();                 //创建工作空间工厂
                IWorkspace        pWorkspace        = pWorkspacefactory.OpenFromFile(path, 0);      //打开工作空间
                IRasterWorkspace  pRasterworkspace  = pWorkspace as IRasterWorkspace;               //创建栅格工作空间
                IRasterDataset    pRasterdataset    = pRasterworkspace.OpenRasterDataset(filename); //创建Dataset
                //影像金字塔的判断与创建
                IRasterPyramid3 pRaspyrmid = pRasterdataset as IRasterPyramid3;
                if (pRaspyrmid != null)
                {
                    if (!(pRaspyrmid.Present))
                    {
                        pRaspyrmid.Create();
                    }
                }
                IRaster      pRaster      = pRasterdataset.CreateDefaultRaster();
                IRasterLayer pRasterlayer = new RasterLayerClass();
                pRasterlayer.CreateFromRaster(pRaster);
                ILayer pLayer = pRasterlayer as ILayer;
                axMapControl1.AddLayer(pLayer, 0);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 创建金字塔
        /// </summary>
        /// <param name="rasterFilePath">栅格文件路径</param>
        public static void CreatePyramid(string rasterFilePath)
        {
            IRasterDataset pRasterDataset = GetRasterDataset(rasterFilePath);
            //影像金字塔判断与创建
            IRasterPyramid3 pRasPyramid = pRasterDataset as IRasterPyramid3;

            if (pRasPyramid == null)
            {
                return;
            }
            if (!pRasPyramid.Present)
            {
                pRasPyramid.Create(); //创建金字塔
            }
        }
Esempio n. 7
0
        protected override void OnClick()
        {
            Type factoryType                  = Type.GetTypeFromProgID("esriDataSourcesRaster.RasterWorkspaceFactory");
            IWorkspaceFactory wsFactory       = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
            string            filePath        = @"C:\Temp\raster\";// NAme of File = LC80400362014321LGN00.jpg
            IWorkspace        workspace       = wsFactory.OpenFromFile(filePath, 0);
            IRasterWorkspace  rasterWorkspace = workspace as IRasterWorkspace;
            IRasterDataset    rasterDataset   = rasterWorkspace.OpenRasterDataset("Landsat_8_Redlands_LC80400362013142LGN01.jpg");

            IRasterPyramid3 rasterPyramid3 = rasterDataset as IRasterPyramid3;
            bool            presentBool    = rasterPyramid3.Present;

            MessageBox.Show("presentBool = " + presentBool);

            ArcMap.Application.CurrentTool = null;
        }
Esempio n. 8
0
        private void Form1_DragDrop(object sender, DragEventArgs e)
        {
            string fullpath = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();       //获得路径

            if (fullpath == "")
            {
                return;
            }
            String path = System.IO.Path.GetDirectoryName(fullpath);
            //获取文件名
            String filename = System.IO.Path.GetFileName(fullpath);
            //文件名之前的路径名
            int    index        = fullpath.LastIndexOf("\\");
            string filePathName = fullpath.Substring(0, index);
            //获取后缀名
            string aLastName = fullpath.Substring(fullpath.LastIndexOf(".") + 1, (fullpath.Length - fullpath.LastIndexOf(".") - 1));

            if (aLastName == "shp")
            {
                axMapControl1.AddShapeFile(filePathName, filename);
                //axMapControl1.ActiveView.Refresh();
            }
            else
            {
                //打开栅格文件
                IWorkspaceFactory pWorkspacefactory = new RasterWorkspaceFactory();                 //创建工作空间工厂
                IWorkspace        pWorkspace        = pWorkspacefactory.OpenFromFile(path, 0);      //打开工作空间
                IRasterWorkspace  pRasterworkspace  = pWorkspace as IRasterWorkspace;               //创建栅格工作空间
                IRasterDataset    pRasterdataset    = pRasterworkspace.OpenRasterDataset(filename); //创建Dataset
                //影像金字塔的判断与创建
                IRasterPyramid3 pRaspyrmid = pRasterdataset as IRasterPyramid3;
                if (pRaspyrmid != null)
                {
                    if (!(pRaspyrmid.Present))
                    {
                        pRaspyrmid.Create();
                    }
                }
                IRaster      pRaster      = pRasterdataset.CreateDefaultRaster();
                IRasterLayer pRasterlayer = new RasterLayerClass();
                pRasterlayer.CreateFromRaster(pRaster);
                ILayer pLayer = pRasterlayer as ILayer;
                axMapControl1.AddLayer(pLayer, 0);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// 通过数据集获取栅格图层
        /// </summary>
        /// <param name="dataset">数据集</param>
        /// <returns></returns>
        public static IRasterLayer GetRasterLayerByDataset(IDataset dataset)
        {
            IRasterWorkspaceEx pRasterWorkspace = (IRasterWorkspaceEx)dataset.Workspace;
            IRasterDataset     pRasterDataset   = pRasterWorkspace.OpenRasterDataset(dataset.Name);
            //影像金字塔判断与创建
            IRasterPyramid3 pRasPyrmid = pRasterDataset as IRasterPyramid3;

            if (pRasPyrmid != null)
            {
                if (!pRasPyrmid.Present)
                {
                    pRasPyrmid.Create(); //创建金字塔
                }
            }

            IRasterLayer pRasterLayer = new RasterLayerClass();

            pRasterLayer.CreateFromDataset(pRasterDataset);
            return(pRasterLayer);
        }
Esempio n. 10
0
        /// <summary>
        /// 添加栅格数据
        /// </summary>
        /// <param name="mapControl">要添加栅格数据的地图控件</param>
        public void AddRasterFile(AxMapControl mapControl)
        {
            //获得文件
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Title           = "打开Raster文件";
            openFileDialog.Filter          = "栅格文件 (*.*)|*.bmp;*.tif;*.jpg;*.img|(*.bmp)|*.bmp|(*.tif)|*.tif|(*.jpg)|*.jpg|(*.img)|*.img";
            openFileDialog.CheckFileExists = true;
            openFileDialog.ShowDialog();
            //拆分路径和文件名
            string fullPath = openFileDialog.FileName;

            if (fullPath == "")
            {
                return;
            }
            string fileDir  = Path.GetDirectoryName(fullPath);
            string fileName = Path.GetFileName(fullPath);
            //从工作空间拿数据集
            IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactory();
            IRasterWorkspace  rasterWorkspace  = (IRasterWorkspace)workspaceFactory.OpenFromFile(fileDir, 0);
            IRasterDataset    rasterDataset    = rasterWorkspace.OpenRasterDataset(fileName);
            //栅格金字塔
            IRasterPyramid3 rasPyramid = rasterDataset as IRasterPyramid3;

            if (rasPyramid != null)
            {
                if (!rasPyramid.Present)
                {
                    rasPyramid.Create();
                }
            }
            //从数据集拿数据
            IRaster      raster      = rasterDataset.CreateDefaultRaster();
            IRasterLayer rasterLayer = new RasterLayerClass();

            rasterLayer.CreateFromRaster(raster);
            //加载数据
            mapControl.AddLayer(rasterLayer);
            mapControl.ActiveView.Refresh();
        }
Esempio n. 11
0
        private void RasterfileLoad_Click(object sender, EventArgs e)
        {
            OpenFileDialog pOpenFileDialog = new OpenFileDialog();

            pOpenFileDialog.CheckFileExists = true;
            pOpenFileDialog.Title           = "打开Raster文件";
            pOpenFileDialog.Filter          = "栅格文件(*.*)|*.bmp;*.tif;*.jpg;*.img|(*.bmp)|*.bmp|(*.tif)|*.tif)|(*.jpg)|*.jpg|(*.img)|*.img";
            pOpenFileDialog.ShowDialog();

            string pRasterFileName = pOpenFileDialog.FileName;

            if (pRasterFileName == "")
            {
                return;
            }
            string pPath     = System.IO.Path.GetDirectoryName(pRasterFileName);
            string pFileName = System.IO.Path.GetFileName(pRasterFileName);

            IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactory();
            IWorkspace        pWorkspace        = pWorkspaceFactory.OpenFromFile(pPath, 0);
            IRasterWorkspace  pRasterWorkspace  = pWorkspace as IRasterWorkspace;
            IRasterDataset    pRasterDataset    = pRasterWorkspace.OpenRasterDataset(pFileName);

            //影像金字塔的判断和创建
            IRasterPyramid3 pRasPyramid = pRasterDataset as IRasterPyramid3;

            if (pRasPyramid != null)
            {
                if (!(pRasPyramid.Present))
                {
                    pRasPyramid.Create();           //创建金字塔
                }
            }
            IRaster      pRaster      = pRasterDataset.CreateDefaultRaster();
            IRasterLayer pRasterLayer = new RasterLayerClass();

            pRasterLayer.CreateFromRaster(pRaster);
            ILayer pLayer = pRasterLayer as ILayer;

            mainMapControl.AddLayer(pLayer, 0);
        }
Esempio n. 12
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add CmdRasterTransZ.OnClick implementation
            IMapControl3 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl3;

            if (pMapCtr != null)
            {
                FrmRasterTransZ m_frmRasterTranZ = new FrmRasterTransZ();
                if (m_frmRasterTranZ.ShowDialog() == DialogResult.OK)
                {
                    if (m_frmRasterTranZ.istrue == true)
                    {
                        ClsRasterOp     pRasterOp      = new ClsRasterOp();
                        IRaster2        pRaster2       = pRasterLayer.Raster as IRaster2;
                        IRasterDataset2 pRasterDataset = pRaster2.RasterDataset as IRasterDataset2;
                        pRasterOp.ChangeRasterValue(pRasterDataset, m_frmRasterTranZ.a, m_frmRasterTranZ.b);
                        //此处要判断图层是否存在金字塔,如果存在则需要重新创建
                        IRasterPyramid3 pDstRasterPyramid3 = pRasterDataset as IRasterPyramid3;
                        if (pDstRasterPyramid3.Present)
                        {
                            IDataLayer2 pDataLayer = pRasterLayer as IDataLayer2;
                            pDataLayer.Disconnect();

                            pDstRasterPyramid3.DeletePyramid();
                            pDstRasterPyramid3.Create();

                            pRasterLayer.CreateFromDataset(pRasterDataset);
                        }
                        //更新图层渲染方式
                        ChangeStrechRender(pRasterLayer);
                        pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                        if (m_axTocControl != null)
                        {
                            m_axTocControl.SetBuddyControl(pMapCtr);
                            m_axTocControl.Update();
                            m_axTocControl.ActiveView.Refresh();
                        }
                    }
                }
            }
        }
Esempio n. 13
0
 /// <summary>
 /// 加载栅格文件到主地图控件
 /// </summary>
 /// <param name="rasterPath">The raster path.</param>
 private void AddRasterFileToMap(string rasterPath)
 {
     try
     {
         IRasterLayer     rasterLayer     = new RasterLayerClass();
         string           directoryName   = System.IO.Path.GetDirectoryName(rasterPath);
         string           fileName        = System.IO.Path.GetFileName(rasterPath);
         IRasterWorkspace rasterWorkspace = EngineAPI.OpenWorkspace(directoryName, DataType.raster) as IRasterWorkspace;
         IRasterDataset   rasterDataset   = rasterWorkspace.OpenRasterDataset(fileName);
         rasterLayer.CreateFromDataset(rasterDataset);
         IRasterPyramid3 rasterPyramid = rasterDataset as IRasterPyramid3;
         if (rasterPyramid != null && !rasterPyramid.Present)
         {
             //new frmCreatePyramid(new List<string>
             //{
             //    rasterLayer.FilePath
             //})
             //{
             //    Owner = EnviVars.instance.MainForm
             //}.ShowDialog();
             //using (GPExecutor gp = new GPExecutor())
             {
                 EnviVars.instance.GpExecutor.CreatePyramid(new List <string>
                 {
                     rasterLayer.FilePath
                 });
             }
         }
         this.axMapControl.AddLayer(rasterLayer, 0);
     }
     catch (Exception ex)
     {
         //XtraMessageBox.Show("加载数据失败!", "提示信息", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Asterisk);
         Log.WriteLog(typeof(frmPreview), ex);
         throw ex;
     }
 }
Esempio n. 14
0
 /// <summary>
 /// Adds the raster layers to map.
 /// </summary>
 /// <param name="rasterDict">The raster dictionary.</param>
 public static void AddRasterLayersToMap(Dictionary <string, IRasterDataset> rasterDict)
 {
     if ((rasterDict != null) && (rasterDict.Count != 0))
     {
         List <string> rasterFiles = new List <string>();
         Dictionary <string, IRasterLayer> dictionary = new Dictionary <string, IRasterLayer>();
         foreach (KeyValuePair <string, IRasterDataset> pair in rasterDict)
         {
             IRasterLayer layer = new RasterLayerClass
             {
                 Name = Path.GetFileNameWithoutExtension(pair.Key)
             };
             layer.CreateFromDataset(pair.Value);
             dictionary.Add(pair.Key, layer);
             IRasterPyramid3 pyramid = pair.Value as IRasterPyramid3;
             if (!((pyramid == null) || pyramid.Present))
             {
                 rasterFiles.Add(pair.Key);
             }
         }
         if (rasterFiles.Count > 0)
         {
             //new frmCreatePyramid(rasterFiles) { Owner = GFS.BLL.EnviVars.instance.MainForm }.ShowDialog();
             //using(GPExecutor gp = new GPExecutor())
             {
                 EnviVars.instance.GpExecutor.CreatePyramid(rasterFiles);
             }
             //EnviVars.instance.GpExecutor.CreatePyramid(rasterFiles);
         }
         foreach (KeyValuePair <string, IRasterLayer> pair2 in dictionary)
         {
             //EnviVars.instance.MapControl.AddLayer(pair2.Value, 0);
             //AddRecentFile(pair2.Key, FileType.Raster);
         }
         //SaveRecentFilesInfo();
     }
 }
        /// <summary>
        /// 装在图片
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 装载图片(object sender, EventArgs e)
        {
            GC.Collect();
            aa         = DateTime.Now;
            quality[0] = (int)ImwriteFlags.JpegQuality;
            quality[1] = 100;
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Multiselect = false;//该值确定是否可以选择多个文件
            dialog.Title       = "请选择文件夹";
            dialog.Filter      = "图片和文本(*.tif)|*.tif|All files(*.*)|*.*";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string        filejpg  = null;
                List <string> list     = new List <string>();
                List <Rect>   rects    = new List <Rect>();
                List <Rect>   rects1   = new List <Rect>();
                List <int>    width    = new List <int>();
                List <int>    height   = new List <int>();
                List <Mat>    newjpg   = new List <Mat>();
                string        path     = null;
                List <Mat>    bjpg     = new List <Mat>();
                List <string> tifname  = new List <string>();
                List <string> imgnames = new List <string>();
                List <int>    X        = new List <int>();
                List <int>    Y        = new List <int>();
                List <Mat>    tif      = new List <Mat>();
                List <int>    cols     = new List <int>();
                List <int>    rows     = new List <int>();
                path = System.IO.Path.GetDirectoryName(dialog.FileName);
                string txtname = System.IO.Path.GetFileNameWithoutExtension(dialog.FileName);
                filejpg = dialog.FileName.ToString();
                if (!File.Exists(path + "\\" + txtname + ".txt"))
                {
                    MessageBox.Show("txt文件不存在!");
                    return;
                }
                System.IO.FileStream txtfs = new System.IO.FileStream(path + "\\" + txtname + ".txt", FileMode.Open);
                StreamReader         txtsr = new StreamReader(txtfs, Encoding.UTF8);
                string strLine;
                //读取文件中的一行
                do
                {
                    strLine = txtsr.ReadLine();
                    list.Add(strLine);
                } while (strLine != null);//判断是否为空,表示到文件最后一行了
                list.Remove(list[list.Count - 1]);
                foreach (string item in list)
                {
                    if (item.Contains("width:"))
                    {
                        string[] Array1 = item.Split(':');
                        width.Add(Convert.ToInt32(Array1[1]));
                    }
                    else if (item.Contains("height:"))
                    {
                        string[] Array1 = item.Split(':');
                        height.Add(Convert.ToInt32(Array1[1]));
                    }
                    else if (item.Contains("fname:"))
                    {
                        string[] Array1 = item.Split(':');
                        tifname.Add(Array1[1] + ":" + Array1[2]);
                    }
                    else if (item.Contains("X:"))
                    {
                        string[] Array1 = item.Split(':');
                        X.Add(Convert.ToInt32(Array1[1]));
                    }
                    else if (item.Contains("Y:"))
                    {
                        string[] Array1 = item.Split(':');
                        Y.Add(Convert.ToInt32(Array1[1]));
                    }
                    else if (item.Contains("col:"))
                    {
                        string[] Array1 = item.Split(':');
                        cols.Add(Convert.ToInt32(Array1[1]));
                    }
                    else if (item.Contains("row:"))
                    {
                        string[] Array1 = item.Split(':');
                        rows.Add(Convert.ToInt32(Array1[1]));
                    }
                    else if (item.Contains("imgname:"))
                    {
                        string[] Array1 = item.Split(':');
                        imgnames.Add(Array1[1]);
                    }
                }
                txtfs.Close();
                txtsr.Close();
                int           maxcol = cols.Max();
                int           maxrow = rows.Max();
                List <int>    XS     = new List <int>();
                List <int>    YS     = new List <int>();
                int           xx     = 0;
                int           yy     = 0;
                HashSet <int> xh     = new HashSet <int>(width);
                HashSet <int> yh     = new HashSet <int>(height);
                List <int>    xs     = xh.ToList <int>();
                List <int>    ys     = yh.ToList <int>();
                for (int i = 0; i < maxcol - (cols.Min() - 1); i++)
                {
                    XS.Add(xx);
                    xx += xs[i];
                }
                for (int i = 0; i < maxrow - (rows.Min() - 1); i++)
                {
                    YS.Add(yy);
                    yy += ys[i];
                }
                int a = 0;
                int b = 0;
                for (int j = 0; j < height.Count; j++)
                {
                    rects.Add(new Rect(XS[a], YS[b], width[j], height[j]));
                    if (a == maxcol - (cols.Min() - 1) - 1)
                    {
                        b++;
                        a = 0;
                        continue;
                    }
                    a++;
                }
                List <Mat> newimg = new List <Mat>();
                Mat        bigimg = new Mat(filejpg);
                for (int i = 0; i < rects.Count; i++)
                {
                    newimg.Add(new Mat(bigimg, rects[i]));
                    newjpg.Add(newimg[i]);
                }
                for (int i = 0; i < newjpg.Count; i++)
                {
                    if (File.Exists(tifname[i]))
                    {
                        tif.Add(new Mat(tifname[i]));
                        rects1.Add(new Rect(X[i], Y[i], width[i], height[i]));
                        Mat imageROI = new Mat(tif[i], rects1[i]);
                        newjpg[i].CopyTo(imageROI);
                        Cv2.ImWrite(tifname[i], tif[i], quality);
                    }
                    else
                    {
                        tif.Add(new Mat());
                        rects1.Add(new Rect());
                    }
                }
                for (int i = 0; i < imgnames.Count; i++)
                {
                    if (imgnames[i].Equals("null") || imgnames[i] == null)
                    {
                        continue;
                    }
                    for (int j = 0; j < this.MapControl.LayerCount; j++)
                    {
                        ILayer mILayer = this.MapControl.get_Layer(j);
                        if (mILayer.Name == imgnames[i])
                        {
                            this.MapControl.DeleteLayer(j);//删除图层
                            IDataLayer      mIDataLayer      = (IDataLayer)mILayer;
                            IName           mIName           = mIDataLayer.DataSourceName;
                            IDataset        mIDataset        = (IDataset)mIName.Open();
                            IRasterPyramid3 mIRasterPyramid3 = mIDataset as IRasterPyramid3;
                            mIRasterPyramid3.DeletePyramid();//删除缓存
                            break;
                        }
                    }
                    string            strFolderPath      = System.IO.Path.GetDirectoryName(tifname[i]);
                    string            strFileName        = System.IO.Path.GetFileName(tifname[i]);
                    IWorkspaceFactory mIWorkspaceFactory = new RasterWorkspaceFactoryClass();
                    IWorkspace        mIWorkspace        = mIWorkspaceFactory.OpenFromFile(strFolderPath, 0);
                    IRasterWorkspace  mIRasterWorkspace  = mIWorkspace as IRasterWorkspace;
                    IRasterDataset    mIRasterDataset    = mIRasterWorkspace.OpenRasterDataset(strFileName);
                    IRasterPyramid    mIRasterPyramid    = mIRasterDataset as IRasterPyramid;
                    if (mIRasterPyramid != null)
                    {
                        if (mIRasterPyramid.Present == false)
                        {
                            mIRasterPyramid.Create();//创建缓存
                        }
                    }
                    IRaster      mIRaster      = mIRasterDataset.CreateDefaultRaster();
                    IRasterLayer mIRasterLayer = new RasterLayerClass();
                    mIRasterLayer.CreateFromRaster(mIRaster);
                    ILayer newILayer = mIRasterLayer as ILayer;
                    this.MapControl.AddLayer(newILayer, 0);//加入地图
                }
                DateTime bb = DateTime.Now;
                MessageBox.Show("完成(" + (bb - aa).TotalSeconds + "s)");
            }
        }
        public static List <ILayer> AnalyzeLayers(IWorkspace workspace)
        {
            var          list        = new List <ILayer>();
            IEnumDataset enumDataset = workspace.get_Datasets(esriDatasetType.esriDTAny);

            enumDataset.Reset();
            IDataset dataset = enumDataset.Next();

            while (dataset != null)
            {
                if (dataset is IFeatureDataset)
                {
                    IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace;
                    IFeatureDataset   featureDataset   = featureWorkspace.OpenFeatureDataset(dataset.Name);
                    IEnumDataset      enumdataset1     = featureDataset.Subsets;
                    enumdataset1.Reset();
                    IGroupLayer groupLayer = new GroupLayerClass();
                    groupLayer.Name = featureDataset.Name;
                    IDataset dataset1 = enumdataset1.Next();
                    while (dataset1 != null)
                    {
                        if (dataset1 is IFeatureClass)
                        {
                            IFeatureLayer featureLayer = new FeatureLayerClass();
                            featureLayer.FeatureClass = featureWorkspace.OpenFeatureClass(dataset1.Name);
                            if (featureLayer.FeatureClass != null)
                            {
                                featureLayer.Name = featureLayer.FeatureClass.AliasName;
                                list.Add(featureLayer);
                                groupLayer.Add(featureLayer);
                            }
                        }
                        dataset1 = enumdataset1.Next();
                    }
                    //list.Add(groupLayer);
                }
                else if (dataset is IFeatureClass)
                {
                    IFeatureWorkspace featureworkSpace = workspace as IFeatureWorkspace;
                    IFeatureLayer     featurelayer     = new FeatureLayerClass();
                    featurelayer.FeatureClass = featureworkSpace.OpenFeatureClass(dataset.Name);
                    featurelayer.Name         = featurelayer.FeatureClass.AliasName;
                    list.Add(featurelayer);
                }
                else if (dataset is IRasterDataset)
                {
                    IRasterWorkspaceEx rasterWorkspace = workspace as IRasterWorkspaceEx;
                    IRasterDataset     rasterDataset   = rasterWorkspace.OpenRasterDataset(dataset.Name);
                    IRasterPyramid3    rasterPyramid   = rasterDataset as IRasterPyramid3;
                    if (rasterPyramid != null)
                    {
                        if (!(rasterPyramid.Present))
                        {
                            rasterPyramid.Create();
                        }
                    }

                    IRasterLayer rasterLayer = new RasterLayerClass();
                    rasterLayer.CreateFromDataset(rasterDataset);
                    ILayer layer = rasterLayer as ILayer;
                    list.Add(layer);
                }

                dataset = enumDataset.Next();
            }

            return(list);
        }