How do you open an IN_MEMORY featureclass? The code below is not working:

            IGPUtilities2 gpUtils = new GPUtilitiesClass();               
            IFeatureClass featureClass = gpUtils.OpenFeatureClassFromString(@"in_memory\MergeHT");                
            IFields2 fields = featureClass.Fields as IFields2;
            IField2 nameField = null;
            for (int fieldIndex = fields.FieldCount - 1; fieldIndex > -1; fieldIndex = fieldIndex - 1)
                nameField = fields.Field[fieldIndex] as IField2;
                if (nameField.Name != "FID" && nameField.Name != "Shape" && nameField.Name != "OBJECTID" && nameField.Name != "SUBTYPECD")

It gives below error:

Exception Error

  • Do you create the in memory feature class using a geoprocessor object? – Rich Wawrzonek Jun 23 '17 at 0:16
  • yes , the IN-Memory feature is created by a Geo-processing tool. – Akhil Kumar Jun 23 '17 at 4:19
  • It seems to me the problem is that nameField is an IField2 object and not an IField object, cast to IField like featureClass.DeleteField((IField)nameField); or if there's no particular reason for an IField2 object then define as nameField = fields.Field[fieldIndex] as IField; – Michael Stimson Jun 26 '17 at 23:42
  • Your iteration is correct for (counter = max;counter>=min; but it's more efficient to use fieldIndex-- than fieldIndex = fieldIndex - 1. The minus minus operator, being decrement by one in place, is the opposite of the plus plus operator (fieldIndex++) being increment by one in place. The in place operators (+=, -=, /= and *=) are also more efficient than expanded calculations which can make a big difference when performing lots of calculations/iterations. – Michael Stimson Jun 26 '17 at 23:54
  • i got the problem! actually its a bug in ArcGIS , we cant delete any field from in_memory features. it works only feature class is saved in some known hard drive location. i tried to delete manually a field from in_memory feature class, Arc Map Got hanged, i tried again through the Geo processing tool, again Arc-map Got Hanged. hence the conclusion is we cant delete any field from in_memory Feature class. – Akhil Kumar Jul 1 '17 at 10:24

You do not state what the error is! Saying something is simply not working does not help, you need to describe the error message.

The following VBA works fine for me:

Public Sub test()
    Dim pgpUtil As IGPUtilities4
    Set pgpUtil = New GPUtilities
    Dim pFC As IFeatureClass
    Set pFC = pgpUtil.OpenFeatureClassFromString("IN_MEMORY\testdata")
    Debug.Print pFC.FeatureCount(Nothing)
End Sub

Here is an example method that opens an in_memory feature class from a gp object. Try following this pattern to open your result. I think the key is the GetAsText() method which retrieves the correct name.

private static IFeatureClass CopyFeaturesToInMemoryFc(IFeatureLayer inputPtFc, int factoryCode, string functionType)
            Geoprocessor gp = new Geoprocessor();
            var copyFeatures = new ESRI.ArcGIS.DataManagementTools.CopyFeatures();
            copyFeatures.in_features = inputPtFc;
            copyFeatures.out_feature_class = @"in_memory\" + functionType;
            gp.OverwriteOutput = true;
            gp.AddOutputsToMap = false; gp.SetEnvironmentValue("outputCoordinateSystem",factoryCode);
            IGeoProcessorResult2 result = (IGeoProcessorResult2)gp.Execute(copyFeatures, null);
            IGPValue gpValue = result.GetOutput(0);
            string inMemFcName = gpValue.GetAsText();
            IGPUtilities3 gpUtilities3 = new GPUtilitiesClass();
            return gpUtilities3.OpenFeatureClassFromString(inMemFcName);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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