private void method_0(IList ilist_0, IWorkspace iworkspace_0) { IEnumDataset dataset = iworkspace_0.get_Datasets(esriDatasetType.esriDTAny); dataset.Reset(); for (IDataset dataset2 = dataset.Next(); dataset2 != null; dataset2 = dataset.Next()) { if (dataset2.Type == esriDatasetType.esriDTFeatureClass) { if ((dataset2 as IFeatureClass).FeatureType == esriFeatureType.esriFTSimple) { ilist_0.Add(new ObjectWrap(dataset2)); } } else if (dataset2.Type == esriDatasetType.esriDTFeatureDataset) { IEnumDataset subsets = dataset2.Subsets; subsets.Reset(); for (IDataset dataset4 = subsets.Next(); dataset4 != null; dataset4 = subsets.Next()) { if ((dataset4.Type == esriDatasetType.esriDTFeatureClass) && ((dataset4 as IFeatureClass).FeatureType == esriFeatureType.esriFTSimple)) { ilist_0.Add(new ObjectWrap(dataset4)); } } } } }
//获得mdb/gdb中要素类 public List <string> Getfeatureclass(IWorkspace pWorkspaceMDB) { List <string> list = new List <string>(); IEnumDataset enumDataset = pWorkspaceMDB.get_Datasets(esriDatasetType.esriDTFeatureClass) as IEnumDataset; IDataset dataset = enumDataset.Next(); while (dataset != null) { if (dataset.Type == esriDatasetType.esriDTFeatureClass) { //IFeatureClass pFeatureClass = dataset as IFeatureClass; //IDataset pDataset = pFeatureClass as IDataset;; list.Add(dataset.Name); dataset = enumDataset.Next(); } } enumDataset = pWorkspaceMDB.get_Datasets(esriDatasetType.esriDTFeatureDataset) as IEnumDataset; dataset = enumDataset.Next(); while (dataset != null) { if (dataset.Type == esriDatasetType.esriDTFeatureDataset) { IEnumDataset pEnumDataset = dataset.Subsets; IDataset dataset2 = pEnumDataset.Next(); while (dataset2 != null) { list.Add(dataset2.Name); dataset2 = pEnumDataset.Next(); } } dataset = enumDataset.Next(); } return(list); }
//加载列表 private void LoadDataGridView() { if (comboBoxSource.Text.Trim() != "" && comboBoxCatalog.Text != "") { dataGridView.Rows.Clear(); //IWorkspaceFactory Pwf = new FileGDBWorkspaceFactoryClass(); //IWorkspace pWorkspace = (IWorkspace)(Pwf.OpenFromFile(GetSourcePath(comboBoxSource.Text), 0)); IWorkspace pWorkspace = GetWorkspace(comboBoxSource.Text); if (pWorkspace == null) { MessageBox.Show("数据源空间不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } IEnumDataset enumDataset = pWorkspace.get_Datasets(esriDatasetType.esriDTRasterCatalog) as IEnumDataset; IDataset dataset = enumDataset.Next(); while (dataset != null) { if (dataset.Name.Trim() == comboBoxCatalog.Text.Trim()) { ITable pTable = dataset as ITable; //IRasterCatalog irastercatalog = (IRasterCatalog)dataset; ICursor pCursor = pTable.Search(null, false); IRow pRow = pCursor.NextRow(); while (pRow != null) { dataGridView.Rows.Add(new object[] { true, pRow.get_Value(pRow.Fields.FindField("Name")) }); pRow = pCursor.NextRow(); } return; } dataset = enumDataset.Next(); } } }
/// <summary> /// 获取数据集下的要素类 /// </summary> /// <param name="workspace">工作空间</param> /// <param name="featureDatasetName">数据集名称</param> /// <param name="featureClassName">要素类名称</param> /// <returns></returns> public static IFeatureClass GetFeatureClass(IWorkspace workspace, string featureDatasetName, string featureClassName) { IDataset dataset = (IDataset)workspace; IEnumDataset enumDataset = dataset.Subsets; enumDataset.Reset(); //get the datasets from enumerator IDataset datasetNext = enumDataset.Next(); //loop through the datasets while (datasetNext != null) { if (datasetNext.Name == featureDatasetName) { IEnumDataset enumDataset2 = datasetNext.Subsets; enumDataset2.Reset(); IDataset dataset3 = enumDataset2.Next(); while (dataset3 != null) { if (dataset3.Name == featureClassName) { return((IFeatureClass)dataset3); } dataset3 = enumDataset2.Next(); } } datasetNext = enumDataset.Next(); } return(null); }
// Adds barriers from object dataset private void AddBarriersFromDataset(IDataset objDS) { if (objDS.Type == esriDatasetType.esriDTFeatureClass) { // It is Feature Class AddBarriersFromFeatureClass(objDS as IFeatureClass); } else if (objDS.Type == esriDatasetType.esriDTFeatureDataset) { // It is Feature DatasetClass IFeatureDataset objFeatureDS = null; objFeatureDS = objDS as IFeatureDataset; // Enum Dataset subsets IEnumDataset objEnumDS = null; objEnumDS = objFeatureDS.Subsets; IDataset objSubDS = null; objSubDS = objEnumDS.Next(); while ( objSubDS != null) { // Add Barriers from subset Feature Class if (objSubDS.Type == esriDatasetType.esriDTFeatureClass) AddBarriersFromFeatureClass(objSubDS as IFeatureClass); objSubDS = objEnumDS.Next(); } } }
//3/10/2009 删除工作空间内的所有要素类 public static void DeleteAllFeatCls(IWorkspace pworkspace) { IEnumDataset pEnumFeatDataset = default(IEnumDataset); IDataset pDataset = default(IDataset); IFeatureDataset pFeatDataset = default(IFeatureDataset); pEnumFeatDataset = pworkspace.get_Datasets(esriDatasetType.esriDTAny); pEnumFeatDataset.Reset(); pDataset = pEnumFeatDataset.Next(); while ((pDataset != null)) { if (pDataset.CanDelete()) { if (pDataset.Type == esriDatasetType.esriDTFeatureDataset) { pFeatDataset = (IFeatureDataset)pDataset; pFeatDataset.Delete(); } else { pDataset.Delete(); } //pDataset.Delete() pDataset = pEnumFeatDataset.Next(); } } }
private void button5_Click(object sender, EventArgs e) { axMapControl1.Map.ClearLayers(); string _pInstance = "sde:oracle11g:172.31.2.90/orcl"; string _pUser = "******"; string _pPassword = "******"; string _pVersion = "sde.DEFAULT"; IWorkspace pWS = null; pWS = GetSDEWorkspace(_pInstance, _pUser, _pPassword, _pVersion) as IWorkspace; try { IEnumDatasetName pEDatasetNames = pWS.get_DatasetNames(esriDatasetType.esriDTAny); IDatasetName pDatasetName = pEDatasetNames.Next(); while (pDatasetName != null) { string name = pDatasetName.Name; if (pDatasetName.Name.Equals("CSTEST.QDTEST")) { if (pDatasetName.Type.Equals(esriDatasetType.esriDTFeatureDataset)) { IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWS; IFeatureDataset pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset("CSTEST.QDTEST"); IEnumDataset pEnumDataset = pFeatureDataset.Subsets; pEnumDataset.Reset(); IDataset pDataset = pEnumDataset.Next(); comboBox1.Items.Clear(); while (pDataset != null) { if (pDataset.Type == esriDatasetType.esriDTFeatureClass) { comboBox1.Items.Add(pDataset.Name); if (pDataset is IFeatureClass) { IFeatureLayer pFeatureLayer = new FeatureLayerClass(); pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset.Name); pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName; axMapControl1.Map.AddLayer(pFeatureLayer); } } pDataset = pEnumDataset.Next(); } comboBox1.Text = comboBox1.Items[0].ToString(); } } pDatasetName = pEDatasetNames.Next(); } } catch (Exception ex) { MessageBox.Show(ex.StackTrace); } }
public static IFeatureClass[] GetFeatureClassByDataset(IWorkspace m_workspace, string datasetName) { List <IFeatureClass> feaList = new List <IFeatureClass>(); IEnumDataset enumDs = m_workspace.get_Datasets(esriDatasetType.esriDTFeatureDataset); IDataset ds = enumDs.Next(); while (ds != null) { if (ds is IFeatureDataset && ds.Name.ToUpper().Trim() == datasetName.ToUpper()) { IEnumDataset enumFs = (ds as IFeatureDataset).Subsets; IDataset ds2 = enumFs.Next(); while (ds2 != null) { if (ds2 is IFeatureClass) { feaList.Add(ds2 as IFeatureClass); } ds2 = enumFs.Next(); } } ds = enumDs.Next(); } return(feaList.ToArray()); }
private void Add_Tables() { IWorkspaceFactory pWorkspaceFactory = new AccessWorkspaceFactoryClass(); IWorkspace pWorkspace = (IWorkspace)pWorkspaceFactory.OpenFromFile(@"C:\Users\mgh\Desktop\Data\GDB_DneshgaheAzad.mdb", 0); IEnumDataset pEnumDataset = pWorkspace.get_Datasets(esriDatasetType.esriDTTable); IDataset pDataset = pEnumDataset.Next(); m_ArrayTables = new ArrayList(); while (pDataset != null) { if (pDataset is ITable) { cboLayerAttributeTable.Items.Add(pDataset.Name); cboLayerGraph.Items.Add(pDataset.Name); m_ArrayTables.Add(pDataset); } pDataset = pEnumDataset.Next(); } if (cboLayerAttributeTable.Items.Count > 0) { cboLayerAttributeTable.SelectedIndex = 0; } if (cboLayerGraph.Items.Count > 0) { cboLayerGraph.SelectedIndex = 0; } }
private void button2_Click(object sender, EventArgs e) { string PDBPath = mdbPath(); if (PDBPath != "") { IWorkspaceFactory pWSFactory = new AccessWorkspaceFactoryClass(); IWorkspace pWS = pWSFactory.OpenFromFile(PDBPath, 0); IEnumDataset pEDataset = pWS.get_Datasets(esriDatasetType.esriDTAny); IDataset pDataset = pEDataset.Next(); comboBox1.Items.Clear(); while (pDataset != null) { if (pDataset.Type == esriDatasetType.esriDTFeatureClass) { comboBox1.Items.Add(pDataset.Name); } pDataset = pEDataset.Next(); } comboBox1.Text = comboBox1.Items[0].ToString(); } }
//#######################以下函数可配合使用######################## //**************************Load Raster Begin**************************** //函数编号:RasterLoad-01 //函数名:DirToMosaic //函数功能:把文件夹中的Raster文件合并到新的Raster文件中去 //参数:sDir:栅格文件夹 // pDataset:最后合并的RasterDataset //备注:pDataset可以使Geodataset中的参数,如果不存在利用函数创建 public void DirToMosaic(string sDir, IRasterDataset pDataset) { //load all raster datasets in the input directory to the raster dataset //the geodatabase raster dataset has to exist, //if not create it first with proper storage parameters. IWorkspaceFactory pWsFact = new RasterWorkspaceFactoryClass();; IWorkspace pFileWs = pWsFact.OpenFromFile(sDir, 0); IRasterDatasetEdit pSDEDs = pDataset as IRasterDatasetEdit; IRasterDataset2 pRasterDs; // load raster datasets from the dir IEnumDataset pEunmDatasets = pFileWs.get_Datasets(esriDatasetType.esriDTRasterDataset); pEunmDatasets.Reset(); pRasterDs = pEunmDatasets.Next() as IRasterDataset2; while (!(pRasterDs == null)) { //!!!pRasterDs.CompleteName; pSDEDs.Mosaic(pRasterDs.CreateFullRaster(), 0.5); //!!!注意IRasterDataset2::CreateFullRaster()方法可以简单实现从RasterDataset到Raster的转换 pRasterDs = pEunmDatasets.Next() as IRasterDataset2; } //cleanup pEunmDatasets = null; pRasterDs = null; pWsFact = null; pSDEDs = null; pFileWs = null; }
private void comboBoxSource_SelectedIndexChanged(object sender, EventArgs e) { comboBoxCatalog.Items.Clear(); comboBoxCatalog.Text = ""; if (comboBoxSource.Text.Trim() != "") { //IWorkspaceFactory Pwf = new FileGDBWorkspaceFactoryClass(); //if(!Directory.Exists(GetSourcePath(comboBoxSource.Text))) // return; //IWorkspace pWorkspace = (IWorkspace)(Pwf.OpenFromFile(GetSourcePath(comboBoxSource.Text), 0)); IWorkspace pWorkspace = GetWorkspace(comboBoxSource.Text); if (pWorkspace == null) { return; } IEnumDataset enumDataset = pWorkspace.get_Datasets(esriDatasetType.esriDTRasterCatalog) as IEnumDataset; IDataset dataset = enumDataset.Next(); while (dataset != null) { comboBoxCatalog.Items.Add(dataset.Name); dataset = enumDataset.Next(); } if (comboBoxCatalog.Items.Count > 0) { comboBoxCatalog.SelectedIndex = 0; } } }
//通过IWokspace和图层名称获取图层 public static List <IFeatureClass> GetFeatureClass(IWorkspace pWorkspace, string DatasetName) { List <IFeatureClass> newlist = new List <IFeatureClass>(); if (pWorkspace == null || DatasetName == "") { return(newlist); } IEnumDataset pEnumDataset = pWorkspace.get_Datasets(esriDatasetType.esriDTFeatureDataset); pEnumDataset.Reset(); IFeatureDataset pFeaDataset = pEnumDataset.Next() as IFeatureDataset; while (pFeaDataset != null) { if (pFeaDataset.Name == DatasetName) { IFeatureClassContainer pFeatureClassContainer = pFeaDataset as IFeatureClassContainer; IEnumFeatureClass pEnumFeatureClass = pFeatureClassContainer.Classes; IFeatureClass pFeatureClass = pEnumFeatureClass.Next(); while (pFeatureClass != null) { newlist.Add(pFeatureClass); pFeatureClass = pEnumFeatureClass.Next(); } } pFeaDataset = pEnumDataset.Next() as IFeatureDataset; } return(newlist); }
private void cmbLayer_SelectedIndexChanged(object sender, EventArgs e) { this.lblTips.Text = ""; Application.DoEvents(); if (this.cmbLayer.Text == "所有图层") { _CurFeatureClass = null; } else { string strCurName = this.cmbLayer.Text; IEnumDataset pEnumDs = _CurFeatureDataset.Subsets; pEnumDs.Reset(); IDataset pDs = pEnumDs.Next(); while (pDs != null) { IFeatureClass pFeatureClass = pDs as IFeatureClass; if (pFeatureClass.AliasName == strCurName) { _CurFeatureClass = pFeatureClass; break; } pDs = pEnumDs.Next(); } } InitContentGrid(); }
public IList <IFeatureClass> TravelWorkSpace4FeatureClass(IWorkspace workspace, string datasetName) { IList <IFeatureClass> result = new List <IFeatureClass>(); using (ComReleaser releaser = new ComReleaser()) { //遍历要素集中的要素类 IEnumDataset dts = workspace.get_Datasets(esriDatasetType.esriDTFeatureDataset); //releaser.ManageLifetime(dts); IDataset dt = dts.Next(); //releaser.ManageLifetime(dt); while (dt != null) { if (dt.Name.Equals(datasetName)) { IEnumDataset fcs = dt.Subsets; //releaser.ManageLifetime(fcs); IDataset fc = fcs.Next(); //releaser.ManageLifetime(fc); while (fc != null) { result.Add((fc as IFeatureClass)); fc = fcs.Next(); } } dt = dts.Next(); } } return(result); }
public static IFeatureClass GetFeatureClassByID(IWorkspace workspace, int classID) { IEnumDataset enumDs = workspace.get_Datasets(esriDatasetType.esriDTAny); IDataset ds = enumDs.Next(); while (ds != null) { if (ds is IFeatureClass) { if ((ds as IFeatureClass).FeatureClassID == classID) { return(ds as IFeatureClass); } } else if (ds is IFeatureDataset) { IEnumDataset enumDs2 = (ds as IFeatureDataset).Subsets; IDataset ds2 = enumDs2.Next(); while (ds2 != null) { if (ds2 is IFeatureClass) { if ((ds2 as IFeatureClass).FeatureClassID == classID) { return(ds2 as IFeatureClass); } } ds2 = enumDs2.Next(); } } ds = enumDs.Next(); } return(null); }
/* private void FeatureLayer(object featureClass) * { * object[] dataName = GetData(); * * IFeatureClass pFeatureClass = featureClass as IFeatureClass; * // IFeatureLayer pFeaturelayer; * // pFeaturelayer = new FeatureLayerClass(); * // pFeaturelayer.FeatureClass = pFeatureClass; * // pFeaturelayer.Name = pFeaturelayer.FeatureClass.AliasName; * m_pFeaturelayer.FeatureClass = pFeatureClass; * }*/ /// <summary> /// 加载Dataset /// </summary> /// <param name="fileFullPath"></param> /// <param name="dsName"></param> private void AddDataset(object dataSet, IMap pMap) { //获取FeatureDataset IFeatureDataset pFeatureDataset = (IFeatureDataset)dataSet; IWorkspace pWorkspace = pFeatureDataset.Workspace; IFeatureWorkspace pFeatureWorkspace; IFeatureLayer pFeatureLayer; pFeatureWorkspace = pWorkspace as IFeatureWorkspace; IEnumDataset pEnDS = pFeatureDataset.Subsets; pEnDS.Reset(); //遍历Dataset IDataset pDS = pEnDS.Next(); while (pDS is IFeatureClass) { pFeatureLayer = new FeatureLayerClass(); pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDS.Name); pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName; m_pFeaturelayer = pFeatureLayer; pMap.AddLayer(pFeatureLayer);//加载Dataset中的FeatureClass pDS = pEnDS.Next(); } m_pActiveView.Refresh();//刷新 }
public static IDataset GetDatasetByName(IWorkspace m_workspace, string name) { IEnumDataset enum_ds = m_workspace.get_Datasets(esriDatasetType.esriDTAny); IDataset ds = enum_ds.Next(); while (ds != null) { if (ds.Name.ToUpper() == name.ToUpper()) { return(ds); } else if (ds is IFeatureDataset) { IFeatureDataset fea_ds = ds as IFeatureDataset; IEnumDataset enum_sub_ds = fea_ds.Subsets; IDataset sub_ds = enum_sub_ds.Next(); while (sub_ds != null) { if (sub_ds.Name.ToUpper() == name.ToUpper()) { return(sub_ds); } sub_ds = enum_sub_ds.Next(); } } ds = enum_ds.Next(); } return(null); }
/// <summary> /// 打开数据库中FeatureClasss /// </summary> /// <param name="FileGdbName"></param> /// <param name="featureDataset"></param> /// <param name="featureclassname"></param> /// <returns></returns> public static IFeatureClass OpenFeatureClass(string FileGdbName, string featureDataset, string featureclassname) { IWorkspaceFactory pworkspF = new FileGDBWorkspaceFactoryClass(); IWorkspace workspace = pworkspF.OpenFromFile(FileGdbName, 0); IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace; IFeatureClass featureClass = null; IFeatureDataset pFeatureDataset = featureWorkspace.OpenFeatureDataset(featureDataset); if (pFeatureDataset == null) { return(null); } IEnumDataset pEnumDataset = pFeatureDataset.Subsets; pEnumDataset.Reset(); IDataset dataset = pEnumDataset.Next(); while (dataset != null) { if (dataset.Name == featureclassname) { featureClass = dataset as IFeatureClass; break; } dataset = pEnumDataset.Next(); } return(featureClass); }
/// <summary> /// 以迭代形式返回工作空间下的所有要素类,包括数据集中的要素类 /// </summary> /// <param name="workspace">工作空间</param> /// <returns>要素类枚举数(要素类集合)</returns> private static IEnumerable GetDataset(this IWorkspace workspace) { //工作空间下的要素类 IEnumDataset enumDataset = workspace.Datasets[esriDatasetType.esriDTFeatureClass]; IFeatureClass featureClass = enumDataset.Next() as IFeatureClass; while (featureClass != null) { yield return(featureClass); featureClass = enumDataset.Next() as IFeatureClass; } //工作空间下的要素集 IEnumDataset dsEnumDataset = workspace.Datasets[esriDatasetType.esriDTFeatureDataset]; IDataset dataset = dsEnumDataset.Next(); while (dataset != null)//遍历要数集 { IFeatureDataset featureDataset = (IFeatureDataset)dataset; IFeatureClassContainer featureclassContainer = (IFeatureClassContainer)featureDataset; IEnumFeatureClass enumFeatureClass = featureclassContainer.Classes; IFeatureClass dsFeatureClass = enumFeatureClass.Next(); while (dsFeatureClass != null)//在每一个数据集中遍历数据层IFeatureClass { yield return(dsFeatureClass); dsFeatureClass = enumFeatureClass.Next(); } dataset = dsEnumDataset.Next(); } }
/// <summary> /// 判断工作空间中是否含有某个要素类 /// </summary> /// <param name="pW"></param> /// <param name="pFeatureClassName"></param> /// <returns></returns> private bool isExitFeatureClass(IWorkspace pW, string pFeatureClassName) { IEnumDataset o = pW.get_Datasets(esriDatasetType.esriDTAny); o.Reset(); for (IDataset dataset2 = o.Next(); dataset2 != null; dataset2 = o.Next()) { if (dataset2.Name == pFeatureClassName) { return(true); } IEnumDataset subsets = dataset2.Subsets; for (IDataset dataset4 = subsets.Next(); dataset4 != null; dataset4 = subsets.Next()) { IFeatureClass class2 = dataset4 as IFeatureClass; if (((class2 != null) && (class2.FeatureType != esriFeatureType.esriFTAnnotation)) && (class2.AliasName == pFeatureClassName)) { return(true); } } if (subsets != null) { Marshal.ReleaseComObject(subsets); } } if (o != null) { Marshal.ReleaseComObject(o); } return(false); }
private void comboBoxSource_SelectedIndexChanged(object sender, EventArgs e) { comboBoxCatalog.Items.Clear(); comboBoxCatalog.Text = ""; dataGridView.Rows.Clear(); if (comboBoxSource.Text.Trim() != "") { //IWorkspaceFactory Pwf = new FileGDBWorkspaceFactoryClass(); // IWorkspace pWorkspace = (IWorkspace)(Pwf.OpenFromFile(GetSourcePath(comboBoxSource.Text), 0)); IWorkspace pWorkspace = GetWorkspace(comboBoxSource.Text); if (pWorkspace == null) { MessageBox.Show("数据源空间不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } IEnumDataset enumDataset = pWorkspace.get_Datasets(esriDatasetType.esriDTRasterCatalog) as IEnumDataset; IDataset dataset = enumDataset.Next(); while (dataset != null) { comboBoxCatalog.Items.Add(dataset.Name); dataset = enumDataset.Next(); } if (comboBoxCatalog.Items.Count > 0) { comboBoxCatalog.SelectedIndex = 0; } } }
private void ListDatasets() { tvDatasets.Nodes.Clear(); if (m_workspace == null) { return; } TreeNode rootNode = tvDatasets.Nodes.Add(System.IO.Path.GetFileNameWithoutExtension(m_workspace.PathName)); rootNode.ImageIndex = 27; rootNode.SelectedImageIndex = 27; rootNode.StateImageIndex = 0; IEnumDataset datasets = m_workspace.Datasets[esriDatasetType.esriDTAny]; datasets.Reset(); IDataset dataset = datasets.Next(); while (dataset != null) { if (dataset is IFeatureClass) { AddFeatureClassToTree(rootNode, dataset as IFeatureClass); } else if (dataset is IFeatureDataset) { AddFeatureDatasetToTree(rootNode, dataset as IFeatureDataset); } dataset = datasets.Next(); } tvDatasets.ExpandAll(); }
protected void RenameClassObjects(IWorkspace wsTarget) { int standardID = SysDbHelper.GetStandardIDBySchemaID(this.m_SchemaID); IEnumDataset enDataset = wsTarget.get_Datasets(esriDatasetType.esriDTAny); IDataset dsCurrent = enDataset.Next(); while (dsCurrent != null) { switch (dsCurrent.Type) { case esriDatasetType.esriDTTable: case esriDatasetType.esriDTFeatureClass: RenameClassObject(dsCurrent, standardID); break; case esriDatasetType.esriDTFeatureDataset: //RenameClassObject(dsCurrent, standardID); // FeatureDataset需要改吗 IEnumDataset enSubDataset = dsCurrent.Subsets; IDataset subDataset = enSubDataset.Next(); while (subDataset != null) { RenameClassObject(subDataset, standardID); subDataset = enSubDataset.Next(); } break; } System.Runtime.InteropServices.Marshal.ReleaseComObject(dsCurrent); dsCurrent = enDataset.Next(); } }
private void AddFeatureDatasetToTree(TreeNode parentNode, IFeatureDataset featDataset) { TreeNode featDSNode = parentNode.Nodes.Add(featDataset.Name); featDSNode.Tag = featDataset; featDSNode.ImageIndex = 9; featDSNode.SelectedImageIndex = 9; featDSNode.StateImageIndex = 0; IEnumDataset datasets = featDataset.Subsets; datasets.Reset(); IDataset dataset = datasets.Next(); while (dataset != null) { if (dataset is IFeatureClass) { AddFeatureClassToTree(featDSNode, dataset as IFeatureClass); } else if (dataset is IFeatureDataset) { AddFeatureDatasetToTree(featDSNode, dataset as IFeatureDataset); } dataset = datasets.Next(); } }
public static IRasterBand GetRasterBand(IWorkspace pSDEWorkspace, string strRasterDataset, string strBandName) { IEnumDataset pEnumdataset = pSDEWorkspace.get_Datasets(esriDatasetType.esriDTRasterDataset); IRasterBandCollection pRasterBandCollection = null; IEnumRasterBand pEnumRasterBand = null; IRasterBand pRasterBand = null; IDataset pDataset = pEnumdataset.Next(); while (pDataset != null) { if (pDataset.Name == strRasterDataset) { pRasterBandCollection = (IRasterBandCollection)pDataset; pEnumRasterBand = pRasterBandCollection.Bands; pRasterBand = pEnumRasterBand.Next(); while (pRasterBand != null) { if (pRasterBand.Bandname == strBandName) { return(pRasterBand); } pRasterBand = pEnumRasterBand.Next(); } } pDataset = pEnumdataset.Next(); } pRasterBandCollection = null; pEnumRasterBand = null; pRasterBand = null; pEnumdataset = null; pDataset = null; return(null); }
//读取mdb数据 public List <ILayer> ReadLayerFromAccess(List <string> filePathList) { List <ILayer> layerList = new List <ILayer>(); if (filePathList.Count == 0) { return(null); } else { foreach (string path in filePathList) { IWorkspaceFactory pWorkspaceFactory = new AccessWorkspaceFactoryClass(); IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(path, 0); IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace; IEnumDataset pEnumDataset = pWorkspace.get_Datasets(esriDatasetType.esriDTFeatureClass) as IEnumDataset; pEnumDataset.Reset(); IDataset pDataset = pEnumDataset.Next(); while (pDataset is IFeatureClass) { IFeatureLayer pFeatureLayer = new FeatureLayerClass(); pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset.Name); pFeatureLayer.Name = pDataset.Name; ILayer pLayer = pFeatureLayer as ILayer; layerList.Add(pFeatureLayer as ILayer); pDataset = pEnumDataset.Next(); } } return(layerList); } }
public void LoadDB() { try { openFileDialog1 = new OpenFileDialog(); openFileDialog1.Title = "Browse mdb Files"; openFileDialog1.DefaultExt = "mdb"; openFileDialog1.Filter = "mdb Diles (*.mdb)|*.mdb"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { DBPath = openFileDialog1.FileName;; } IWorkspaceFactory AccessWorkSpace = new AccessWorkspaceFactoryClass(); IWorkspace MyWorkSpace = AccessWorkSpace.OpenFromFile(DBPath, 0); IFeatureWorkspace featWorkspace = MyWorkSpace as IFeatureWorkspace; IEnumDataset AllLayerFromDB = MyWorkSpace.get_Datasets(esriDatasetType.esriDTFeatureClass); IDataset SingleLayer = AllLayerFromDB.Next(); while (SingleLayer != null) { string LayerText = SingleLayer.Name; comboBox12.Items.Add(LayerText); SingleLayer = AllLayerFromDB.Next(); } comboBox12.Text = comboBox12.Items[0].ToString(); } catch { } }
public void Init(IServerObjectHelper pSOH) { serverObjectHelper = pSOH; mapService = (MapServer)serverObjectHelper.ServerObject; mapServerDataAccess = (IMapServerDataAccess)serverObjectHelper.ServerObject; // Check if this service contains a Utility Network layer unLayerInfo = soeUtil.GetUNLayerInfo(mapService); if (unLayerInfo != null) { // Get the Utility Network dataset IFeatureClass fc = (IFeatureClass)mapServerDataAccess.GetDataSource(mapService.DefaultMapName, unLayerInfo.SubLayers.Element[0]); // Get UN dataset IFeatureDataset fd = fc.FeatureDataset; IDataset ds = (IDataset)fd; IEnumDataset enumSubDS = ds.Subsets; IDataset subDS = enumSubDS.Next(); while (subDS != null) { if (subDS.Type == esriDatasetType.esriDTUtilityNetwork) { unDataset = subDS; break; } subDS = enumSubDS.Next(); } logger.LogMessage(ServerLogger.msgType.infoStandard, soe_name + ".init()", 200, "UN dataset found: " + unDataset.Name); } }
//通过IWorkspace获取图层 public static IFeatureClass GetFeatureClass(IWorkspace pWorkspace, string LayerName, string DatasetName) { if (pWorkspace == null) { return(null); } IEnumDataset pEnumDataset = pWorkspace.get_Datasets(esriDatasetType.esriDTFeatureClass); pEnumDataset.Reset(); IDataset pDataset = pEnumDataset.Next(); while (pDataset != null) { if (pDataset.Name == LayerName) { return(pDataset as IFeatureClass); } pDataset = pEnumDataset.Next(); } pEnumDataset = pWorkspace.get_Datasets(esriDatasetType.esriDTFeatureDataset); pDataset = pEnumDataset.Next(); // IFeatureDataset pFeaDataset = pEnumDataset.Next() as IFeatureDataset; while (pDataset != null) { if (DatasetName == "") { IFeatureClassContainer pFeatureClassContainer = pDataset as IFeatureClassContainer; IEnumFeatureClass pEnumFeatureClass = pFeatureClassContainer.Classes; IFeatureClass pFeatureClass = pEnumFeatureClass.Next(); while (pFeatureClass != null) { if (pFeatureClass.AliasName.Contains(LayerName)) { return(pFeatureClass); } pFeatureClass = pEnumFeatureClass.Next(); } } else { if (pDataset.Name == DatasetName) { IFeatureClassContainer pFeatureClassContainer = pDataset as IFeatureClassContainer; IEnumFeatureClass pEnumFeatureClass = pFeatureClassContainer.Classes; IFeatureClass pFeatureClass = pEnumFeatureClass.Next(); while (pFeatureClass != null) { if (pFeatureClass.AliasName.Contains(LayerName)) { return(pFeatureClass); } pFeatureClass = pEnumFeatureClass.Next(); } } } pDataset = pEnumDataset.Next() as IFeatureDataset; } return(null); }
private static System.Collections.ArrayList AddUniques(IEnumDataset fromTheseDatasets, System.Collections.ArrayList AppendTo = null) { if (AppendTo == null) { AppendTo = new System.Collections.ArrayList(); } IDataset aDs = fromTheseDatasets.Next(); while (aDs != null) { // If this is a FeatureDataset, we need to // Check to see if the dataset is a FeatureClass or a table. This is all we care about if ((aDs.Type == esriDatasetType.esriDTFeatureClass) || (aDs.Type == esriDatasetType.esriDTTable)) { // Cast the DS as an ITable ITable thisTable = aDs as ITable; // Find the Data Source field int fldID = -1; if (thisTable.FindField("DataSourceID") != -1) { fldID = thisTable.FindField("DataSourceID"); } if (thisTable.FindField("DescriptionSourceID") != -1) { fldID = thisTable.FindField("DescriptionSourceID"); } if (thisTable.FindField("DefinitionSourceID") != -1) { fldID = thisTable.FindField("DefinitionSourceID"); } if (fldID == -1) { aDs = fromTheseDatasets.Next(); continue; } IField dsField = thisTable.Fields.get_Field(fldID); // Use the IDataStatistics interface to find unique values IDataStatistics dataStats = new DataStatisticsClass(); dataStats.Cursor = thisTable.Search(null, false); dataStats.Field = dsField.Name; System.Collections.IEnumerator uniqueValues = dataStats.UniqueValues; // Setup for iteration uniqueValues.Reset(); // Add the unique values to the collection try { uniqueValues.MoveNext(); while (uniqueValues.Current != null) { // Only add the value if it isn't already there... if (!AppendTo.Contains(uniqueValues.Current.ToString())) { AppendTo.Add(uniqueValues.Current.ToString()); } uniqueValues.MoveNext(); } } catch (Exception) { return null; } } // Iterate to the next dataset aDs = fromTheseDatasets.Next(); } return AppendTo; }