cpicciri

Using Geoprocessor clip with InMemoryWorkspaceFactory

Discussion created by cpicciri on Aug 4, 2011
Latest reply on Aug 10, 2011 by cpicciri
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();
}

Outcomes