ArcEngine加载SDE图层

private void btnAddLayers_Click(object sender, EventArgs e)
        {
            //载入图层
            pWSF = new SdeWorkspaceFactory();

            IPropertySet pPropertySet = new PropertySet();
            pPropertySet.SetProperty("Server", "DU");
            pPropertySet.SetProperty("Instance", "esri_sde");
            pPropertySet.SetProperty("user", "sde");
            pPropertySet.SetProperty("password", "111");
            pPropertySet.SetProperty("version", "sde.DEFAULT");

            IWorkspace pSdeWorkspace = null;//sde工作空间
            IFeatureWorkspace pFeatureWorkspace = null;//矢量工作空间
            IRasterWorkspaceEx pRasterWorkspace = null;//栅格工作空间,注意必须是//IRasterWorkspaceEx
            try//打开工作空间
            {
                pSdeWorkspace = pWSF.Open(pPropertySet, 0);
                pFeatureWorkspace = pSdeWorkspace as IFeatureWorkspace;
                pRasterWorkspace = pSdeWorkspace as IRasterWorkspaceEx;

                //加载栅格图层
                IRasterDataset pRasterDataset = (IRasterDataset)

pRasterWorkspace.OpenRasterDataset("SDE.YJ");
                IRasterLayer pLayerBackground = new RasterLayerClass();
                pLayerBackground.CreateFromDataset(pRasterDataset);
                mapControlMain.AddLayer(pLayerBackground);
                mapControlOverView.AddLayer(pLayerBackground);//鹰眼

                //加载矢量图层
                IFeatureClass pFCBorderArea = pFeatureWorkspace.OpenFeatureClass

("Background");
                IFeatureLayer pFLBorderArea = new FeatureLayer();
                pFLBorderArea.FeatureClass = pFCBorderArea;
                pFLBorderArea.Name = "边界面";
                ILayer pLayerBorderArea = pFLBorderArea as ILayer;
                mapControlMain.AddLayer(pLayerBorderArea);

                IFeatureClass pFCDepartmentsArea =

pFeatureWorkspace.OpenFeatureClass("DepartmentsArea");
                IFeatureLayer pFLDepartmentsArea = new FeatureLayer();
                pFLDepartmentsArea.FeatureClass = pFCDepartmentsArea;
                pFLDepartmentsArea.Name = "主要单位";
                ILayer pLayerDepartmentsArea = pFLDepartmentsArea as ILayer;
                mapControlMain.AddLayer(pLayerDepartmentsArea);

                IFeatureClass pFCRoads = pFeatureWorkspace.OpenFeatureClass

("Roads");
                IFeatureLayer pFLRoads = new FeatureLayer();
                pFLRoads.FeatureClass = pFCRoads;
                pFLRoads.Name = "道路";
                ILayer pLayerRoads = pFLRoads as ILayer;
                mapControlMain.AddLayer(pLayerRoads);

                IFeatureClass pFCWaterarea = pFeatureWorkspace.OpenFeatureClass

("Waterarea");
                IFeatureLayer pFLWaterarea = new FeatureLayer();
                pFLWaterarea.FeatureClass = pFCWaterarea;
                pFLWaterarea.Name = "水域";
                ILayer pLayerWaterarea = pFLWaterarea as ILayer;
                mapControlMain.AddLayer(pLayerWaterarea);

                IFeatureClass pFCRivers = pFeatureWorkspace.OpenFeatureClass

("Rivers");
                IFeatureLayer pFLRivers = new FeatureLayer();
                pFLRivers.FeatureClass = pFCRivers;
                pFLRivers.Name = "河流";
                ILayer pLayerRivers = pFLRivers as ILayer;
                mapControlMain.AddLayer(pLayerRivers);

                IFeatureClass pFCCurlvets = pFeatureWorkspace.OpenFeatureClass

("Curlvets");
                IFeatureLayer pFLCurlvets = new FeatureLayer();
                pFLCurlvets.FeatureClass = pFCCurlvets;
                pFLCurlvets.Name = "涵洞";
                ILayer pLayerCurlvets = pFLCurlvets as ILayer;
                mapControlMain.AddLayer(pLayerCurlvets);

                IFeatureClass pFCPumpingStations =

pFeatureWorkspace.OpenFeatureClass("PumpingStation");
                IFeatureLayer pFLPumpingStations = new FeatureLayer();
                pFLPumpingStations.FeatureClass = pFCPumpingStations;
                pFLPumpingStations.Name = "泵站";
                ILayer pLayerPumpingStations = pFLPumpingStations as ILayer;
                mapControlMain.AddLayer(pLayerPumpingStations);


                IFeatureClass pFCBorder = pFeatureWorkspace.OpenFeatureClass

("Border");
                IFeatureLayer pFLBorder = new FeatureLayer();
                pFLBorder.FeatureClass = pFCBorder;
                pFLBorder.Name = "边界线";
                ILayer pLayerBorder = pFLBorder as ILayer;
                mapControlMain.AddLayer(pLayerBorder);
                mapControlOverView.AddLayer(pLayerBorder);

                mapControlMain.ActiveView.Refresh();
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
          
        }

posted @ 2010-05-17 14:26  孙老板  阅读(1149)  评论(0编辑  收藏  举报