Ejemplo n.º 1
0
        //函数号:
        //函数名:LoadRasterToCatalogDatabase
        //函数功能:Raster导入Database
        //参数:pWorkspace:数据库,pWorkspace可以是Access 或者SDE
        //		strCata:Catalog名称
        //		pRasterDs:需要入库的Rasterdataset
        //备注:insert a raster dataset with given path and file name to an existing raster catalog
        public void LoadRasterToCatalogDatabase(IWorkspace pWorkspace, string strCata, IRasterDataset pRasterDs, string name)
        {
            //QI IRasterWorkspaceEx to IWorkspace
            IRasterWorkspaceEx pRasWKS = pWorkspace as IRasterWorkspaceEx;

            //Open raster catalog
            //IRasterCatalog相当于一个FeatureClass(表),表中的每一个记录可以存放Raster
            IRasterCatalog pInCatalog = pRasWKS.OpenRasterCatalog(strCata);
            // get raster field index
            int iRaster = pInCatalog.RasterFieldIndex;

            // QI IFeatureClass for inserting
            IFeatureClass pFeatureClass = pInCatalog as IFeatureClass;

            // get insert cursor
            IFeatureCursor pCursor = pFeatureClass.Insert(false);

            // create raster value from raster dataset with default storagedef
            IRasterValue pRasterValue = new RasterValueClass();

            pRasterValue.RasterDataset    = pRasterDs;
            pRasterValue.RasterStorageDef = new RasterStorageDefClass();

            pRasterValue.RasterDatasetName.NameString = name;
            //这里可以设置新的RasterStorageDef

            // insert the rastervalue  ' it will update name, metadata and geometry field
            IFeatureBuffer pRow = pFeatureClass.CreateFeatureBuffer();

            pRow.set_Value(iRaster, pRasterValue);
            pCursor.InsertFeature(pRow);
        }
Ejemplo n.º 2
0
        //Open SDE RasterCatalog
        // Libraries needed to run the code:
        //   ESRI.ArcGIS.esriSystem, ESRI.ArcGIS.Geodatabase, and ESRI.ArcGIS.DataSourcesGDB
        public IRasterCatalog OpenSDERasCata(string server, string instance, string database, string user,
                                             string password, string rasterCatalogName, string version)
        {
            // Open an ArcSDE raster Catalog with the given name
            // server, instance, database, user, password, version are database connection info
            // rasterCatalogName is the name of the raster Catalog

            //Open the ArcSDE workspace
            IPropertySet propertySet = new PropertySetClass();

            propertySet.SetProperty("server", server);
            propertySet.SetProperty("instance", instance);
            propertySet.SetProperty("database", database);
            propertySet.SetProperty("user", user);
            propertySet.SetProperty("password", password);
            propertySet.SetProperty("version", version);

            // cocreate the workspace factory
            IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactoryClass();

            // Open the raster workspace using the previously defined porperty set
            // and QI to the desired IRasterWorkspaceEx interface to access the existing catalog
            IRasterWorkspaceEx rasterWorkspaceEx = workspaceFactory.Open(propertySet, 0) as IRasterWorkspaceEx;

            //Open the ArcSDE raster Catalog
            IRasterCatalog rasterCatalog = null;

            rasterCatalog = rasterWorkspaceEx.OpenRasterCatalog(rasterCatalogName);

            return(rasterCatalog);
        }
Ejemplo n.º 3
0
        public IList <RasterName> get_RasterDataSetNames()
        {
            IList <RasterName> names = new List <RasterName>();

            if (this.m_workSpace != null)
            {
                IEnumDatasetName   enumDatasetName   = m_workSpace.get_DatasetNames(esriDatasetType.esriDTRasterCatalog);
                IDatasetName       datasetName       = enumDatasetName.Next();//DataSet的名字
                IRasterWorkspaceEx rasterWorkspaceEx = m_workSpace as IRasterWorkspaceEx;
                while (datasetName != null)
                {
                    RasterName name = new RasterName();
                    name.RasDCName = datasetName.Name.ToString();
                    IRasterCatalogName rasterCaName  = (IRasterCatalogName)datasetName;
                    IRasterCatalog     rasterCatalog = rasterWorkspaceEx.OpenRasterCatalog(name.RasDCName);
                    ITable             table         = rasterCatalog as ITable;
                    ICursor            cursor        = table.Search(null, false);
                    IRow row = cursor.NextRow();
                    while (row != null)
                    {
                        name.RDSName.Add(row.get_Value(cursor.FindField("NAME")).ToString());

                        row = cursor.NextRow();
                    }
                    names.Add(name);
                    datasetName = enumDatasetName.Next();
                }
            }
            return(names);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 加载栅格库体
        /// </summary>
        /// <param name="m_Hook">主程序hook</param>
        /// <param name="DbEleInfo">矢量库体对应的库体信息XmlElement</param>
        /// <param name="ex">输出错误信息</param>
        public static void AddRasterLayer(Plugin.Application.IAppDBIntegraRef m_Hook, XmlElement DbEleInfo, out Exception ex)
        {
            ex = null;
            try
            {
                IGroupLayer pGroupLayer = new GroupLayerClass();
                pGroupLayer.Name = m_Hook.ProjectTree.SelectedNode.DataKeyString + "_" + m_Hook.ProjectTree.SelectedNode.Text;
                // string rasterDBType = (m_Hook.ProjectTree.SelectedNode.Tag as XmlElement).GetAttribute("存储类型");
                // string rasterDBType = DbEleInfo.GetAttribute("存储类型");
                string     rasterDBType = string.Empty;
                XmlElement RasterEle    = DbEleInfo.SelectSingleNode(".//栅格数据库") as XmlElement;
                rasterDBType = RasterEle.GetAttribute("存储类型").Trim();
                XmlElement elementTemp   = DbEleInfo.SelectSingleNode(".//栅格数据库/连接信息") as XmlElement;
                IWorkspace TempWorkSpace = ModDBOperate.GetDBInfoByXMLNode(elementTemp, "") as IWorkspace;
                if (TempWorkSpace == null)
                {
                    // SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "连接数据库失败!");
                    ex = new Exception("连接数据库失发生异常");
                    return;
                }
                IRasterWorkspaceEx pRasterWS = TempWorkSpace as IRasterWorkspaceEx;
                if (pRasterWS == null)
                {
                    return;
                }
                string feaclsName = (elementTemp.FirstChild as XmlElement).GetAttribute("名称");
                if (rasterDBType.Trim() == "栅格编目")
                {
                    //栅格编目数据加载
                    IRasterCatalog         pRasterCatalog = pRasterWS.OpenRasterCatalog(feaclsName);
                    IGdbRasterCatalogLayer pGDBRCLayer    = new GdbRasterCatalogLayerClass();
                    if (!pGDBRCLayer.Setup(pRasterCatalog as ITable))
                    {
                        return;
                    }
                    IFeatureLayer mFeaLayer = pGDBRCLayer as IFeatureLayer;
                    pGroupLayer.Add(mFeaLayer as ILayer);
                }
                else if (rasterDBType.Trim() == "栅格数据集")
                {
                    //栅格数据集加载

                    IRasterDataset pRasterDataset = pRasterWS.OpenRasterDataset(feaclsName);
                    IRasterLayer   pRasterLayer   = new RasterLayerClass();
                    pRasterLayer.CreateFromDataset(pRasterDataset);
                    if (pRasterLayer == null)
                    {
                        return;
                    }
                    pGroupLayer.Add(pRasterLayer as ILayer);
                }
                m_Hook.MapControl.Map.AddLayer(pGroupLayer);
            }
            catch (Exception eError)
            {
                ex = eError;
                return;
            }
        }
Ejemplo n.º 5
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (this.listBox1.SelectedItems == null)
            {
                MessageBox.Show("请选择图幅名!");
                return;
            }

            string sqlText = "";

            for (int i = 0; i < this.listBox1.SelectedItems.Count; i++)
            {
                sqlText = "select name,DATASTRUCTURE from sheetmetadata where NAME='" + listBox1.SelectedItems[i] + "'";
                m_oraCmd.CommandText = sqlText;
                OracleDataReader dr = m_oraCmd.ExecuteReader();
                if (!dr.HasRows)
                {
                    MessageBox.Show("图幅不存在!");
                    return;
                }
                while (dr.Read())
                {
                    // this.listBox1.Items.Add(dr.GetValue(0).ToString());
                    if (dr.GetValue(1).ToString() == "矢量")
                    {
                        IFeatureLayer feaLyr;
                        feaLyr = m_gdata.AddFeatureClassToMap(dr.GetValue(0).ToString());
                        this.m_mapControl.Map.AddLayer(feaLyr);
                    }
                    if (dr.GetValue(1).ToString() == "影像")
                    {
                        IRasterWorkspaceEx rasterWS      = m_workSpace as IRasterWorkspaceEx;
                        IRasterCatalog     rasterCatalog = rasterWS.OpenRasterCatalog("COASTALGIS." + dr.GetValue(1).ToString());
                        ITable             table         = rasterCatalog as ITable;
                        ICursor            cursor        = table.Search(null, false);
                        IRow           row      = cursor.NextRow();
                        IRasterDataset rasterDS = null;
                        while (row != null)
                        {
                            IRasterCatalogItem rasterCatalogItem = row as IRasterCatalogItem;

                            if (dr.GetValue(0).ToString() == row.get_Value(cursor.FindField("NAME")).ToString())
                            {
                                rasterDS = rasterCatalogItem.RasterDataset;
                                break;
                            }
                            row = cursor.NextRow();
                        }
                        IRasterLayer rasterLayer = new RasterLayerClass();
                        rasterLayer.CreateFromDataset(rasterDS);
                        this.m_mapControl.Map.AddLayer(rasterLayer);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        //Open SDE RasterCatalog2
        // Libraries needed to run the code:
        //   ESRI.ArcGIS.esriSystem, ESRI.ArcGIS.Geodatabase, and ESRI.ArcGIS.DataSourcesGDB
        public IRasterCatalog OpenSDERasCata2(IWorkspace pWorkspace, string rasterCatalogName)
        {
            // Open the raster workspace using the previously defined porperty set
            // and QI to the desired IRasterWorkspaceEx interface to access the existing catalog
            IRasterWorkspaceEx rasterWorkspaceEx = pWorkspace as IRasterWorkspaceEx;

            //Open the ArcSDE raster Catalog
            IRasterCatalog rasterCatalog = null;

            rasterCatalog = rasterWorkspaceEx.OpenRasterCatalog(rasterCatalogName);

            return(rasterCatalog);
        }
Ejemplo n.º 7
0
        //Open Personal Geodatabase RasterCatalog
        //   ESRI.ArcGIS.Geodatabase, ESRI.ArcGIS.DataSourcesGDB
        public IRasterCatalog OpenPGDBRasterCatalog(string pathName, string rasterCatalogName)
        {
            // Open personal geodatabase raster catalog with the given name
            // pathName is the PGDB path (location of the personal geodatabase)
            // rasterCatalogName is the name of the raster catalog to be opened

            //Open the Access workspace
            IWorkspaceFactory2 workspaceFactory = new AccessWorkspaceFactoryClass();

            IRasterWorkspaceEx rasterWorkspaceEx = workspaceFactory.OpenFromFile(pathName, 0) as IRasterWorkspaceEx;

            //Open the PGDB raster Catalog
            IRasterCatalog rasterCatalog = null;

            rasterCatalog = rasterWorkspaceEx.OpenRasterCatalog(rasterCatalogName);

            return(rasterCatalog);
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            ESRI.ArcGIS.esriSystem.AoInitialize aoInit = null;
            try
            {
                ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);
                aoInit = new AoInitializeClass();
                esriLicenseStatus licStatus = aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeBasic);
                Console.WriteLine("License Checkout successful.");
            }
            catch (Exception exc)
            {
                // If it fails at this point, shutdown the test and ignore any subsequent errors.
                Console.WriteLine(exc.Message);
            }

            try
            {
                //Create temporary unmanaged raster catalog and load all rasters
                CreateUnmanagedRasterCatalog();

                //Open raster catalog
                IRasterWorkspaceEx rasterWorkspaceEx = (IRasterWorkspaceEx)OpenRasterPGDBWorkspace(tempPGDBPath);
                IRasterCatalog     rasterCatalog     = rasterWorkspaceEx.OpenRasterCatalog(tempRasterCatalog);

                //Mosaic rasters in the raster catalog
                Mosaic(rasterCatalog);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }

            Console.Write("Please press any key to close the application.");
            Console.ReadKey();

            //Do not make any call to ArcObjects after ShutDown() call
            aoInit.Shutdown();
        }
Ejemplo n.º 9
0
        //cyf 2011065 modify
        public override void OnClick()
        {
            Exception err = null;

            /////获取工程项目名称
            DevComponents.AdvTree.Node ProjectNode = new DevComponents.AdvTree.Node();
            ProjectNode = m_Hook.ProjectTree.SelectedNode;
            while (ProjectNode.Parent != null)
            {
                ProjectNode = ProjectNode.Parent;
            }
            //cyf 20110625 add:
            DevComponents.AdvTree.Node DBNode = new DevComponents.AdvTree.Node(); //数据库树节点
            //获取数据库节点
            DBNode = m_Hook.ProjectTree.SelectedNode;
            while (DBNode.Parent != null && DBNode.DataKeyString != "DB")
            {
                DBNode = DBNode.Parent;
            }
            if (DBNode.DataKeyString != "DB")
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据库节点失败!");
                return;
            }

            DevComponents.AdvTree.Node DtSetNode = new DevComponents.AdvTree.Node();  //数据集树节点
            #region 获取数据集节点
            if (DBNode.Text == "现势库" || DBNode.Text == "历史库" || DBNode.Text == "临时库") //.DataKeyString == "现势库"
            {
                //获取数据集节点
                DtSetNode = m_Hook.ProjectTree.SelectedNode;
                while (DtSetNode.Parent != null && DtSetNode.DataKeyString != "FD")
                {
                    DtSetNode = DtSetNode.Parent;
                }
                if (DtSetNode.DataKeyString != "FD")
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据集节点失败!");
                    return;
                }
            }
            else if (DBNode.Text == "栅格数据库")
            {
                //cyf 20110626 add:获取栅格数据库图层节点
                DtSetNode = m_Hook.ProjectTree.SelectedNode;
                if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "RC")
                {
                    while (DtSetNode.Parent != null && DtSetNode.DataKeyString != "RC")
                    {
                        DtSetNode = DtSetNode.Parent;
                    }
                    if (DtSetNode.DataKeyString != "RC")
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据集节点失败!");
                        return;
                    }
                }
                else if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "RD")
                {
                    while (DtSetNode.Parent != null && DtSetNode.DataKeyString != "RD")
                    {
                        DtSetNode = DtSetNode.Parent;
                    }
                    if (DtSetNode.DataKeyString != "RD")
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据集节点失败!");
                        return;
                    }
                }
                //end
            }
            #endregion


            XmlElement elementTemp   = (DBNode.Tag as XmlElement).SelectSingleNode(".//连接信息") as XmlElement;
            IWorkspace TempWorkSpace = ModDBOperator.GetDBInfoByXMLNode(elementTemp, "") as IWorkspace;
            if (TempWorkSpace == null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "连接数据库失败!");
                return;
            }
            //cyf 20110625 modify
            ILayer player = null;
            //ILayer player = ModDBOperator.GetGroupLayer(m_Hook.MapControl, m_Hook.ProjectTree.SelectedNode.DataKeyString + "_" + ProjectNode.Text);
            if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "FD")
            {
                player = ModDBOperator.GetGroupLayer(m_Hook.MapControl, m_Hook.ProjectTree.SelectedNode.Text + "_" + ProjectNode.Text);
            }
            else if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "FC")
            {
                player = ModDBOperator.GetGroupLayer(m_Hook.MapControl, DtSetNode.Text + "_" + ProjectNode.Text);
            }
            //cyf 20110626 add:添加获取栅格数据图层
            else if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "RC" || m_Hook.ProjectTree.SelectedNode.DataKeyString == "RD")
            {
                //获取栅格数据图层
                player = ModDBOperator.GetGroupLayer(m_Hook.MapControl, DtSetNode.Text + "_" + ProjectNode.Text);
            }
            //end
            if (player != null)
            {
                m_Hook.MapControl.Map.DeleteLayer(player);
                m_Hook.TOCControl.Update();
            }
            //end

            IGroupLayer pGroupLayer = new GroupLayerClass();

            //cyf 20110625

            if (DBNode.Text == "现势库" || DBNode.Text == "历史库" || DBNode.Text == "临时库") //.DataKeyString == "现势库"
            {
                /////////若为历史库管理状态退出该状态,加载现势库
                m_Hook.MapControl.Map.ClearLayers();
                Plugin.Interface.ICommandRef HisBaseCommand = null;
                bool GetSeccess = Plugin.ModuleCommon.DicCommands.TryGetValue("GeoDBATool.ControlsDBHistoryManage", out HisBaseCommand);
                if (GetSeccess)
                {
                    HisCommand = HisBaseCommand as ControlsDBHistoryManage;
                    if (HisCommand.Checked)
                    {
                        HisCommand.IsHistory = false;//判断是不是历史库点的加载,若是现势库就卸载掉历史库,若是历史库就不操作
                        HisCommand.OnClick();
                    }
                }
                #region 加载数据
                SysCommon.Gis.SysGisDataSet sysGisDataset = new SysCommon.Gis.SysGisDataSet(TempWorkSpace);
                //cyf 20110625 modify
                IFeatureDataset featureDataset = null;        //数据集
                if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "FD")
                {
                    featureDataset = sysGisDataset.GetFeatureDataset(m_Hook.ProjectTree.SelectedNode.Text, out err);
                    if (err != null)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据集失败,请检查该数据集是否存在!");
                        return;
                    }
                    pGroupLayer.Name = m_Hook.ProjectTree.SelectedNode.Text + "_" + ProjectNode.Text;
                }
                else if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "FC")
                {
                    featureDataset = sysGisDataset.GetFeatureDataset(DtSetNode.Text, out err);
                    if (err != null)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据集失败!");
                        return;
                    }
                    pGroupLayer.Name = DtSetNode.Text + "_" + ProjectNode.Text;
                }
                //end

                List <IDataset> lstDataset = sysGisDataset.GetFeatureClass(featureDataset);
                //遍历要素类,加载图层
                string dbType   = "";
                string userName = "";//用户名

                userName = elementTemp.GetAttribute("用户");
                dbType   = elementTemp.GetAttribute("类型");
                foreach (IDataset dataset in lstDataset)
                {
                    IFeatureClass pFeatureClass = dataset as IFeatureClass;
                    if (pFeatureClass == null)
                    {
                        continue;
                    }
                    IFeatureLayer pFeatureLayer = new FeatureLayerClass();
                    if (pFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)
                    {
                        pFeatureLayer = new FDOGraphicsLayerClass();
                    }
                    pFeatureLayer.FeatureClass = pFeatureClass;
                    if (dbType.Trim().ToUpper() == "SDE")
                    {
                        //cyf 20110706 modify:修改为不去掉用户名 changed by xisheng 0906 去掉用户名
                        if (dataset.Name.ToUpper().Contains(userName.Trim().ToUpper()))
                        {
                            //SDE用户图层名去掉用户名
                            pFeatureLayer.Name = dataset.Name.Substring(userName.Trim().Length + 1);
                        }
                        else
                        {
                            pFeatureLayer.Name = dataset.Name;
                        }
                        //end
                    }
                    else
                    {
                        pFeatureLayer.Name = dataset.Name;
                    }
                    //cyf 20110625 modify
                    if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "FC")
                    {
                        //加载指定的图层
                        if (m_Hook.ProjectTree.SelectedNode.Text != pFeatureLayer.Name)
                        {
                            continue;
                        }
                    }
                    else if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "FD")
                    {
                        //加载具备权限的图层
                        XmlElement feaclsElem = null;
                        try { feaclsElem = (m_Hook.ProjectTree.SelectedNode.Tag as XmlElement).SelectSingleNode(".//图层名") as XmlElement; } catch { }
                        if (feaclsElem != null)
                        {
                            if (!feaclsElem.GetAttribute("名称").Contains(pFeatureLayer.Name))
                            {
                                //若不具备数据权限,则不进行加载
                                continue;
                            }
                        }
                    }
                    //end
                    pGroupLayer.Add(pFeatureLayer as ILayer);
                }

                m_Hook.MapControl.Map.AddLayer(pGroupLayer);
                #endregion
            }
            //else if (DBNode.Text == "历史库")
            //{
            //    //历史库加载
            //    //ModDBOperator.WriteLog("GetCommand");
            //    Plugin.Interface.ICommandRef HisBaseCommand = null;
            //    bool GetSeccess = Plugin.ModuleCommon.DicCommands.TryGetValue("GeoDBATool.ControlsDBHistoryManage", out HisBaseCommand);
            //    if (GetSeccess)
            //    {
            //        HisCommand = HisBaseCommand as ControlsDBHistoryManage;
            //        //判断是不是历史库点的加载,若是现势库就卸载掉历史库,若是历史库就不操作
            //        HisCommand.IsHistory = true;
            //        HisCommand.OnClick();
            //        if (HisCommand.MyControlHistoryBar != null)
            //        {
            //            string HisDBType = elementTemp.GetAttribute("类型");
            //            string[] strTemp = new string[] { elementTemp.GetAttribute("服务器"), elementTemp.GetAttribute("服务名"), elementTemp.GetAttribute("数据库"), elementTemp.GetAttribute("用户"), elementTemp.GetAttribute("密码"), elementTemp.GetAttribute("版本") };

            //            HisCommand.MyControlHistoryBar.AddHistoryData(strTemp, HisDBType);
            //        }
            //    }
            //}
            //加载sde数据后,注册版本
            //if (dbType.Trim().ToUpper() == "SDE")
            //{
            //    IDataset pFeaDt = featureDataset as IDataset;
            //    if (pFeaDt != null)
            //    {
            //        IVersionedObject pVerObj = pFeaDt as IVersionedObject;
            //        if (!pVerObj.IsRegisteredAsVersioned)
            //        {
            //            //注册版本
            //            pVerObj.RegisterAsVersioned(true);
            //        }
            //        else
            //        {
            //            pVerObj.RegisterAsVersioned(false);
            //        }
            //    }

            //}

            else if (DBNode.Text == "栅格数据库")
            {
                //栅格数据加载,分为两种情况:栅格数据集、栅格编目
                //cyf 20110625 modify
                pGroupLayer.Name = m_Hook.ProjectTree.SelectedNode.Text + "_" + ProjectNode.Text;
                //end
                string rasterDBType = (m_Hook.ProjectTree.SelectedNode.Tag as XmlElement).GetAttribute("存储类型");

                elementTemp   = (DBNode.Tag as XmlElement).SelectSingleNode(".//连接信息") as XmlElement; //cyf 20110626
                TempWorkSpace = ModDBOperator.GetDBInfoByXMLNode(elementTemp, "") as IWorkspace;
                if (TempWorkSpace == null)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "连接数据库失败!");
                    return;
                }
                IRasterWorkspaceEx pRasterWS = TempWorkSpace as IRasterWorkspaceEx;
                if (pRasterWS == null)
                {
                    return;
                }
                //string feaclsName = (elementTemp.FirstChild as XmlElement).GetAttribute("名称");
                string feaclsName = m_Hook.ProjectTree.SelectedNode.Text;
                try
                {
                    if (rasterDBType.Trim() == "栅格编目")
                    {
                        //栅格编目数据加载
                        IRasterCatalog         pRasterCatalog = pRasterWS.OpenRasterCatalog(feaclsName);
                        IGdbRasterCatalogLayer pGDBRCLayer    = new GdbRasterCatalogLayerClass();
                        if (!pGDBRCLayer.Setup(pRasterCatalog as ITable))
                        {
                            return;
                        }
                        IFeatureLayer mFeaLayer = pGDBRCLayer as IFeatureLayer;
                        pGroupLayer.Add(mFeaLayer as ILayer);
                        //IFeatureClass pFeaCls = pRasterCatalog as IFeatureClass;
                        //if (pFeaCls == null) return;
                        //IFeatureCursor pFeaCursor=pFeaCls.Search(null,false);
                        //if(pFeaCursor==null) return;
                        //IFeature pFea=pFeaCursor.NextFeature();
                        //while (pFea != null)
                        //{
                        //    IRasterCatalogItem pRCItem = pFea as IRasterCatalogItem;
                        //    IRasterDataset pRasterDt = pRCItem.RasterDataset;
                        //    IRasterLayer mRasterLayer = new RasterLayerClass();
                        //    mRasterLayer.CreateFromDataset(pRasterDt);
                        //    if (mRasterLayer == null) return;
                        //    pGroupLayer.Add(mRasterLayer as ILayer);

                        //    pFea = pFeaCursor.NextFeature();

                        //    //IFeatureLayer pFeaLayer = new FeatureLayerClass();
                        //    //pFeaLayer.FeatureClass = pFeaCls as IFeatureClass;
                        //    //pFeaLayer.Name = feaclsName;
                        //    //pGroupLayer.Add(pFeaLayer as ILayer);
                        //}
                    }
                    else if (rasterDBType.Trim() == "栅格数据集")
                    {
                        //栅格数据集加载

                        IRasterDataset pRasterDataset = pRasterWS.OpenRasterDataset(feaclsName);
                        //IRasterPyramid pRasterPyramid = pRasterDataset as IRasterPyramid;
                        //if(!pRasterPyramid.Present)
                        //{
                        //    if (SysCommon.Error.ErrorHandle.ShowFrmInformation("是", "否", "未构建金字塔,是否构建金字塔?"))
                        //    {
                        //        pRasterPyramid.Create();
                        //    }
                        //}
                        IRasterLayer pRasterLayer = new RasterLayerClass();
                        pRasterLayer.CreateFromDataset(pRasterDataset);
                        if (pRasterLayer == null)
                        {
                            return;
                        }
                        pGroupLayer.Add(pRasterLayer as ILayer);
                    }
                    m_Hook.MapControl.Map.AddLayer(pGroupLayer);
                } catch (Exception e)
                {
                    //*******************************************************************
                    //guozheng added
                    if (ModData.SysLog != null)
                    {
                        ModData.SysLog.Write(e, null, DateTime.Now);
                    }
                    else
                    {
                        ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                        ModData.SysLog.Write(e, null, DateTime.Now);
                    }
                    //********************************************************************

                    return;
                }
            }
            //对图层进行排序

            SysCommon.Gis.ModGisPub.LayersCompose(m_Hook.MapControl);

            //符号化 去掉加载的符号化 20111025 席胜

            //GeoUtilities.ControlsRenderLayerByMxd RenderLayerByMxd = new GeoUtilities.ControlsRenderLayerByMxd();
            //RenderLayerByMxd.OnCreate(m_Hook);
            //RenderLayerByMxd.OnClick();
        }
Ejemplo n.º 10
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            Exception err = null;

            #region 检查设置是否完备
            //服务器连接设置检查
            if (comBoxType.SelectedIndex == 1)
            {
                if (txtUser.Text.Length == 0 || txtPassWord.Text.Length == 0)
                {
                    labelXErr.Text = "请完整设置SDE服务器访问参数!";
                    return;
                }
            }
            else
            {
                if (txtDataBase.Text.Length == 0)
                {
                    labelXErr.Text = "请完整设置本地数据库路径!";
                    return;
                }
            }

            //判断数据库是否已经存在
            if (comBoxType.Text.Trim().ToUpper() == "PDB")
            {
                if (File.Exists(txtDataBase.Text.Trim()))
                {
                    MessageBox.Show("数据库'" + txtDataBase.Text.Trim().Substring(txtDataBase.Text.Trim().LastIndexOf('\\') + 1) + "'已经存在,请检查!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            else if (comBoxType.Text.Trim().ToUpper() == "GDB")
            {
                if (Directory.Exists(txtDataBase.Text.Trim()))
                {
                    MessageBox.Show("数据库'" + txtDataBase.Text.Trim().Substring(txtDataBase.Text.Trim().LastIndexOf('\\') + 1) + "'已经存在,请检查!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }

            if (rbdataset.Checked)// cmbRasterType.Text.Trim() == "栅格数据集")
            {
                //栅格数据集设置检查
                if (cmbCompression.Text.Trim() == "")
                {
                    MessageBox.Show("请选择压缩类型!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (cmbResampleType.Text.Trim() == "")
                {
                    MessageBox.Show("请选择重采样类型!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                try
                {
                    if (txtPyramid.Text.Trim() != "")
                    {
                        Convert.ToInt32(txtPyramid.Text.Trim());
                    }

                    Convert.ToInt32(tileH.Text.Trim());
                    Convert.ToInt32(tileW.Text.Trim());
                    Convert.ToInt32(txtBand.Text.Trim());
                }
                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);
                    }
                    //********************************************************************

                    MessageBox.Show("请填写有效的数字!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //labelXErr.Text = "请填写有效的数字!";
                    return;
                }
            }

            if (txtRasterName.Text == "")
            {
                labelXErr.Text = "请设置栅格编目名称或栅格数据集名称!";
                return;
            }

            #endregion


            #region 设置数据库连接
            //SysCommon.Gis.SysGisDataSet pSysDT = new SysCommon.Gis.SysGisDataSet();
            if (this.comBoxType.SelectedIndex == 2)    //PDB库体
            {
                //pSysDT.SetWorkspace(txtDataBase.Text.Trim(),SysCommon.enumWSType.PDB,out err);
                SetDestinationProp("PDB", txtDataBase.Text, "", "", "", "");
            }
            else if (this.comBoxType.SelectedIndex == 1)    //SDE库体
            {
                //pSysDT.SetWorkspace(txtServer.Text, txtInstance.Text, "", txtUser.Text, txtPassWord.Text, txtVersion.Text, out err);
                SetDestinationProp("SDE", txtServer.Text, txtInstance.Text, txtUser.Text, txtPassWord.Text, txtVersion.Text);
            }
            else if (this.comBoxType.SelectedIndex == 0)   //GDB库体
            {
                //pSysDT.SetWorkspace(txtDataBase.Text.Trim(), SysCommon.enumWSType.GDB, out err);
                SetDestinationProp("GDB", txtDataBase.Text, "", "", "", "");
            }
            if (err != null)
            {
                MessageBox.Show("连接数据库出错!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            //pworkSpace=pSysDT.WorkSpace;
            #endregion

            //创建库体
            //ISpatialReference pGeoSpaRef = GetSpatialRef(cmbGeoSpaRef.Text.Trim());
            //ISpatialReference pRasterSpaRef = GetSpatialRef(cmbRasterSpaRef.Text.Trim());

            //几何空间参考
            ISpatialReference pGeoSpaRef = GetSpatialRef(txtGeoSpati.Text.Trim(), out err);
            if (err != null)
            {
                return;
            }
            //栅格空间参考
            ISpatialReference pRasterSpaRef = GetSpatialRef2(txtRasterSpati.Text.Trim(), out err);
            if (err != null)
            {
                return;
            }

            rstPixelType pPixelType = GetPixelType();
            //栅格数据工作空间
            IRasterWorkspaceEx pRasterWSEx = pworkSpace as IRasterWorkspaceEx;
            if (pRasterWSEx == null)
            {
                labelXErr.Text = "数据库连接出错!";
                return;
            }

            if (rbcatalog.Checked)
            {
                //首先判断栅格目录是否存在
                try
                {
                    IRasterCatalog tempRasterCatalog = pRasterWSEx.OpenRasterCatalog(txtRasterName.Text.Trim());
                    if (tempRasterCatalog != null)
                    {
                        MessageBox.Show("栅格数据'" + txtRasterName.Text.Trim() + "'已经存在,请检查!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
                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);
                    }
                    //********************************************************************
                }
                //创建栅格目录
                //*********************************************************
                //guozheng added CreateCatalog Log
                List <string> Pra = new List <string>();
                Pra.Add(txtRasterName.Text.Trim());
                if (ModData.SysLog != null)
                {
                    ModData.SysLog.Write("创建栅格目录", Pra, DateTime.Now);
                }
                else
                {
                    ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                    ModData.SysLog.Write("创建栅格目录", Pra, DateTime.Now);
                }
                //*********************************************************
                //创建栅格目录
                CreateCatalog(pRasterWSEx, txtRasterName.Text.Trim(), "Raster", "Shape", pRasterSpaRef, pGeoSpaRef, "", true, out err);
            }
            else if (rbdataset.Checked)
            {
                //首先判断栅格目录是否存在
                try
                {
                    IRasterDataset tempRasterDataset = pRasterWSEx.OpenRasterDataset(txtRasterName.Text.Trim());
                    if (tempRasterDataset != null)
                    {
                        MessageBox.Show("栅格数据'" + txtRasterName.Text.Trim() + "'已经存在,请检查!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
                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);
                    }
                    //********************************************************************
                }
                //创建栅格数据集
                //*********************************************************
                //guozheng added CreateRasterDataset Log
                List <string> Pra = new List <string>();
                Pra.Add(txtRasterName.Text.Trim());
                if (ModData.SysLog != null)
                {
                    ModData.SysLog.Write("创建栅格数据集", Pra, DateTime.Now);
                }
                else
                {
                    ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                    ModData.SysLog.Write("创建栅格数据集", Pra, DateTime.Now);
                }
                //*********************************************************
                //创建栅格数据集
                CreateRasterDataset(pRasterWSEx, txtRasterName.Text.Trim(), Convert.ToInt32(txtBand.Text.Trim()), pPixelType, pRasterSpaRef, pGeoSpaRef, null, null, "", out err);
            }
            else
            {
                MessageBox.Show("请选择栅格数据库的类型!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (err != null)
            {
                MessageBox.Show(err.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //labelXErr.Text = err.Message;
                return;
            }


            ///将现势库信息写入配置文件(res\\schema)
            ///
            DevComponents.AdvTree.Node pCurNode = m_Hook.ProjectTree.SelectedNode; ///获得树图上选择的工程节点
            string pProjectname = pCurNode.Name;

            System.Xml.XmlNode    Projectnode        = m_Hook.DBXmlDocument.SelectSingleNode("工程管理/工程[@名称='" + pProjectname + "']");
            System.Xml.XmlElement ProjectNodeElement = Projectnode as System.Xml.XmlElement;

            //设置存储类型,栅格目录,栅格数据集
            System.Xml.XmlElement DbTypeEle = ProjectNodeElement.SelectSingleNode(".//栅格数据库") as System.Xml.XmlElement;
            if (rbcatalog.Checked)
            {
                DbTypeEle.SetAttribute("存储类型", "栅格编目");
            }
            else if (rbdataset.Checked)
            {
                DbTypeEle.SetAttribute("存储类型", "栅格数据集");
            }

            System.Xml.XmlElement ProjectConnEle = ProjectNodeElement.SelectSingleNode(".//栅格数据库/连接信息") as System.Xml.XmlElement;

            ///设置数据库连接类型
            if (this.comBoxType.SelectedIndex == 2)
            {
                ProjectConnEle.SetAttribute("类型", "PDB");
                ProjectConnEle.SetAttribute("数据库", txtDataBase.Text);
            }
            else if (this.comBoxType.SelectedIndex == 0)
            {
                ProjectConnEle.SetAttribute("类型", "GDB");
                ProjectConnEle.SetAttribute("数据库", txtDataBase.Text);
            }
            else if (this.comBoxType.SelectedIndex == 1)
            {
                ProjectConnEle.SetAttribute("类型", "SDE");
                ProjectConnEle.SetAttribute("服务器", txtServer.Text);
                ProjectConnEle.SetAttribute("服务名", txtInstance.Text);
                ProjectConnEle.SetAttribute("数据库", txtDataBase.Text);
                ProjectConnEle.SetAttribute("用户", txtUser.Text);
                ProjectConnEle.SetAttribute("密码", txtPassWord.Text);
                ProjectConnEle.SetAttribute("版本", txtVersion.Text);
            }

            ///设置数据集名称
            ///
            System.Xml.XmlElement ProjectUserDSEle = ProjectConnEle.SelectSingleNode(".//库体") as System.Xml.XmlElement;
            ProjectUserDSEle.SetAttribute("名称", txtRasterName.Text.Trim());

            //设置栅格数据参数
            System.Xml.XmlElement rasterParaEle = ProjectNodeElement.SelectSingleNode(".//栅格数据库/参数设置") as System.Xml.XmlElement;
            rasterParaEle.SetAttribute("重采样类型", cmbResampleType.Text.Trim());
            rasterParaEle.SetAttribute("压缩类型", cmbCompression.Text.Trim());
            rasterParaEle.SetAttribute("金字塔", txtPyramid.Text.Trim());
            rasterParaEle.SetAttribute("瓦片高度", tileH.Text.Trim());
            rasterParaEle.SetAttribute("瓦片宽度", tileW.Text.Trim());
            rasterParaEle.SetAttribute("波段", txtBand.Text.Trim());


            m_Hook.DBXmlDocument.Save(ModData.v_projectXML);

            MessageBox.Show("创建成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Occurs in the master geodatabase after data changes in either a replica
        /// geodatabase or delta database are transferred to the master geodatabase.
        /// </summary>
        /// <param name="targetReplica">The target replica.</param>
        /// <param name="dataChangesSource">A collection of changes made to the master geodatabase.</param>
        /// <param name="oidMappingTable">Not used in this implementation.</param>
        /// <param name="changesTable">Not used in this implemented.</param>
        public void AfterSynchronizingDataChanges(IReplica targetReplica, object dataChangesSource, ITable oidMappingTable, ITable changesTable)
        {
            // Make sure that the correct replica is being synchronized.
            String replicaName            = targetReplica.Name;
            String unqualifiedReplicaName = replicaName.Substring(replicaName.LastIndexOf('.') + 1);

            if (!unqualifiedReplicaName.Equals(rasterReplicaName))
            {
                return;
            }

            // Get the rasters to pull if connected synchronization is occurring.
            IDataChanges3 dataChanges3 = dataChangesSource as IDataChanges3;

            if (dataChanges3 != null)
            {
                // Get the source's replicas.
                IName              sourceWorkspaceName     = (IName)dataChanges3.ParentWorkspaceName;
                IWorkspace         sourceWorkspace         = (IWorkspace)sourceWorkspaceName.Open();
                IWorkspaceReplicas sourceWorkspaceReplicas = (IWorkspaceReplicas)sourceWorkspace;

                // Get the replica generation numbers.
                int genBegin  = 0;
                int genEnd    = 0;
                int targetGen = 0;
                dataChanges3.GenerationNumbers(out genBegin, out genEnd, out targetGen);
                IQueryFilter queryFilter = new QueryFilterClass();
                queryFilter.WhereClause = String.Format("{0} > {1} or {0} is NULL", genFieldName, genBegin);

                // Open a cursor to get the rasters to copy form the source.
                IRasterWorkspaceEx sourceRasterWorkspaceEx = (IRasterWorkspaceEx)sourceWorkspace;
                IRasterCatalog     sourceRasterCatalog     = sourceRasterWorkspaceEx.OpenRasterCatalog(rasterCatalogName);
                IFeatureClass      sourceFeatureClass      = (IFeatureClass)sourceRasterCatalog;
                int            sourceGenFieldIndex         = sourceFeatureClass.FindField(genFieldName);
                IFeatureCursor sourceCursor = sourceFeatureClass.Search(queryFilter, true);

                // Open the target raster catalog.
                IRasterWorkspaceEx targetRasterWorkspaceEx = (IRasterWorkspaceEx)workspaceHelper.Workspace;
                IRasterCatalog     targetRasterCatalog     = targetRasterWorkspaceEx.OpenRasterCatalog(rasterCatalogName);
                IFeatureClass      targetFeatureClass      = (IFeatureClass)targetRasterCatalog;
                int            targetGenFieldIndex         = targetFeatureClass.FindField(genFieldName);
                IFeatureCursor targetCursor = targetFeatureClass.Insert(true);

                // Copy the rasters from the source to the target.
                IFeature sourceFeature = null;
                while ((sourceFeature = sourceCursor.NextFeature()) != null)
                {
                    // Copy the raster and set the target gen to -1 (received).
                    IFeatureBuffer featureBuffer = targetFeatureClass.CreateFeatureBuffer();
                    featureBuffer.set_Value(targetRasterCatalog.RasterFieldIndex, sourceFeature.get_Value(sourceRasterCatalog.RasterFieldIndex));
                    featureBuffer.set_Value(targetGenFieldIndex, -1);
                    targetCursor.InsertFeature(featureBuffer);

                    // Set the source row value to the current generation.
                    if (sourceFeature.get_Value(sourceGenFieldIndex) == DBNull.Value)
                    {
                        sourceFeature.set_Value(sourceGenFieldIndex, genEnd);
                    }
                    sourceFeature.Store();
                }
                Marshal.FinalReleaseComObject(sourceCursor);
                Marshal.FinalReleaseComObject(targetCursor);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 获取栅格目录
        /// </summary>
        /// <param name="pWs"></param>
        /// <param name="pCatlogName"></param>
        /// <returns></returns>
        public IRasterCatalog GetCatlog(IWorkspace pWs, string pCatlogName)
        {
            IRasterWorkspaceEx pRsWx = pWs as IRasterWorkspaceEx;

            return(pRsWx.OpenRasterCatalog(pCatlogName));
        }
Ejemplo n.º 13
0
        private void comboBoxDataSource_SelectedIndexChanged(object sender, EventArgs e)
        {
            //cyf 20110613 add
            //this.comboBoxFeaClass.Items.Clear();
            //end
            SysGisTable sysTable = new SysGisTable(_tmpWorkspace);
            Exception   eError;
            //根据用户选择的数据源,得到数据源的工作空间
            string DataSourceName = this.comboBoxDataSource.Text;
            string conninfostr    = sysTable.GetFieldValue("DATABASEMD", "CONNECTIONINFO", "DATABASENAME='" + DataSourceName + "'", out eError).ToString();
            int    type           = int.Parse(sysTable.GetFieldValue("DATABASEMD", "DATAFORMATID", "DATABASENAME='" + DataSourceName + "'", out eError).ToString());
            string strDBPara      = sysTable.GetFieldValue("DATABASEMD", "DBPARA", "DATABASENAME='" + DataSourceName + "'", out eError).ToString();
            int    index6         = conninfostr.LastIndexOf("|");
            //string strdataset = conninfostr.Substring(index6 + 1);

            IWorkspace pWorkspace = ModuleMap.GetWorkSpacefromConninfo(conninfostr, type);

            if (pWorkspace == null)
            {
                return;
            }
            _ListDataset.Clear();
            _ListTypeOfDataset.Clear();
            string strDatasets = conninfostr.Substring(index6 + 1);

            string[]          strTemp       = strDatasets.Split(new char[] { ',' });
            IFeatureWorkspace pFeaWorkSpace = pWorkspace as IFeatureWorkspace;

            if (pFeaWorkSpace != null)
            {
                for (int k = 0; k < strTemp.Length; k++)
                {
                    IDataset pTmpdataset = null;
                    if (strDBPara.Contains("栅格数据集"))
                    {
                        IRasterWorkspaceEx rasterWorkspace = (IRasterWorkspaceEx)pFeaWorkSpace;
                        IRasterDataset     pRDataset       = rasterWorkspace.OpenRasterDataset(strTemp[k]);
                        pTmpdataset = pRDataset as IDataset;
                        if (pTmpdataset != null)
                        {
                            _ListTypeOfDataset.Add("RD");
                        }
                    }
                    else if (strDBPara.Contains("栅格编目"))
                    {
                        IRasterWorkspaceEx rasterWorkspace = (IRasterWorkspaceEx)pFeaWorkSpace;
                        IRasterCatalog     pRCatalog       = rasterWorkspace.OpenRasterCatalog(strTemp[k]);
                        pTmpdataset = pRCatalog as IDataset;
                        if (pTmpdataset != null)
                        {
                            _ListTypeOfDataset.Add("RC");
                        }
                    }
                    else
                    {
                        pTmpdataset = pFeaWorkSpace.OpenFeatureDataset(strTemp[k]) as IDataset;
                        if (pTmpdataset != null)
                        {
                            _ListTypeOfDataset.Add("FC");
                        }
                    }
                    if (pTmpdataset != null)
                    {
                        _ListDataset.Add(pTmpdataset);
                    }
                }
            }
            _dataWorkspace = pWorkspace;

            if (pWorkspace == null)
            {
                return;
            }
        }