Select to view content in your preferred language

Using InMemory FeatureClasses for geoprocessing

4376
5
07-08-2010 05:02 AM
PeterPowell
Deactivated User
Hello,

I have been struggling with using InMemory FeatureClasses in a geoprocessing. Not exactly sure how to set the in_features and out_feature_class to use InMemory feature classes. Everything I have tried has resulted in an
Failed to execute. Parameters are not valid.
ERROR 000732: Input Features: Dataset Addresses does not exist or is not supported
ERROR 000840: The value is not a Feature Class.

Has anyone actually sucessfully using InMemery feature classs as input and output for geoprocessing in C#?
0 Kudos
5 Replies
KirkKuykendall
Deactivated User
0 Kudos
PeterPowell
Deactivated User
Yes I can do this manually.

I have had a bit of success. I have been able to use an input inMemory fc but when I try to to specify it fails. I have tied the following:

1. For the GP I have set the workspace variable and just entered a new fc name in the out parameter of the geoprocessing wizard.
2. Tried both "In_Memory\Test" and "MyWorkspace\Test" and both return with an failed for unknown reason.

If I specify a shape file as the output I have no problem. Trying to minimize writing to disk.
0 Kudos
JohnHauck
Frequent Contributor
The following worked for me without error:

            UID CLSID = null;
            String featureClassName = "TestFC";

            //create and open in memory workspace
            IWorkspaceFactory WF = new InMemoryWorkspaceFactoryClass();
            IName name = WF.Create("", "MyWorkspace", null, 0) as IName;
            IWorkspace inMemWorkspace = (IWorkspace)name.Open();
            IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)inMemWorkspace;

            // assign the class id value if not assigned
            if (CLSID == null)
            {
                CLSID = new UIDClass();
                CLSID.Value = "esriGeoDatabase.Feature";
            }

            IObjectClassDescription objectClassDescription = new FeatureClassDescriptionClass();

            // create the fields using the required fields method
            IFields fields = objectClassDescription.RequiredFields;
            IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
            IField field = new FieldClass();

            // create a user defined text field
            IFieldEdit fieldEdit = (IFieldEdit)field;

            // setup field properties
            fieldEdit.Name_2 = "SampleField";
            fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
            fieldEdit.IsNullable_2 = true;
            fieldEdit.AliasName_2 = "Sample Field Column";
            fieldEdit.DefaultValue_2 = "test";
            fieldEdit.Editable_2 = true;
            fieldEdit.Length_2 = 100;

            // add field to field collection
            fieldsEdit.AddField(field);
            fields = (IFields)fieldsEdit;

            String strShapeField = "";

            // locate the shape field
            for (int j = 0; j < fields.FieldCount; j++)
            {
                if (fields.get_Field(j).Type == esriFieldType.esriFieldTypeGeometry)
                {
                    strShapeField = fields.get_Field(j).Name;
                }
            }

            //create feature class in memory workspace
            IFeatureClass featureClass = featureWorkspace.CreateFeatureClass(featureClassName, fields, CLSID, null, esriFeatureType.esriFTSimple, strShapeField, null);

            //copy the feature class to disk to verify process
            Geoprocessor gp = new Geoprocessor();
            CopyFeatures copyFeatLay = new CopyFeatures();
            copyFeatLay.in_features = featureClass;
            copyFeatLay.out_feature_class = @"C:\temp\test1.shp";
            gp.Execute(copyFeatLay, null);
0 Kudos
PeterPowell
Deactivated User
Thanks for the responses. Sorry for not being clear. I can write to a shape file with no problem. I want to write the results to in_memory featureclass like you can do when manualy calling the geoprocessing.

            Geoprocessor gp = new Geoprocessor();
            CopyFeatures copyFeatLay = new CopyFeatures();
            copyFeatLay.in_features = featureClass;
            copyFeatLay.out_feature_class = "In_Memory\Test";// or  "Myworkspace\Test"
            gp.Execute(copyFeatLay, null);
0 Kudos
ScottDickison
Deactivated User
Thanks for the responses. Sorry for not being clear. I can write to a shape file with no problem. I want to write the results to in_memory featureclass like you can do when manualy calling the geoprocessing.

            Geoprocessor gp = new Geoprocessor();
            CopyFeatures copyFeatLay = new CopyFeatures();
            copyFeatLay.in_features = featureClass;
            copyFeatLay.out_feature_class = "In_Memory\Test";// or  "Myworkspace\Test"
            gp.Execute(copyFeatLay, null);


Were you able to figure out how this was done? I'm attempting to do something similar.
0 Kudos