Example #1
0
        /// <summary>
        /// 栅格入库类似ArcMap中的Load
        /// </summary>
        /// <param name="pWs"></param>
        /// <param name="pRasterName"></param>
        /// <param name="pRaser"></param>
        public void RasterInput(IWorkspace pWs, string pRasterName, IRaster pRaser)
        {
            IRasterWorkspaceEx pRsWx = pWs as IRasterWorkspaceEx;

            IRasterLoader pRastCatLoader = new RasterLoaderClass();

            pRastCatLoader.MosaicColormapMode = rstMosaicColormapMode.MM_FIRST;
            pRastCatLoader.Load(pRsWx.OpenRasterDataset(pRasterName), pRaser);
        }
        /// <summary>
        /// 导入数据(栅格数据集)
        /// </summary>
        /// <param name="RDDatasetName">栅格数据集名称</param>
        /// <param name="filePath">源数据路径</param>
        /// <param name="pWorkspace">栅格数据集工作空间</param>
        /// <param name="eError"></param>
        /// <returns></returns>
        private bool InputRasterDataset(string RDDatasetName, string filePath, IWorkspace pWorkspace, out Exception eError)
        {
            eError = null;
            FileInfo pFileInfo = new FileInfo(filePath);
            string   pFileDic  = pFileInfo.DirectoryName;          //文件目录
            string   pFileName = pFileInfo.Name;                   //文件名

            try
            {
                //IMosaicRaster pMosaicR = null;
                //目标栅格数据集
                IRasterDataset pObjRasterDataset = GetRasterDataset(RDDatasetName, pWorkspace, out eError);
                if (pObjRasterDataset == null)
                {
                    return(false);
                }
                //IRaster pObjRaster = pObjRasterDataset.CreateDefaultRaster();
                //if(pObjRaster!=null)
                //{
                //    pMosaicR = pObjRaster as IMosaicRaster;
                //}

                //栅格数据工作空间
                IWorkspaceFactory pOrgRasterWsFac = new RasterWorkspaceFactoryClass();
                IWorkspace        pWS             = pOrgRasterWsFac.OpenFromFile(pFileDic, 0);
                IRasterWorkspace2 pRasterWS       = pWS as IRasterWorkspace2;
                if (pRasterWS == null)
                {
                    return(false);
                }
                IRasterDataset pOrgRDataset = pRasterWS.OpenRasterDataset(pFileName);
                IRaster        pOrgRaster   = pOrgRDataset.CreateDefaultRaster();

                //load raster data to exist raster dataset
                IRasterLoader pRasterLoad = new RasterLoaderClass();
                if (pOrgRaster != null)
                {
                    //if(pMosaicR!=null)
                    //{
                    //    //若目标要素不为空,则进行拼接
                    //    //pMosaicR.MosaicOperatorType = rstMosaicOperatorType.MT_LAST;
                    //    pMosaicR.OrderByField = "Name";
                    //    pMosaicR.Ascending = true;
                    //    pMosaicR.MosaicColormapMode = rstMosaicColormapMode.MM_MATCH;
                    //    IMosaicOperator pMosaicOpe=pMosaicR.MosaicOperator;

                    //}
                    pRasterLoad.Background = 0;                                          //background value be ignored when loading
                    pRasterLoad.PixelAlignmentTolerance = 0;                             //重采样的容差
                    pRasterLoad.MosaicColormapMode      = rstMosaicColormapMode.MM_LAST; //拼接的颜色采用 last map color

                    pRasterLoad.Load(pObjRasterDataset, pOrgRaster);
                }
                Marshal.ReleaseComObject(pRasterLoad);
            }
            catch (System.Exception ex)
            {
                //*******************************************************************
                //guozheng added
                if (ModData.SysLog != null)
                {
                    ModData.SysLog.Write(ex, null, DateTime.Now);
                }
                else
                {
                    ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                    ModData.SysLog.Write(ex, null, DateTime.Now);
                }
                //********************************************************************

                eError = ex;
                return(false);
            }
            return(true);
        }
Example #3
0
        /// <summary>
        /// 栅格入库类似ArcMap中的Load
        /// </summary>
        /// <param name="pWs"></param>
        /// <param name="pRasterName"></param>
        /// <param name="pRaser"></param>
        public void RasterInput(IWorkspace pWs, string pRasterName, IRaster pRaser)
        {
            IRasterWorkspaceEx pRsWx = pWs as IRasterWorkspaceEx;

            IRasterLoader pRastCatLoader = new RasterLoaderClass();

            pRastCatLoader.MosaicColormapMode = rstMosaicColormapMode.MM_FIRST;
            pRastCatLoader.Load(pRsWx.OpenRasterDataset(pRasterName), pRaser);
        }
Example #4
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            Exception eError = null;

            //界面控制判断和检查


            if (txtSavePath.Text == "")
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "请选择保存路径!");
                return;
            }
            //栅格数据文件名称
            string pFileName = txtSavePath.Text.Trim();

            pFileName = pFileName.Substring(pFileName.LastIndexOf('\\') + 1);
            //目标栅格数据存储类型
            string pFormat = cmbDataFormat.Text.Trim().ToUpper();

            #region 创建目标工作空间
            IWorkspace pDesWS = null;//定义工作空间

            //如果存在同名库体则删除


            if (File.Exists(txtSavePath.Text.Trim()))
            {
                File.Delete(txtSavePath.Text.Trim());
            }
            if (cmbDataFormat.Text.Trim().ToUpper() == "PDB")
            {
                pDesWS = CreateWorkspace(txtSavePath.Text.Trim(), "PDB", out eError);
            }
            else if (cmbDataFormat.Text.Trim().ToUpper() == "GDB")
            {
                pDesWS = CreateWorkspace(txtSavePath.Text.Trim(), "GDB", out eError);
            }
            else if (cmbDataFormat.Text.Trim().ToUpper() == "TIF")
            {
                pDesWS = CreateWorkspace(txtSavePath.Text.Trim(), "tif", out eError);
            }
            else if (cmbDataFormat.Text.Trim().ToUpper() == "IMG")
            {
                pDesWS = CreateWorkspace(txtSavePath.Text.Trim(), "img", out eError);
            }
            if (eError != null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "创建工作空间失败!");
                return;
            }
            if (pDesWS == null)
            {
                return;
            }

            #endregion


            //IExtractionOp extraction = new RasterExtractionOpClass();
            IGeometry clipExtent = null;       //几何限制条件
            #region 获得几何限制条件
            IGeometry pGeo1 = null;
            IGeometry pGeo2 = null;
            IGeometry pGeo3 = null;

            pGeo1 = GetUnionGeo(dgMap);

            pGeo2 = GetUnionGeo(dgCounty);
            pGeo3 = GetUnionGeo(dgRange);
            ITopologicalOperator pTop = clipExtent as ITopologicalOperator;
            if (pGeo1 != null)
            {
                if (clipExtent == null)
                {
                    clipExtent = pGeo1;
                }
                else
                {
                    clipExtent = pTop.Union(pGeo1);
                }
            }
            pTop = clipExtent as ITopologicalOperator;
            if (pGeo2 != null)
            {
                if (clipExtent == null)
                {
                    clipExtent = pGeo2;
                }
                else
                {
                    clipExtent = pTop.Union(pGeo2);
                }
            }
            pTop = clipExtent as ITopologicalOperator;
            if (pGeo3 != null)
            {
                if (clipExtent == null)
                {
                    clipExtent = pGeo3;
                }
                else
                {
                    clipExtent = pTop.Union(pGeo3);
                }
            }
            if (clipExtent != null)
            {
                pTop = clipExtent as ITopologicalOperator;
                pTop.Simplify();
                clipExtent = pTop as IGeometry;
            }
            #endregion
            try
            {
                #region 提取数据
                IRaster pOrgRaster = null;           //源栅格数据



                if (m_dbType == "栅格数据集")
                {
                    //源栅格数据图层

                    IRasterLayer mOrgRasterlyer = m_Layer as IRasterLayer;
                    if (mOrgRasterlyer == null)
                    {
                        return;
                    }

                    //源栅格数据集
                    pOrgRaster = mOrgRasterlyer.Raster;
                    if (pOrgRaster == null)
                    {
                        return;
                    }
                    //栅格数据集提取

                    StractData(pFileName, clipExtent, pDesWS, pFormat, pOrgRaster, checkBoxClip.Checked, out eError);
                    if (eError != null)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", eError.Message);
                        return;
                    }
                }
                else
                {
                    //源数据为栅格数据编目,步骤入下:
                    //(1) 创建临时的工作空间;
                    //(2) 将符合属性条件的栅格数据拼接成栅格数据集后,存储在临时的工作空间里面
                    //(3) 将临时的工作空间里面的栅格数据集案范围提取出来

                    //=======================================================================================

                    #region 栅格编目数据提取

                    //(1)创建临时工作空间

                    IWorkspace tempWS = CreateWorkspace(ModData.temporaryDBPath, "GDB", out eError);
                    if (eError != null)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "创建临时的工作空间出错!");
                        return;
                    }
                    if (tempWS == null)
                    {
                        return;
                    }

                    //(2)遍历源栅格数据,将数据入库到临时工作空间里面

                    //源栅格数据图层

                    IFeatureLayer mOrgFeaLyer = m_Layer as IFeatureLayer;
                    if (mOrgFeaLyer == null)
                    {
                        return;
                    }
                    IRasterDataset pResRDataset = null;     //最后生成的栅格数据集


                    IFeatureClass pOrgFeaCls = mOrgFeaLyer.FeatureClass;
                    IQueryFilter  pFilter    = new QueryFilterClass();
                    pFilter.WhereClause = txtWhereStr.Text.Trim();
                    IFeatureCursor pFeaCursor = pOrgFeaCls.Search(pFilter, false);
                    if (pFeaCursor == null)
                    {
                        return;
                    }
                    IFeature pORgFea = pFeaCursor.NextFeature();
                    #region 遍历源栅格数据,进行源栅格数据入库(过滤和拼接)
                    while (pORgFea != null)
                    {
                        IRasterCatalogItem pOrgRCItem   = pORgFea as IRasterCatalogItem;
                        IRasterDataset     pOrgRasterDt = pOrgRCItem.RasterDataset;
                        if (pResRDataset == null)
                        {
                            //第一个数据入库直接将源数据拷贝过去

                            if (pOrgRasterDt.CanCopy())
                            {
                                pResRDataset = pOrgRasterDt.Copy(m_DesRasterCollName, tempWS) as IRasterDataset;
                                pORgFea      = pFeaCursor.NextFeature();
                                continue;
                            }
                        }
                        //从第二个栅格数据开始,进行入库和拼接

                        IRaster       pOrgRast    = pOrgRasterDt.CreateDefaultRaster();
                        IRasterLoader pRasterLoad = new RasterLoaderClass();
                        if (pOrgRast != null)
                        {
                            pRasterLoad.Background = 0;                                          //background value be ignored when loading
                            pRasterLoad.PixelAlignmentTolerance = 0;                             //重采样的容差
                            pRasterLoad.MosaicColormapMode      = rstMosaicColormapMode.MM_LAST; //拼接的颜色采用 last map color

                            pRasterLoad.Load(pResRDataset, pOrgRast);
                        }
                        Marshal.ReleaseComObject(pRasterLoad);

                        pORgFea = pFeaCursor.NextFeature();
                    }

                    //释放cursor
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeaCursor);
                    #endregion

                    //(3) 将临时工作空间里面的栅格数据集提取出来

                    if (pResRDataset == null)
                    {
                        return;
                    }
                    pOrgRaster = pResRDataset.CreateDefaultRaster();
                    StractData(pFileName, clipExtent, pDesWS, pFormat, pOrgRaster, checkBoxClip.Checked, out eError);
                    if (eError != null)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", eError.Message);
                        return;
                    }
                    #endregion
                }
                #endregion
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "操作完成!");
            }
            catch (Exception er)
            {
                //*******************************************************************
                //guozheng added
                if (ModData.SysLog != null)
                {
                    ModData.SysLog.Write(er, null, DateTime.Now);
                }
                else
                {
                    ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                    ModData.SysLog.Write(er, null, DateTime.Now);
                }
                //********************************************************************
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "提取栅格数据失败!\n" + er.Message);
                return;
            }
            this.Close();
        }