Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

In my application a plug-in datasource has been implemented to read specifically formatted files containing a mix of data types, including geometry in the form of polygons, lines, and points. Using the "Add Data" button in ArcScene/ArcMap, the file in question can be selected to reveal the different datasets (polygons or lines, usually) contained within the file, after which they can be added individually into the scene or map.

A functionality I'm looking to add involves automation of the add data process, so I need a way to specify which (one, some or all) dataset(s) within the file get added to the scene/map. However, what I have currently always adds the polygons (which are the default) and not line or point data.

Currently I'm creating feature layers as follows:

        // open workspace
        IWorkspace workspace = workspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(filename), 0);

        // cast as feature workspace
        IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace;

        // get a featureclass from the workspace
        IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(System.IO.Path.GetFileName(filename));

        // create a new feature layer 
        IFeatureLayer featureLayer = new FeatureLayerClass
        {
            Name = featureClass.AliasName,
            FeatureClass = featureClass
        }; 

The issue arises when getting a featureclass from the workspace, which is done by a string containing the name. It only works properly if I include the file extension in the argument to OpenFeatureClass(string), for example "3d_data.ext" instead of simply "3d_data". I find this confusing-- shouldn't the extension only be required when opening the workspace from the file?

When browsing the file via "Add data", the polygon data is called "3d_data", and lines is "3d_data-lines". Creation of the feature class fails if "3d_data-lines" is provided to OpenFeatureClass, just as it does if just "3d_data" is used. Do I have to Open a FeatureDataset from the file first, and then create individual featureclasses from the FeatureDataset?

share|improve this question
1  
if you loop through each featureclassname in your workspace, do you see one for each type? Can you scan the IWorkspace.Datasetnames for the one you want and use IName.Open() to open the featureclass you need? –  Kirk Kuykendall Dec 7 '10 at 23:11
add comment

1 Answer 1

Kirk's comments sent me in the right direction. It turns out the manner in which the plug-in datasource is implemented in my case I can only create directory workspaces. So the directory containing the file is created as a workspace,

        var directory = System.IO.Path.GetDirectoryName(filename);

        IWorkspace workspace = workspaceFactory.OpenFromFile(directory, 0); 

The file can then be opened as a dataset,

        /// cast the directory workspace into a feature workspace
        IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace;

        /// get the dataset from the selected file
        IFeatureDataset featureDataset = featureWorkspace.OpenFeatureDataset(System.IO.Path.GetFileName(filename));

And then each dataset (featureclass) can be retrieved and made into a layer.

        //initialize a list of layers that will be added to the map/scene
        List<IFeatureLayer> layers = new List<IFeatureLayer>();

        var subsets = featureDataset.Subsets;
        var dataset = subsets.Next();
        while (dataset != null)
        {
            var featureClass = dataset as IFeatureClass;

            // create a new feature layer 
            IFeatureLayer featureLayer = new FeatureLayerClass
            {
                Name = featureClass.AliasName,
                FeatureClass = featureClass
            };
            layers.Add(featureLayer);

            dataset = subsets.Next();
        }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.