Select to view content in your preferred language

Clip and export Geoprocessing tool problem

2570
5
07-02-2010 02:58 AM
BrianBorg
Emerging Contributor
I have used the GP Model builder to build a model that accepts 3 variables (Input Layer of type layer file, Clip Feature of tyoe feature class and Output dataset). This model clips the input layer by the clip feature and exports the result. The model works fine in ArcGIS Desktop.

In the meantime I am using arcobjects to consume my GP model from .NET and I am finding it a bit hard. I want to create the Clip feature in memory and pass it to the Model. When I pass a null the model works fine but when I pass a feature class an exception is being returned:ex = {"Error HRESULT E_FAIL has been returned from a call to a COM component."} If I omit the Clip Feature from the model, the model works fine

This is how I am creating the feature class in memory and passing it to the GP Model:

GP.AddToolbox(@"C:\Users\xxxx\AppData\Roaming\ESRI\ArcToolbox\My Toolboxes\Export.tbx");
IVariantArray parameters = new VarArrayClass();
parameters.Add("C:\\temp\\export.lyr");
parameters.Add("SHAPE, C:\\temp\\exportshape\\");

/*CREATE IN MEMORY WORKSPACE*/
                            IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.InMemoryWorkspaceFactory();
                            IWorkspaceName workspaceName = workspaceFactory.Create("", "MyWorkspace", null, 0); // Create a new InMemory geodatabase.
                            IName name = (IName)workspaceName; // Cast for IName.
                            IWorkspace inmemWor = (IWorkspace)name.Open();; // Open a reference to the access workspace through the name object.
                            IFeatureWorkspace featWork = (IFeatureWorkspace)inmemWor;

                            // Create the fields collection and fields for the feature class.
                            IFieldsEdit pFldsEdt = new FieldsClass();
                            IFieldEdit pFldEdt = new FieldClass();

                            ISpatialReferenceFactory pSpatialRefFactory = new SpatialReferenceEnvironmentClass();
                            IGeographicCoordinateSystem pGeographicCoordSys = pSpatialRefFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
                            ISpatialReference pSpaRef = pGeographicCoordSys;
                            pSpaRef.SetDomain(-180, 180, -90, 90);

                            pFldEdt = new FieldClass();
                            pFldEdt.Type_2 = esriFieldType.esriFieldTypeOID;
                            pFldEdt.Name_2 = "OBJECTID";
                            pFldEdt.AliasName_2 = "OBJECTID";
                            pFldsEdt.AddField(pFldEdt);

                            IGeometryDefEdit pGeoDef;
                            pGeoDef = new GeometryDefClass();
                            pGeoDef.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
                            pGeoDef.SpatialReference_2 = pSpaRef;
                            pGeoDef.GridCount_2 = 1;
                            pGeoDef.set_GridSize(0, 1000);
                            pGeoDef.AvgNumPoints_2 = 0;
                            pGeoDef.HasM_2 = false;
                            pGeoDef.HasZ_2 = false;

                            pFldEdt = new FieldClass();
                            pFldEdt.Name_2 = "SHAPE";
                            pFldEdt.AliasName_2 = "SHAPE";
                            pFldEdt.Type_2 = esriFieldType.esriFieldTypeGeometry;
                            pFldEdt.GeometryDef_2 = pGeoDef;
                            pFldsEdt.AddField(pFldEdt);

                            /*CREATE FEATURE CLASS*/
                            IFeatureClass pFClass = featWork.CreateFeatureClass("Clip FC", pFldsEdt, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
                           
                            /*CREATE FEATURE */
                            IFeature Ftr = pFClass.CreateFeature();
                            ESRI.ArcGIS.Geometry.IPolygon polygon = new ESRI.ArcGIS.Geometry.PolygonClass();
                            IPointCollection pointCollection;
                            pointCollection = polygon as IPointCollection;

                            object Missing = Type.Missing;

                            IPoint point = new PointClass();
                            point.PutCoords(14.291, 35.913);
                            pointCollection.AddPoint(point, ref Missing, ref Missing);

                            point.PutCoords(14.545, 35.913);
                            pointCollection.AddPoint(point, ref Missing, ref Missing);

                            point.PutCoords(14.545, 35.719);
                            pointCollection.AddPoint(point, ref Missing, ref Missing);

                            point.PutCoords(14.291, 35.719);
                            pointCollection.AddPoint(point, ref Missing, ref Missing);
                            polygon.Close();

                            Ftr.Shape = polygon;
                            Ftr.Store();
                            parameters.Add(pFClass );
                            GP.OverwriteOutput = true;
                            GP.Execute("ClipandExport", parameters, null);
0 Kudos
5 Replies
BrianBorg
Emerging Contributor
I would appreciate any help
0 Kudos
RalfGottschalk
Esri Contributor
bramu,

I think the problem you are running into is that the InMemoryWorkspaceFactory unfortunately does not work with Geoprocessing. (NIM042590) 

Use "in_memory" in the Create Feature Class tool instead to create your feature class and that should work in the clip.
0 Kudos
BrianBorg
Emerging Contributor
Can you give me an example please? I am relatively new to this. In the Create Feature Class tool I have put "in_memory" in Feature class location and set it as a parameter with datatype as workspace but same problem is happening. I think that I am missing something
0 Kudos
BrianBorg
Emerging Contributor
can someone help me on this because I am stuck!
0 Kudos
RalfGottschalk
Esri Contributor
The geoprocessor has a concept of an in memory workspace.  An example of using it can be found here:

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//00010000041n000000

Though this is the 10.0 documentation, it works with 9.3.1 too.
0 Kudos