SDE连接,创建数据集,数据导入以及数据导出


1.界面




2.数据库的连接


  1. IWorkspace workspace;  

  2. IFeatureWorkspace featureWorkspace;  

  3. IRasterWorkspaceEx rasterWorkspaceEx;  

  4. IFeatureDataset featureDataset;  

  5. IRasterDataset rasterDataset;  

  6. IPropertySet propertySet;  

  7. private void btnConnectDB_Click(object sender, EventArgs e)  

  8. {  

  9.     propertySet = new PropertySetClass();  

  10.     propertySet.SetProperty(“server”“Toby-PC”);  

  11.     propertySet.SetProperty(“instance”“5151/tcp”);  

  12.     propertySet.SetProperty(“database”“sde”);  

  13.     propertySet.SetProperty(“user”“sde”);  

  14.     propertySet.SetProperty(“password”“Toby521904”);  

  15.     propertySet.SetProperty(“version”“SDE.DEFAULT”);  

  16.     IWorkspaceFactory workspaceFactory =new SdeWorkspaceFactory();  

  17.     workspace = workspaceFactory.Open(propertySet, 0);  

  18.     MessageBox.Show(“连接成功”);  

  19.     

  20. }  


3.创建数据集


  1. private void btnCreateDataSet_Click(object sender, EventArgs e)  

  2.     {  

  3.         if (this.txtRasterDS.Text != “” || this.txtFeatureDS.Text != “”)  

  4.         {  

  5.             featureWorkspace = workspace as IFeatureWorkspace;  

  6.             rasterWorkspaceEx = workspace as IRasterWorkspaceEx;  

  7.             IEnumDatasetName enumDatasetName;  

  8.             bool isExit = false;  

  9.             IDatasetName datasetName;  

  10.             string dsName = “”;  

  11.             if (this.txtFeatureDS.Text != “”)  

  12.             {  

  13.                 //定义空间参考  

  14.                 ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();  

  15.                 ISpatialReference spatialReference = spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);  

  16.                 spatialReference.SetDomain(-1000, -1000, 1000, 1000);  

  17.                 enumDatasetName = workspace.get_DatasetNames(esriDatasetType.esriDTFeatureDataset);  

  18.                 datasetName = enumDatasetName.Next();  

  19.                 isExit = false;  

  20.                 dsName = “sde.SDE.” + this.txtFeatureDS.Text;  

  21.                 while (datasetName != null)  

  22.                 {  

  23.                     if (datasetName.Name == dsName)  

  24.                     {  

  25.                         isExit = true;  

  26.                         MessageBox.Show(“矢量数据集已经存在!”);  

  27.                         this.txtFeatureDS.Focus();  

  28.                         return;  

  29.                     }  

  30.                     datasetName = enumDatasetName.Next();  

  31.                 }  

  32.                 if (isExit == false)  

  33.                 {  

  34.                     featureDataset = featureWorkspace.CreateFeatureDataset(this.txtFeatureDS.Text, spatialReference);  

  35.                 }  

  36.                 MessageBox.Show(“矢量数据集创建成功”);  

  37.             }  

  38.             if (this.txtRasterDS.Text != “”)  

  39.             {  

  40.                 //创建影像数据集;  

  41.                 isExit = false;  

  42.                 enumDatasetName = workspace.get_DatasetNames(esriDatasetType.esriDTRasterDataset);  

  43.                 datasetName = enumDatasetName.Next();  

  44.                 dsName = “SDE.” + this.txtRasterDS.Text;  

  45.                 while (datasetName != null)  

  46.                 {  

  47.                     if (datasetName.Name == dsName)  

  48.                     {  

  49.                         isExit = true;  

  50.                         MessageBox.Show(“矢量数据集已经存在!”);  

  51.                         break;  

  52.                     }  

  53.                     datasetName = enumDatasetName.Next();  

  54.                 }  

  55.                 if (isExit == false)  

  56.                 {  

  57.                     IRasterStorageDef rasterStorageDef = new RasterStorageDefClass();  

  58.                     rasterStorageDef.CompressionType = esriRasterCompressionType.esriRasterCompressionUncompressed;  

  59.                     rasterStorageDef.PyramidLevel = 1;  

  60.                     rasterStorageDef.PyramidResampleType = rstResamplingTypes.RSP_BilinearInterpolation;  

  61.                     rasterStorageDef.TileHeight = 128;  

  62.                     rasterStorageDef.TileWidth = 128;  

  63.                     IRasterDef rasterDef = new RasterDefClass();  

  64.                     ISpatialReference rasterDSpatialReference = new UnknownCoordinateSystemClass();  

  65.                     rasterDef.SpatialReference = rasterDSpatialReference;  

  66.                     IGeometryDef geometryDef = new GeometryDefClass();  

  67.                     IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;  

  68.                     geometryDefEdit.AvgNumPoints_2 = 5;  

  69.                     geometryDefEdit.GridCount_2 = 1;  

  70.                     geometryDefEdit.set_GridSize(0, 1000);  

  71.                     geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;  

  72.                     ISpatialReference spatialReference2 = new UnknownCoordinateSystemClass();  

  73.                     geometryDefEdit.SpatialReference_2 = spatialReference2;  

  74.                     rasterDataset = rasterWorkspaceEx.CreateRasterDataset(this.txtRasterDS.Text, 1, rstPixelType.PT_LONG, rasterStorageDef, “DEFAULTS”, rasterDef, geometryDef);  

  75.                     MessageBox.Show(“栅格数据集创建成功”);  

  76.                 }  

  77.             }  

  78.         }  

  79.     }<span style=“font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);”> </span>  


4.矢量数据直接导入sde


  1. private void importFToSDE_Click(object sender, EventArgs e)  

  2.     {  

  3.         try  

  4.         {  

  5.             IDataset pDataSet = workspace as IDataset;  

  6.             this.openFileDialog1.Filter = “shp file(*.shp)|*.shp”;  

  7.             this.openFileDialog1.Title = “打开矢量数据”;  

  8.             this.openFileDialog1.Multiselect = false;  

  9.             string fileName = “”;  

  10.             if (this.openFileDialog1.ShowDialog() == DialogResult.OK)  

  11.             {  

  12.                 fileName = this.openFileDialog1.FileName;  

  13.                 FileInfo fileInfo = new FileInfo(fileName);  

  14.                 string filePath = fileInfo.DirectoryName;  

  15.                 string file = fileInfo.Name;  

  16.                 FeatureClassToFeatureClass(pDataSet, filePath, file, “dddd”true);  

  17.             }  

  18.             MessageBox.Show(“导入成功”);  

  19.         }  

  20.         catch (Exception ee)  

  21.         {  

  22.             MessageBox.Show(ee.ToString());  

  23.         }   

  24.     }  




[csharp] view
plain
 copy



  1. public void FeatureClassToFeatureClass(IDataset pDataSet, string strFeatFileDir, string strFeatFileName, string strOutName, bool isWorkspace)  

  2. {  

  3.     try  

  4.     {  

  5.         IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();  

  6.         IFeatureWorkspace pFeatureWK = (IFeatureWorkspace)pWSF.OpenFromFile(strFeatFileDir, 0);  

  7.         IFeatureClass pInFeatureClass = pFeatureWK.OpenFeatureClass(strFeatFileName);  

  8.         if (pInFeatureClass == null || pDataSet == null)  

  9.         {  

  10.             MessageBox.Show(“创建失败”);  

  11.             return;  

  12.         }  

  13.         IFeatureClassName pInFeatureclassName;  

  14.         IDataset pIndataset = (IDataset)pInFeatureClass;  

  15.         pInFeatureclassName = (IFeatureClassName)pIndataset.FullName;  

  16.         //如果名称已存在  

  17.         IWorkspace2 pWS2 = null;  

  18.         if (isWorkspace)  

  19.             pWS2 = pDataSet as IWorkspace2;  

  20.         else  

  21.             pWS2 = pDataSet.Workspace as IWorkspace2;  

  22.         if (pWS2.get_NameExists(esriDatasetType.esriDTFeatureClass, strOutName))  

  23.         {  

  24.             DialogResult result;  

  25.             result = System.Windows.Forms.MessageBox.Show(null“矢量文件名  “ + strOutName + ”  在数据库中已存在!” + “/r是否覆盖?”“相同文件名”, MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);  

  26.             //覆盖原矢量要素  

  27.             if (result == DialogResult.Yes)  

  28.             {  

  29.                 IFeatureWorkspace pFWS = (IFeatureWorkspace)pWS2;  

  30.                 IDataset pDataset = pFWS.OpenFeatureClass(strOutName) as IDataset;  

  31.                 pDataset.Delete();  

  32.                 pDataset = null;  

  33.             }  

  34.         }  

  35.         IFields pInFields, pOutFields;  

  36.         IFieldChecker pFieldChecker = new FieldCheckerClass();  

  37.         IEnumFieldError pError;  

  38.         pInFields = pInFeatureClass.Fields;  

  39.         pFieldChecker.Validate(pInFields, out pError, out pOutFields);  

  40.         IField geoField = null;  

  41.         for (int i = 0; i < pOutFields.FieldCount; i++)  

  42.         {  

  43.             IField pField = pOutFields.get_Field(i);  

  44.             if (pField.Type == esriFieldType.esriFieldTypeOID)  

  45.             {  

  46.                 IFieldEdit pFieldEdit = (IFieldEdit)pField;  

  47.                 pFieldEdit.Name_2 = pField.AliasName;  

  48.             }  

  49.             if (pField.Type == esriFieldType.esriFieldTypeGeometry)  

  50.             {  

  51.                 geoField = pField;  

  52.                 break;  

  53.             }  

  54.         }  

  55.         IGeometryDef geometryDef = geoField.GeometryDef;  

  56.         IFeatureDataConverter one2another = new FeatureDataConverterClass();  

  57.         IFeatureClassName pOutFeatureClassName = new FeatureClassNameClass();  

  58.         IDatasetName pOutDatasetName = (IDatasetName)pOutFeatureClassName;  

  59.         if (isWorkspace)  

  60.             pOutDatasetName.WorkspaceName = (IWorkspaceName)pDataSet.FullName;  

  61.         else  

  62.             pOutDatasetName.WorkspaceName = (IWorkspaceName)((IDataset)pDataSet.Workspace).FullName;  

  63.         pOutDatasetName.Name = strOutName;  

  64.         if (isWorkspace)  

  65.         {  

  66.             one2another.ConvertFeatureClass(pInFeatureclassName, nullnull, pOutFeatureClassName, geometryDef, pOutFields, “”, 1000, 0);  

  67.         }  

  68.         else  

  69.         {  

  70.             IFeatureDataset pFeatDS = (IFeatureDataset)pDataSet;  

  71.             IFeatureDatasetName pOutFeatDSName = pFeatDS.FullName as IFeatureDatasetName;  

  72.             one2another.ConvertFeatureClass(pInFeatureclassName, null, pOutFeatDSName, pOutFeatureClassName, geometryDef, pOutFields, “”, 1000, 0);  

  73.             pOutFeatDSName = null;  

  74.             pFeatDS = null;  

  75.         }  

  76.     }  

  77.     catch (Exception ex)  

  78.     {  

  79.         MessageBox.Show(ex.Message);  

  80.         return;  

  81.     }  

  82. }  


5.矢量数据导入sde数据集


       


  1. private void importF_Click(object sender, EventArgs e)  

  2.     {  

  3.         featureWorkspace = workspace as IFeatureWorkspace;  

  4.         this.openFileDialog1.Filter = “shp file(*.shp)|*.shp”;  

  5.         this.openFileDialog1.Title = “打开矢量数据”;  

  6.         this.openFileDialog1.Multiselect = false;  

  7.         string fileName = “”;  

  8.         if (this.openFileDialog1.ShowDialog() == DialogResult.OK)  

  9.         {  

  10.             fileName = this.openFileDialog1.FileName;  

  11.             FileInfo fileInfo = new FileInfo(fileName);  

  12.             string filePath = fileInfo.DirectoryName;  

  13.             string file = fileInfo.Name;  

  14.             IWorkspaceFactory shpwpf = new ShapefileWorkspaceFactory();  

  15.             IWorkspace shpwp = shpwpf.OpenFromFile(filePath, 0);  

  16.             IFeatureWorkspace shpfwp = shpwp as IFeatureWorkspace;  

  17.             IFeatureClass shpfc = shpfwp.OpenFeatureClass(file);  

  18.             //导入SDE数据库  

  19.             IFeatureClass sdeFeatureClass = null;  

  20.             IFeatureClassDescription featureClassDescription = new FeatureClassDescriptionClass();  

  21.             IObjectClassDescription objectClassDescription = featureClassDescription as IObjectClassDescription;  

  22.             IFields fields = shpfc.Fields;  

  23.             IFieldChecker fieldChecker = new FieldCheckerClass();  

  24.             IEnumFieldError enumFieldError = null;  

  25.             IFields vFields = null;  

  26.             fieldChecker.ValidateWorkspace = featureWorkspace as IWorkspace;  

  27.             fieldChecker.Validate(fields,out enumFieldError,out vFields);  

  28.             featureDataset = featureWorkspace.OpenFeatureDataset(this.txtFeatureDS.Text);  

  29.             try  

  30.             {  

  31.                 sdeFeatureClass = featureWorkspace.OpenFeatureClass(shpfc.AliasName);  

  32.             }  

  33.             catch  

  34.             {  

  35.                  

  36.             }  

  37.             if (sdeFeatureClass == null)  

  38.             {  

  39.                 sdeFeatureClass = featureDataset.CreateFeatureClass(shpfc.AliasName, vFields,  

  40.                     objectClassDescription.InstanceCLSID, objectClassDescription.ClassExtensionCLSID,  

  41.                     shpfc.FeatureType, shpfc.ShapeFieldName, “”);  

  42.                 IFeatureCursor featureCursor = shpfc.Search(nulltrue);  

  43.                 IFeature feature = featureCursor.NextFeature();  

  44.                 IFeatureCursor sdeFeatureCursor = sdeFeatureClass.Insert(true);  

  45.                 IFeatureBuffer sdeFeatureBuffer;  

  46.                 while (feature != null)  

  47.                 {  

  48.                     sdeFeatureBuffer = sdeFeatureClass.CreateFeatureBuffer();  

  49.                     IField shpField = new FieldClass();  

  50.                     IFields shpFields = feature.Fields;  

  51.                     for (int i = 0; i < shpFields.FieldCount; i++)  

  52.                     {  

  53.                         shpField = shpFields.get_Field(i);  

  54.                         int index = sdeFeatureBuffer.Fields.FindField(shpField.Name);  

  55.                         if (index != -1)  

  56.                         {  

  57.                             sdeFeatureBuffer.set_Value(index, feature.get_Value(i));  

  58.                         }  

  59.                     }  

  60.                     sdeFeatureCursor.InsertFeature(sdeFeatureBuffer);  

  61.                     sdeFeatureCursor.Flush();  

  62.                     feature = featureCursor.NextFeature();  

  63.                 }  

  64.             }  

  65.         }  

  66.         MessageBox.Show(“导入成功”);  

  67.     }  


6.导入栅格数据


 


  1. private void importR_Click(object sender, EventArgs e)  

  2.     {  

  3.         this.openFileDialog1.Filter = “Imag file (*.img)|*.img”;  

  4.         this.openFileDialog1.Title = “打开影像数据”;  

  5.         this.openFileDialog1.Multiselect = false;  

  6.         string fileName = “”;  

  7.         if (this.openFileDialog1.ShowDialog() == DialogResult.OK)  

  8.         {  

  9.             fileName = this.openFileDialog1.FileName;  

  10.             string filepath;  

  11.             string file;  

  12.             string file1;  

  13.             int lastIndex;  

  14.             lastIndex = fileName.LastIndexOf(@“”);  

  15.             filepath = fileName.Substring(0, lastIndex);  

  16.             file = fileName.Substring(lastIndex + 1);  

  17.             //导入SDE数据库  

  18.             rasterWorkspaceEx = workspace as IRasterWorkspaceEx;  

  19.             IWorkspaceFactory tifwpf = new RasterWorkspaceFactoryClass();  

  20.             IWorkspace tifwp = tifwpf.OpenFromFile(filepath, 0);  

  21.             IRasterWorkspace tifrwp = tifwp as IRasterWorkspace;  

  22.             IRasterDataset rasterDataset = tifrwp.OpenRasterDataset(file);  

  23.             lastIndex = file.LastIndexOf(@“.”);  

  24.             file1 = file.Substring(0, lastIndex);  

  25.             imortRasterData(filepath, file, file1);  

  26.             MessageBox.Show(“导入成功”);  

  27.         }  

  28.     }  






[csharp] view
plain
 copy



  1. private void imortRasterData(string strRasterFileDir, string strRasterFileName, string strOutName)  

  2.     {  

  3.         try  

  4.         {  

  5.             //判断是否有重名现象  

  6.             IWorkspace2 pWS2 = workspace as IWorkspace2;  

  7.             //如果名称已存在  

  8.             if (pWS2.get_NameExists(esriDatasetType.esriDTRasterDataset, strOutName))  

  9.             {  

  10.                 DialogResult result;  

  11.                 result = MessageBox.Show(this“栅格文件名  “ + strOutName + ”  在数据库中已存在!” + “\r是否覆盖?”“相同文件名”, MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);  

  12.                 //覆盖原矢量要素  

  13.                 if (result == DialogResult.Yes)  

  14.                 {  

  15.                     IRasterWorkspaceEx pRWs = workspace as IRasterWorkspaceEx;  

  16.                     IDataset pDataset = pRWs.OpenRasterDataset(strOutName) as IDataset;  

  17.                     pDataset.Delete();  

  18.                     pDataset = null;  

  19.                 }  

  20.                 else if (result == DialogResult.No)  

  21.                 {  

  22.                     return;  

  23.                 }  

  24.             }  

  25.             IWorkspaceFactory pRasterWsFac = new RasterWorkspaceFactoryClass();  

  26.             IWorkspace pWs = pRasterWsFac.OpenFromFile(strRasterFileDir, 0);  

  27.             IRasterDataset pRasterDs = null;  

  28.             IRasterWorkspace pRasterWs;  

  29.             if (!(pWs is IRasterWorkspace))  

  30.             {  

  31.                 return;  

  32.             }  

  33.             pRasterWs = pWs as IRasterWorkspace;  

  34.             pRasterDs = pRasterWs.OpenRasterDataset(strRasterFileName);  

  35.             ISaveAs2 saveAs2 = (ISaveAs2)pRasterDs;  

  36.             IRasterStorageDef rasterStorageDef = new RasterStorageDefClass();  

  37.             IRasterStorageDef2 rasterStorageDef2 = (IRasterStorageDef2)rasterStorageDef;  

  38.             rasterStorageDef2.CompressionType =esriRasterCompressionType.esriRasterCompressionUncompressed;  

  39.             rasterStorageDef2.CompressionQuality = 100;  

  40.             rasterStorageDef2.Tiled = true;  

  41.             rasterStorageDef2.TileHeight = 128;  

  42.             rasterStorageDef2.TileWidth = 128;  

  43.             saveAs2.SaveAsRasterDataset(strOutName, workspace, “gdb”, rasterStorageDef2);  

  44.         }  

  45.         catch (Exception ex)  

  46.         {  

  47.             MessageBox.Show(ex.ToString());  

  48.             return;  

  49.         }  

  50.     }  


 


7.从SDE中读取数据


  1. private void ReadFromSDE_Click(object sender, EventArgs e)  

  2.     {  

  3.         this.cbbDataSet.Items.Clear();  

  4.         this.FeatureLayer.Items.Clear();  

  5.         this.RasterLayer.Items.Clear();  

  6.         IEnumDatasetName enumDatasetName;  

  7.         IDatasetName datasetName;  

  8.         //获取矢量数据集  

  9.         enumDatasetName = workspace.get_DatasetNames(esriDatasetType.esriDTFeatureDataset);  

  10.         datasetName = enumDatasetName.Next();  

  11.         while (datasetName != null)  

  12.         {  

  13.             this.cbbDataSet.Items.Add(datasetName.Name);  

  14.             datasetName = enumDatasetName.Next();  

  15.         }  

  16.         //获取图层名  

  17.         enumDatasetName=workspace.get_DatasetNames(esriDatasetType.esriDTFeatureClass);  

  18.         datasetName = enumDatasetName.Next();  

  19.         while (datasetName != null)  

  20.         {  

  21.             this.FeatureLayer.Items.Add(datasetName.Name);  

  22.             datasetName = enumDatasetName.Next();  

  23.         }  

  24.         //获取栅格图层名  

  25.         enumDatasetName = workspace.get_DatasetNames(esriDatasetType.esriDTRasterDataset);  

  26.         datasetName = enumDatasetName.Next();  

  27.         while (datasetName != null)  

  28.         {  

  29.             this.RasterLayer.Items.Add(datasetName.Name);  

  30.             datasetName = enumDatasetName.Next();  

  31.         }  

  32.         MessageBox.Show(“读取成功”);  

  33.     }  


8.遍历数据集中的文件


  1. private void cbbDataSet_TextChanged(object sender, EventArgs e)  

  2.     {  

  3.         this.FeatureLayer.Items.Clear();  

  4.         IDataset dataset;  

  5.         IEnumDataset enumDataset;  

  6.         enumDataset = workspace.get_Datasets(esriDatasetType.esriDTFeatureDataset);  

  7.         dataset = enumDataset.Next();  

  8.         IDataset pDataset = null;  

  9.         while (dataset != null)  

  10.         {  

  11.             if (dataset.Name == this.cbbDataSet.Text)  

  12.             {  

  13.                 pDataset = dataset as IDataset;  

  14.                 break;  

  15.             }  

  16.             dataset = enumDataset.Next();  

  17.         }  

  18.         IFeatureDataset featDs = pDataset as IFeatureDataset;  

  19.         IFeatureClassContainer fcContainer = featDs as IFeatureClassContainer;  

  20.         for (int i = 0; i < fcContainer.ClassCount; i++)  

  21.         {  

  22.             this.FeatureLayer.Items.Add(fcContainer.get_Class(i).AliasName);  

  23.         }  

  24.     }  


9.数据的加载


  1. private void btnOk_Click(object sender, EventArgs e)  

  2.     {  

  3.         //直接从sde中读取数据.  

  4.         if (this.FeatureLayer.Text != “” && this.cbbDataSet.Text == “”)  

  5.         {  

  6.             IEnumDataset enumDataset;  

  7.             IDataset dataset;  

  8.             IFeatureLayer pFeatureLayer=new FeatureLayerClass();  

  9.             //获取图层名  

  10.             enumDataset = workspace.get_Datasets(esriDatasetType.esriDTFeatureClass);  

  11.             dataset = enumDataset.Next();  

  12.             while (dataset != null)  

  13.             {  

  14.                 if (dataset.Name.ToLower() == this.FeatureLayer.Text.ToLower())  

  15.                 {  

  16.                     pFeatureLayer.FeatureClass = dataset as IFeatureClass;  

  17.                     break;  

  18.                 }  

  19.                 dataset = enumDataset.Next();  

  20.             }  

  21.             this.axMapControl1.AddLayer(pFeatureLayer as ILayer);  

  22.             this.axMapControl1.Extent = this.axMapControl1.FullExtent;  

  23.         }  

  24.         // 从sde数据集中读取数据  

  25.         if (this.FeatureLayer.Text != “” && this.cbbDataSet.Text != “”)  

  26.         {  

  27.             IDataset dataset;  

  28.             IEnumDataset enumDataset;  

  29.             enumDataset = workspace.get_Datasets(esriDatasetType.esriDTFeatureDataset);  

  30.             dataset = enumDataset.Next();  

  31.             IDataset pDataset = null;  

  32.             while (dataset != null)  

  33.             {  

  34.                 if (dataset.Name == this.cbbDataSet.Text)  

  35.                 {  

  36.                     pDataset = dataset as IDataset;  

  37.                     break;  

  38.                 }  

  39.                 dataset = enumDataset.Next();  

  40.             }  

  41.             IFeatureDataset featDs = pDataset as IFeatureDataset;  

  42.             IFeatureLayer pFeatureLayer = new FeatureLayerClass();  

  43.             IFeatureClassContainer fcContainer = featDs as IFeatureClassContainer;  

  44.             for (int i = 0; i < fcContainer.ClassCount; i++)  

  45.             {  

  46.                 if (fcContainer.get_Class(i).AliasName.ToLower() == this.FeatureLayer.Text.ToLower())  

  47.                 {  

  48.                     pFeatureLayer.FeatureClass = fcContainer.get_Class(i) as IFeatureClass;  

  49.                     break;  

  50.                 }  

  51.                 //this.FeatureLayer.Items.Add(fcContainer.get_Class(i).AliasName);  

  52.             }  

  53.             this.axMapControl1.AddLayer(pFeatureLayer as ILayer);  

  54.             this.axMapControl1.Extent = this.axMapControl1.FullExtent;  

  55.         }  

  56.         //加载栅格数据  

  57.         if (this.RasterLayer.Text != “”)  

  58.         {  

  59.             IDataset dataset;  

  60.             IEnumDataset enumDataset;  

  61.             enumDataset = workspace.get_Datasets(esriDatasetType.esriDTRasterDataset);  

  62.             dataset = enumDataset.Next();  

  63.             IDataset pDataset = null;  

  64.             while (dataset != null)  

  65.             {  

  66.                 if (dataset.Name.ToLower() == this.RasterLayer.Text.ToLower())  

  67.                 {  

  68.                     pDataset = dataset as IDataset;  

  69.                     break;  

  70.                 }  

  71.                 dataset = enumDataset.Next();  

  72.             }  

  73.             IRasterDataset pRasterDataset = dataset as IRasterDataset;  

  74.             IRasterLayer pRasLyr=new RasterLayerClass();  

  75.             pRasLyr.CreateFromDataset(pRasterDataset);  

  76.             this.axMapControl1.AddLayer(pRasLyr as ILayer);  

  77.             this.axMapControl1.Extent = this.axMapControl1.FullExtent;  

  78.         }  

  79.         MessageBox.Show(“加载成功”);  

  80.     }  





转载自:https://blog.csdn.net/baidu_23263735/article/details/78259938

You may also like...