jmaccgs

Get IFeature's Parent Dataset

Discussion created by jmaccgs on Jun 2, 2011
Latest reply on Jun 2, 2011 by jmaccgs
Hello,

I have a hierarchical dataset as follows:


  • Water (Dataset)

  • [INDENT]WAnode (FeatureClass)
    WBoosterStation (FeatureClass)
    ...[/INDENT]
  • Address (Dataset)

  • [INDENT]AStreetName (FeatureClass)
    AStreetNumber (FeatureClass)
    ...[/INDENT]
When a new feature is created (WAnode, AStreetName, etc.), I need to get a sequence value for it. The sequence table we use depends on the Dataset in which the feature is being created.

So, if I'm going to create a new WAnode, which is in the Water dataset, I should be using the A_ASSETID_SEQ sequence table.

I'm building an Editor Add-In and the Events_OnCreateFeature event works nicely, as it passes in an IObject that can be cast to an IFeature; the new feature we're creating. The problem is that there's no way to get the topmost dataset for the feature. You can call newFeature.Class.AliasName to get the feature class' name (WAnode in our example), but there's no way to get the parent class (Water).

I can get a reference to the current editor workspace and work the other way, since IDatasets have a Subsets attribute to descend. In that case, I work through two levels of datasets looking for "WAnode", but in this case, the names I get from the dataset are prefixed with our schema name "Managed.". I can strip this out, but ultimately, this approach forces our feature classes to be named uniquely, even across datasets (if the Address dataset had a WAnode, we cannot determine which dataset our new feature belongs to).

Is there a way to get the new feature's parent dataset?

Or, alternatively, is there a way to get the current schema name so that I can at least strip the "Managed." programmatically? We can deal with the unique FeatureClass names restriction, although this is definitely the inferior solution.

Any comments are appreciated.

Here's the snippet of code I'm using to descend into the workspace datasets to search for the new feature's parent dataset:

void Events_OnCreateFeature(ESRI.ArcGIS.Geodatabase.IObject obj) {
            IFeature newFeature = (IFeature)obj;
            String datasetName = null;

            // Iterate through all of the datasets in this workspace,
            // trying to figure out the name of the dataset into which
            // this new feature is being added.
            IWorkspace workspace = ArcMap.Editor.EditWorkspace;
            IEnumDataset datasets = workspace.get_Datasets(esriDatasetType.esriDTFeatureDataset);
            IDataset dataset = datasets.Next();
            while (dataset != null)
            {
                // Iterate through all of the child datasets.
                IEnumDataset subsets = dataset.Subsets;
                IDataset subset = subsets.Next();
                while (subset != null)
                {
                    // Check to see if we have a match. If so, store it and
                    // get the **** out of here.
                    if (subset.BrowseName == newFeature.Class.AliasName) {
                        datasetName = subset.Name;
                        break;
                    }
                    subset = subsets.Next();
                }
                if (datasetName != null)
                    break;

                // Get the next dataset.
                dataset = datasets.Next();
            }
            ...
}

Outcomes