Using Geoprocessor clip with InMemoryWorkspaceFactory

582
8
08-04-2011 05:46 AM
CarlosPiccirillo
New Contributor III
Hi everyone,

I am trying to use InMemoryWorkspaceFactory with the Geoprocessor in an attempt to improve a slow part of program.

The code below runs fine if I use a file geodatabase so I know the logic is okay but as soon as I switch to trying to use an InMemoryWorkspaceFactory, the clip command produces no output and I don't get an error either.

The second method is what I am using to list all layers in the workspace and it only list the in and clip layers, not the output.

I've been trying stuff for two full days now and am out of ideas on what to try next.

Thanks,
Carlos


public static bool DetermineOverlapArea3(IFeatureLayer pAppLayer, IFeatureLayer pEnsLayer,
      IFeature pAppFeature, IFeature pEnsFeature)
{
    try
    {
 IQueryFilter queryFilter = new QueryFilterClass();
 IDataset pDataset1 = null;
 IDataset pDataset2 = null;
 IFeatureSelection pFeatureSelection1 = null;
 IFeatureSelection pFeatureSelection2 = null;
 IFeatureClassName pInFeatureClassName1 = new FeatureClassNameClass();
 IFeatureClassName pInFeatureClassName2 = new FeatureClassNameClass();
 IDatasetName pInDatasetName1 = null;
 IDatasetName pInDatasetName2 = null;
 IFeatureClassName pOutFeatureClassName1 = new FeatureClassNameClass();
 IFeatureClassName pOutFeatureClassName2 = new FeatureClassNameClass();
 IDatasetName pOutDatasetName1 = null;
 IDatasetName pOutDatasetName2 = null;
 IWorkspaceFactory pWorkspaceFactory = new InMemoryWorkspaceFactoryClass();
 IFeatureLayer pFeatureLayer = new FeatureLayerClass();
 IFeatureWorkspace pFeatureWorkspace = null;
 IWorkspaceName pWorkspaceName = new WorkspaceNameClass();
 IFeatureClass pFeatureClass = null;

 pWorkspaceName = pWorkspaceFactory.Create("", "TEMP", null, 0);
 IName pName = pWorkspaceName as IName;
 IWorkspace pWorkspace = pName.Open() as IWorkspace;
 pFeatureWorkspace = pWorkspace as IFeatureWorkspace;

 if (pAppLayer != null)
 {
     pFeatureSelection1 = pAppLayer as IFeatureSelection;
     queryFilter.WhereClause = "APP_NO = '" + m_AppNo + "'";
     pDataset1 = pAppLayer.FeatureClass as IDataset;
     pFeatureSelection1.SelectFeatures(queryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
     pInFeatureClassName1 = pDataset1.FullName as IFeatureClassName;
     pInDatasetName1 = pInFeatureClassName1 as IDatasetName;
     pOutDatasetName1 = pOutFeatureClassName1 as IDatasetName;
     pOutDatasetName1.Name = "APPTEMP";
     pOutDatasetName1.WorkspaceName = pWorkspaceName;
     pOutFeatureClassName1.FeatureType = esriFeatureType.esriFTSimple;
     pOutFeatureClassName1.ShapeType = esriGeometryType.esriGeometryAny;
     pOutFeatureClassName1.ShapeFieldName = "Shape";
     IExportOperation pExportOperation = new ExportOperationClass();
     pExportOperation.ExportFeatureClass(pInDatasetName1, null, pFeatureSelection1.SelectionSet, null, pOutFeatureClassName1, 0);
 }

 if (pEnsLayer != null)
 {
     pFeatureSelection2 = pEnsLayer as IFeatureSelection;
     queryFilter.WhereClause = "BASIN_NAME = '" + m_Label + "'";
     pDataset2 = pEnsLayer.FeatureClass as IDataset;
     pFeatureSelection2.SelectFeatures(queryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
     pInFeatureClassName2 = pDataset2.FullName as IFeatureClassName;
     pInDatasetName2 = pInFeatureClassName2 as IDatasetName;
     pOutDatasetName2 = pOutFeatureClassName2 as IDatasetName;
     pOutDatasetName2.Name = "ENSTEMP";
     pOutDatasetName2.WorkspaceName = pWorkspaceName;
     pOutFeatureClassName2.FeatureType = esriFeatureType.esriFTSimple;
     pOutFeatureClassName2.ShapeType = esriGeometryType.esriGeometryAny;
     pOutFeatureClassName2.ShapeFieldName = "Shape";
     IExportOperation pExportOperation = new ExportOperationClass();
     pExportOperation.ExportFeatureClass(pInDatasetName2, null, pFeatureSelection2.SelectionSet, null, pOutFeatureClassName2, 0);
 }

 ESRI.ArcGIS.AnalysisTools.Clip pClip = new ESRI.ArcGIS.AnalysisTools.Clip();

 pClip.in_features = pWorkspace + "APPTEMP";
 pClip.clip_features = pWorkspace + "ENSTEMP";
 pClip.out_feature_class = pWorkspace + "APP_ENS_OVERLAP";

 ITrackCancel pTrackCancel = new CancelTrackerClass();
 pTrackCancel.CancelOnClick = false;
 pTrackCancel.CancelOnKeyPress = true;

 ESRI.ArcGIS.Geoprocessor.Geoprocessor pGeoprocessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
 pGeoprocessor.Execute(pClip, pTrackCancel);

 //Get the resulting intersection polygon.
 pFeatureClass = pFeatureWorkspace.OpenFeatureClass("APP_ENS_OVERLAP");
 pFeatureLayer.FeatureClass = pFeatureClass;
 IFeatureSelection pFeatureSelection = pFeatureLayer as IFeatureSelection;
 pFeatureSelection.SelectFeatures(null, esriSelectionResultEnum.esriSelectionResultNew, false);
 ISelectionSet pSelectionSet = pFeatureSelection.SelectionSet as ISelectionSet;
 ICursor pCursor;
 pSelectionSet.Search(null, true, out pCursor);
 IFeatureCursor pFeatureCursor = pCursor as IFeatureCursor;
 IFeature pIntersectFeature = pFeatureCursor.NextFeature();

 IArea pIntersectArea = pIntersectFeature.Shape as IArea;
 IArea pAppArea = pAppFeature.Shape as IArea;
 IArea pEnsArea = pEnsFeature.Shape as IArea;

 int appOverlap = Convert.ToInt32((pIntersectArea.Area / pAppArea.Area) * 100);
 int ensOverlap = Convert.ToInt32((pIntersectArea.Area / pEnsArea.Area) * 100);

 if (appOverlap > 5 || ensOverlap > 5)
     return true;
 else
     return false;

    }
    catch (Exception ex)
    {
 LogError(ex.StackTrace, ex.Message, "DetermineOverlapArea", null);
 return false;
    }
}


IEnumDataset pEnumDataset = pWorkspace.get_Datasets(esriDatasetType.esriDTFeatureClass) as IEnumDataset;
IDataset pDataset = pEnumDataset.Next();

while (pDataset != null)
{
    MessageBox.Show(pDataset.Name);
    pDataset = pEnumDataset.Next();
}
0 Kudos
8 Replies
KenBuja
MVP Honored Contributor
I haven't tried using the IMemoryWorkSpaceFactory, but I have been able to use a geoprocessor process parameter like

"in_memory\output"
0 Kudos
CarlosPiccirillo
New Contributor III
Ken,

Thanks for the reply. I saw something about that in the documentation but could not get it to work either. Do you have some sample code in any language I can look at that uses "in_memory"?

Thanks for your time.
Carlos

I haven't tried using the IMemoryWorkSpaceFactory, but I have been able to use a geoprocessor process parameter like

"in_memory\output"
0 Kudos
KenBuja
MVP Honored Contributor
My code makes calls to functions containing the geoprocessing tools. I've declared the geoprocessor Global.GP in another module and initialized it elsewhere


pDissolvedFClass = DissolveDataset(pResourceFClass, DissolveFieldName, StatisticsFieldName & " " & Stat, "in_memory\DissolvedResource")

    Friend Function DissolveDataset(ByVal InputName As Object, ByVal DissolveField As String, ByVal StatsFields As String, ByVal OutputName As String) As ESRI.ArcGIS.Geodatabase.IFeatureClass

        Dim DissolveDS As New ESRI.ArcGIS.DataManagementTools.Dissolve
        Dim Result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2

        Try
            Using releaser As New ESRI.ArcGIS.ADF.ComReleaser
                releaser.ManageLifetime(DissolveDS)
                DissolveDS.in_features = InputName
                DissolveDS.dissolve_field = DissolveField
                DissolveDS.statistics_fields = StatsFields
                DissolveDS.out_feature_class = OutputName

                Result = RunTool(DissolveDS, Nothing)
                If Result Is Nothing Then
                    System.Windows.Forms.MessageBox.Show("Could not dissolve dataset")
                    Return Nothing
                End If

                Return ReturnObjectfromResult(Result, "Feature Class")
            End Using

        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.ToString, "Dissolve error")
            Return Nothing
        End Try

    End Function

    Friend Function ReturnObjectfromResult(ByVal result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2, ByVal Type As String) As Object

        Dim GPVal As ESRI.ArcGIS.Geodatabase.IGPValue
        Dim InMemFC As String
        Dim GPUtil As ESRI.ArcGIS.Geoprocessing.IGPUtilities3 = New ESRI.ArcGIS.Geoprocessing.GPUtilities

        Try
            GPVal = result.GetOutput(0)
            InMemFC = GPVal.GetAsText()

            Select Case Type
                Case "Feature Class"
                    Return GPUtil.OpenFeatureClassFromString(InMemFC)
                Case "Table"
                    Return GPUtil.OpenTableFromString(InMemFC)
            End Select

        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.ToString, "Return FeatureClass error")
            Return Nothing
        End Try

    End Function

    Private Sub ReturnMessages(ByVal pResult As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2, ByVal Title As String)

        Dim ErrorMessage As String

        If pResult.MessageCount > 0 Then
            For Count As Integer = 0 To pResult.MessageCount - 1
                ErrorMessage += pResult.GetMessage(Count)
            Next
        End If

        System.Windows.Forms.MessageBox.Show(ErrorMessage, Title)

    End Sub

    Friend Function RunTool(ByVal Process As ESRI.ArcGIS.Geoprocessor.IGPProcess, ByVal TC As ESRI.ArcGIS.esriSystem.ITrackCancel2) As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2

        Dim Result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2

        Try
            Result = CType(Globals.GP.Execute(Process, Nothing), ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2)
            If Result.Status <> ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded Then ReturnMessages(Result, "Geoprocessing Error")
            Globals.GP.ClearMessages()
        Catch ex As Exception
            ReturnMessages(Result, "Fail")
            System.Windows.Forms.MessageBox.Show(ex.ToString, "Run Geoprocessor")
        End Try

        Return Result

    End Function


0 Kudos
CarlosPiccirillo
New Contributor III
Ken,

Thanks for sample code. Looking at your code, I got mine to work. Unfortunately, I am still having one issue. The methos below gets called from a loop. The first time the method gets called everything works fine. The second time however, the line below retuns null.

GeoProcessorResult result = pGeoprocessor.Execute(pClip, null) as GeoProcessorResult;

Any idea why this is happening?

Thanks,
Carlos


        public static bool DetermineOverlapArea3(IFeatureLayer pAppLayer, IFeatureLayer pEnsLayer,
                                                 IFeature pAppFeature, IFeature pEnsFeature)
        {
            try
            {
                IQueryFilter queryFilter = new QueryFilterClass();
                IDataset pDataset1 = null;
                IDataset pDataset2 = null;
                IFeatureSelection pFeatureSelection1 = null;
                IFeatureSelection pFeatureSelection2 = null;
                IFeatureClassName pInFeatureClassName1 = new FeatureClassNameClass();
                IFeatureClassName pInFeatureClassName2 = new FeatureClassNameClass();
                IDatasetName pInDatasetName1 = null;
                IDatasetName pInDatasetName2 = null;
                IFeatureClassName pOutFeatureClassName1 = new FeatureClassNameClass();
                IFeatureClassName pOutFeatureClassName2 = new FeatureClassNameClass();
                IDatasetName pOutDatasetName1 = null;
                IDatasetName pOutDatasetName2 = null;
                IWorkspaceFactory pWorkspaceFactory = new InMemoryWorkspaceFactoryClass();
                IFeatureLayer pFeatureLayer = new FeatureLayerClass();
                IFeatureWorkspace pFeatureWorkspace = null;
                IWorkspaceName pWorkspaceName = new WorkspaceNameClass();

                pWorkspaceName = pWorkspaceFactory.Create("", "TEMP", null, 0);
                IName pName = pWorkspaceName as IName;
                IWorkspace pWorkspace = pName.Open() as IWorkspace;
                pFeatureWorkspace = pWorkspace as IFeatureWorkspace;

                if (pAppLayer != null)
                {
                    pFeatureSelection1 = pAppLayer as IFeatureSelection;
                    queryFilter.WhereClause = "APP_NO = '" + m_AppNo + "'";
                    pDataset1 = pAppLayer.FeatureClass as IDataset;
                    pFeatureSelection1.SelectFeatures(queryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
                    pInFeatureClassName1 = pDataset1.FullName as IFeatureClassName;
                    pInDatasetName1 = pInFeatureClassName1 as IDatasetName;
                    pOutDatasetName1 = pOutFeatureClassName1 as IDatasetName;
                    pOutDatasetName1.Name = "APPTEMP";
                    pOutDatasetName1.WorkspaceName = pWorkspaceName;
                    pOutFeatureClassName1.FeatureType = esriFeatureType.esriFTSimple;
                    pOutFeatureClassName1.ShapeType = esriGeometryType.esriGeometryAny;
                    pOutFeatureClassName1.ShapeFieldName = "Shape";
                    IExportOperation pExportOperation = new ExportOperationClass();
                    pExportOperation.ExportFeatureClass(pInDatasetName1, null, pFeatureSelection1.SelectionSet, null, pOutFeatureClassName1, 0);
                }

                if (pEnsLayer != null)
                {
                    pFeatureSelection2 = pEnsLayer as IFeatureSelection;
                    queryFilter.WhereClause = "BASIN_NAME = '" + m_Label + "'";
                    pDataset2 = pEnsLayer.FeatureClass as IDataset;
                    pFeatureSelection2.SelectFeatures(queryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
                    pInFeatureClassName2 = pDataset2.FullName as IFeatureClassName;
                    pInDatasetName2 = pInFeatureClassName2 as IDatasetName;
                    pOutDatasetName2 = pOutFeatureClassName2 as IDatasetName;
                    pOutDatasetName2.Name = "ENSTEMP";
                    pOutDatasetName2.WorkspaceName = pWorkspaceName;
                    pOutFeatureClassName2.FeatureType = esriFeatureType.esriFTSimple;
                    pOutFeatureClassName2.ShapeType = esriGeometryType.esriGeometryAny;
                    pOutFeatureClassName2.ShapeFieldName = "Shape";
                    IExportOperation pExportOperation = new ExportOperationClass();
                    pExportOperation.ExportFeatureClass(pInDatasetName2, null, pFeatureSelection2.SelectionSet, null, pOutFeatureClassName2, 0);
                }

                IFeatureClass pAppFeatureClass = pFeatureWorkspace.OpenFeatureClass("APPTEMP");
                IFeatureClass pEnsFeatureClass = pFeatureWorkspace.OpenFeatureClass("ENSTEMP");

                //Execute clip.
                Clip pClip = new Clip();
                pClip.in_features = pAppFeatureClass;
                pClip.clip_features = pEnsFeatureClass;
                pClip.out_feature_class = "in_memory\\APP_ENS_OVERLAP";

                Geoprocessor pGeoprocessor = new Geoprocessor();
                GeoProcessorResult result = pGeoprocessor.Execute(pClip, null) as GeoProcessorResult;

                IGPValue pGPValue = result.GetOutput(0);
                string InMemoryFeatureClass = string.Empty;
                InMemoryFeatureClass = pGPValue.GetAsText();

                //Get resulting feature class.
                IGPUtilities pGPUtilities = new GPUtilities();
                IFeatureClass pOverlapEnsFeatureClass = pGPUtilities.OpenFeatureClassFromString(InMemoryFeatureClass);

                //Get the resulting intersection polygon.
                pFeatureLayer.FeatureClass = pOverlapEnsFeatureClass;
                IFeatureSelection pFeatureSelection = pFeatureLayer as IFeatureSelection;
                pFeatureSelection.SelectFeatures(null, esriSelectionResultEnum.esriSelectionResultNew, false);
                ISelectionSet pSelectionSet = pFeatureSelection.SelectionSet as ISelectionSet;
                ICursor pCursor;
                pSelectionSet.Search(null, true, out pCursor);
                IFeatureCursor pFeatureCursor = pCursor as IFeatureCursor;
                IFeature pIntersectFeature = pFeatureCursor.NextFeature();

                IArea pIntersectArea = pIntersectFeature.Shape as IArea;
                IArea pAppArea = pAppFeature.Shape as IArea;
                IArea pEnsArea = pEnsFeature.Shape as IArea;

                int appOverlap = Convert.ToInt32((pIntersectArea.Area / pAppArea.Area) * 100);
                int ensOverlap = Convert.ToInt32((pIntersectArea.Area / pEnsArea.Area) * 100);

                if (appOverlap > 5 || ensOverlap > 5)
                    return true;
                else
                    return false;

            }
            catch (Exception ex)
            {
                LogError(ex.StackTrace, ex.Message, "DetermineOverlapArea", null);
                return false;
            }
        }
0 Kudos
KenBuja
MVP Honored Contributor
Hi Carlos,

I'm glad to hear you're making progress. Since you don't have the code to show why the Clip process didn't run, examine the Results information in ArcMap to find out what happened. Could it be that it's not overwriting "in_memory\APP_ENS_OVERLAP"? Have you set the Geoprocessor to overwrite outputs, either through the Geoprocessing Options dialog or by setting
pGeoprocessor.OverwriteOutput = "true"
0 Kudos
CarlosPiccirillo
New Contributor III
Hi Ken,

Thanks for the reply. You are right on, I did not have pGeoprocessor.OverwriteOutput = "true" set. I added that line to the code below and now it gets further along but after a couple hundred records or so, it starts failing every time the method below gets called (inside loop of another method) and the error is "Object reference not set to an instance of an object." I know what's happening, but no clue as to why. The problem occurs because line:

ISelectionSet pSelectionSet = pFeatureSelection.SelectionSet as ISelectionSet;

suddenly stops returning a selection set. This line should always return something because the method only gets called when a spatial query determines that two polygons from different layers intersect each other so I don't understand why suddenly it stops working. Sounds like a memory leak or object not being cleared correctly but I've tried adding lines like, if (pWorkspaceFactory != null) { Marshal.ReleaseComObject(pWorkspaceFactory); pWorkspaceFactory = null; } for every object to clear it but it doesn't help. I can post the method calling this method if you want. Just have to do it in another message because it's too large to fit in this one.

Thanks again for your help and time, I appreciate it!!!


        public static bool DetermineOverlapArea3(IFeatureLayer pAppLayer, IFeatureLayer pEnsLayer,
                                                 IFeature pAppFeature, IFeature pEnsFeature)
        {
            try
            {
                IQueryFilter queryFilter = new QueryFilterClass();
                IDataset pDataset1 = null;
                IDataset pDataset2 = null;
                IFeatureSelection pFeatureSelection1 = null;
                IFeatureSelection pFeatureSelection2 = null;
                IFeatureClassName pInFeatureClassName1 = new FeatureClassNameClass();
                IFeatureClassName pInFeatureClassName2 = new FeatureClassNameClass();
                IDatasetName pInDatasetName1 = null;
                IDatasetName pInDatasetName2 = null;
                IFeatureClassName pOutFeatureClassName1 = new FeatureClassNameClass();
                IFeatureClassName pOutFeatureClassName2 = new FeatureClassNameClass();
                IDatasetName pOutDatasetName1 = null;
                IDatasetName pOutDatasetName2 = null;
                IWorkspaceFactory pWorkspaceFactory = new InMemoryWorkspaceFactoryClass();
                IFeatureLayer pFeatureLayer = new FeatureLayerClass();
                IFeatureWorkspace pFeatureWorkspace = null;
                IWorkspaceName pWorkspaceName = new WorkspaceNameClass();

                pWorkspaceName = pWorkspaceFactory.Create("", "TEMP", null, 0);
                IName pName = pWorkspaceName as IName;
                IWorkspace pWorkspace = pName.Open() as IWorkspace;
                pFeatureWorkspace = pWorkspace as IFeatureWorkspace;

                if (pAppLayer != null)
                {
                    pFeatureSelection1 = pAppLayer as IFeatureSelection;
                    queryFilter.WhereClause = "APP_NO = '" + m_AppNo + "'";
                    pDataset1 = pAppLayer.FeatureClass as IDataset;
                    pFeatureSelection1.SelectFeatures(queryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
                    pInFeatureClassName1 = pDataset1.FullName as IFeatureClassName;
                    pInDatasetName1 = pInFeatureClassName1 as IDatasetName;
                    pOutDatasetName1 = pOutFeatureClassName1 as IDatasetName;
                    pOutDatasetName1.Name = "APPTEMP";
                    pOutDatasetName1.WorkspaceName = pWorkspaceName;
                    pOutFeatureClassName1.FeatureType = esriFeatureType.esriFTSimple;
                    pOutFeatureClassName1.ShapeType = esriGeometryType.esriGeometryAny;
                    pOutFeatureClassName1.ShapeFieldName = "Shape";
                    IExportOperation pExportOperation = new ExportOperationClass();
                    pExportOperation.ExportFeatureClass(pInDatasetName1, null, pFeatureSelection1.SelectionSet, null, pOutFeatureClassName1, 0);
                }

                if (pEnsLayer != null)
                {
                    pFeatureSelection2 = pEnsLayer as IFeatureSelection;
                    queryFilter.WhereClause = "BASIN_NAME = '" + m_Label + "'";
                    pDataset2 = pEnsLayer.FeatureClass as IDataset;
                    pFeatureSelection2.SelectFeatures(queryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
                    pInFeatureClassName2 = pDataset2.FullName as IFeatureClassName;
                    pInDatasetName2 = pInFeatureClassName2 as IDatasetName;
                    pOutDatasetName2 = pOutFeatureClassName2 as IDatasetName;
                    pOutDatasetName2.Name = "ENSTEMP";
                    pOutDatasetName2.WorkspaceName = pWorkspaceName;
                    pOutFeatureClassName2.FeatureType = esriFeatureType.esriFTSimple;
                    pOutFeatureClassName2.ShapeType = esriGeometryType.esriGeometryAny;
                    pOutFeatureClassName2.ShapeFieldName = "Shape";
                    IExportOperation pExportOperation = new ExportOperationClass();
                    pExportOperation.ExportFeatureClass(pInDatasetName2, null, pFeatureSelection2.SelectionSet, null, pOutFeatureClassName2, 0);
                }

                IFeatureClass pAppFeatureClass = pFeatureWorkspace.OpenFeatureClass("APPTEMP");
                IFeatureClass pEnsFeatureClass = pFeatureWorkspace.OpenFeatureClass("ENSTEMP");

                //Execute clip.
                Clip pClip = new Clip();
                pClip.in_features = pAppFeatureClass;
                pClip.clip_features = pEnsFeatureClass;
                pClip.out_feature_class = "in_memory\\APP_ENS_OVERLAP";

                Geoprocessor pGeoprocessor = new Geoprocessor();
                pGeoprocessor.AddOutputsToMap = false;
                pGeoprocessor.OverwriteOutput = true;
                IGeoProcessorResult result = pGeoprocessor.Execute(pClip, null) as IGeoProcessorResult;

                //Get the resulting intersection polygon.
                IFeatureClass pOverlapEnsFeatureClass = pGeoprocessor.Open("in_memory\\APP_ENS_OVERLAP") as IFeatureClass;
                pFeatureLayer.FeatureClass = pOverlapEnsFeatureClass;
                IFeatureSelection pFeatureSelection = pFeatureLayer as IFeatureSelection;
                pFeatureSelection.SelectFeatures(null, esriSelectionResultEnum.esriSelectionResultNew, false);
                ISelectionSet pSelectionSet = pFeatureSelection.SelectionSet as ISelectionSet;   //PROBLEM HERE
                ICursor pCursor;
                pSelectionSet.Search(null, true, out pCursor);
                IFeatureCursor pFeatureCursor = pCursor as IFeatureCursor;
                IFeature pIntersectFeature = pFeatureCursor.NextFeature();

                IArea pIntersectArea = pIntersectFeature.Shape as IArea;
                IArea pAppArea = pAppFeature.Shape as IArea;
                IArea pEnsArea = pEnsFeature.Shape as IArea;

                int appOverlap = Convert.ToInt32((pIntersectArea.Area / pAppArea.Area) * 100);
                int ensOverlap = Convert.ToInt32((pIntersectArea.Area / pEnsArea.Area) * 100);

                if (appOverlap > 5 || ensOverlap > 5)
                    return true;
                else
                    return false;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                //LogError(ex.StackTrace, ex.Message, "DetermineOverlapArea", null);
                return false;
            }
        }
Hi Carlos,

I'm glad to hear you're making progress. Since you don't have the code to show why the Clip process didn't run, examine the Results information in ArcMap to find out what happened. Could it be that it's not overwriting "in_memory\APP_ENS_OVERLAP"? Have you set the Geoprocessor to overwrite outputs, either through the Geoprocessing Options dialog or by setting
pGeoprocessor.OverwriteOutput = "true"
0 Kudos
DuncanHornby
MVP Frequent Contributor
May be a bit late in this discussion but I was playing around with creating in_memory workspaces in VBA (ArcGIS 9.3). Here is my code.

Public Sub InMemoryExample()
' Description: Sample code showing how an in memory table can be created

' Create Workspacefactory
Dim pWorkSpaceFactory As IWorkspaceFactory2
Set pWorkSpaceFactory = New InMemoryWorkspaceFactory

' Create Workspace
Dim pWorkspaceName As IWorkspaceName2
Set pWorkspaceName = pWorkSpaceFactory.Create("", "MyInMemoryWorkspace", Nothing, 0)

' Get a handle on Name
Dim pName As IName
Set pName = pWorkspaceName

' Get a handle on FeatureWorkspace
Dim pFeatureWorkspace As IFeatureWorkspace
Set pFeatureWorkspace = pName.Open

' Now create a fields object and add some fields to it

' Create Fields object and set the number of fields
Dim pFields As IFields
Set pFields = New Fields
Dim pFieldsEdit As IFieldsEdit
Set pFieldsEdit = pFields
pFieldsEdit.FieldCount = 2

' Create objectID field
Dim pField As IField
Set pField = New Field
Dim pFieldEdit As IFieldEdit
Set pFieldEdit = pField
With pFieldEdit
.Name = "OBJECTID"
.Type = esriFieldTypeOID
End With
Set pFieldsEdit.Field(0) = pField

' Create Type field
Set pField = New Field
Set pFieldEdit = pField
With pFieldEdit
.Editable = True
.Name = "VegType"
.Type = esriFieldTypeString
.Length = 4
.AliasName = "Vegetation Type Code"
End With
Set pFieldsEdit.Field(1) = pField

' Create Table
Dim pTable As ITable
Set pTable = pFeatureWorkspace.CreateTable("MyInMemTable", pFields, Nothing, Nothing, "")

' Create a sample row and add data
Dim pRow As IRow
Set pRow = pTable.CreateRow
With pRow
.Value(1) = "WOOD"
.Store
End With

' Add table to map document
Dim pMXD As IMxDocument
Set pMXD = ThisDocument
Dim pMap As IMap
Set pMap = pMXD.FocusMap
Dim pStandAloneTableCollection As IStandaloneTableCollection
Set pStandAloneTableCollection = pMap
Dim pStandAloneTable As IStandaloneTable
Set pStandAloneTable = New StandaloneTable
Set pStandAloneTable.Table = pTable
pStandAloneTableCollection.AddStandaloneTable pStandAloneTable
pMXD.UpdateContents
End Sub


Duncan
0 Kudos
CarlosPiccirillo
New Contributor III
Thanks Duncan, I appreciate it. 🙂
0 Kudos