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);
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);
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.