Geoprocessing Using ArcObjects - Feature Class to Feature Class...

3898
2
06-11-2010 12:02 AM
RobertKoch
New Contributor
Hi,

I am writing an extension for ArcMap using ArcObjects and VB.Net. As part of this extension I would like to access the �??Feature Class to Feature Class�?? geoprocessing tool using ArcObjects.

Using the example in http://edndoc.esri.com/arcobjects/9.2/CPP_VB6_VBA_VCPP_Doc/COM/gp/Using%20Geoprocessing%20Tools%20in... as a guide, I have managed to come up with the code below. This code however causes ArcMap to crash at the GP.Execute line.

I have read the help file for this tool which suggests that the �??in_features�?? and �??out_path�?? need to be of types  IFeatureLayer and IWorkspace respectively. Unfortunately I don�??t know how to set the properties correctly for this interface. http://resources.esri.com/help/9.3/arcgisdesktop/com/gp_toolref/conversion_tools/feature_class_to_fe...

Also am I correct in setting the optional parameters to Nothing? Or should I not declare/set these at all?

To start with I�??m just looking to go from SHP to SHP, but ultimately the goal will be SHP to SDE.

Can anyone help me out?

Thanks. Rob.

  Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim GP As IGeoProcessor = New GeoProcessor
        'Dim gp As ESRI.ArcGIS.Geoprocessor.Geoprocessor = New ESRI.ArcGIS.Geoprocessor.Geoprocessor

        'Declare variables for input
        Dim in_features As String
        Dim out_path As String
        Dim out_name As String
        Dim where_clause As String
        Dim field_mapping As String
        Dim config_keyword As String

        'Define the input/output parameter
        in_features = "C:\temp\roads.shp"
        out_path = "C:\temp"
        out_name = "aaa.shp"
        where_clause = Nothing
        field_mapping = Nothing
        config_keyword = Nothing

        'Declare and set a variant array
        Dim parameters As IVariantArray
        parameters = New VarArray

        'Populate the variant array with
        parameters.Add(in_features)
        parameters.Add(out_path)
        parameters.Add(out_name)
        parameters.Add(where_clause)
        parameters.Add(field_mapping)
        parameters.Add(config_keyword)

        'GP.FeatureclassToFeatureclass_conversion(in_features, out_path, out_name)
        GP.Execute("FeatureclassToFeatureclass_conversion", parameters, Nothing)

    End Sub
0 Kudos
2 Replies
StefanOffermann
Occasional Contributor II
Hi,

instead of using an IVariantArray, you can simply use the following code:

in_features = "C:\temp\roads.shp"
out_path = "C:\temp"
out_name = "aaa.shp"
GP.FeatureclassToFeatureclass_conversion(in_features, out_path, out_name)


This would be my normal approach using C#, there should be no big difference with VB.NET

Best regards, Stefan
0 Kudos
RobertKoch
New Contributor
Hi Stefan,

Thanks for the reply. Your code is certainly a lot simpler than the example I was working from. Having said this, ArcMap is still crashing each time it gets to the final line (see attachment for error).

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim GP As IGeoProcessor = New GeoProcessor

        'Declare variables for input
        Dim in_features As String
        Dim out_path As String
        Dim out_name As String

        in_features = "C:\temp\TR_ROADS.shp"
        out_path = "C:\temp"
        out_name = "aaa.shp"

        GP.FeatureclassToFeatureclass_conversion(in_features, out_path, out_name)

    End Sub


I also found another example which supposedly take a shape file, creates a Personal GDB and writes the shape file to a feature class within:

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim GP As Object = CreateObject("esriGeoprocessing.GpDispatch.1")
        Dim filepath As String = "c:\temp\"
        GP.workspace = filepath
        GP.CreatePersonalGDB_management(filepath, "aaa.mdb")
        GP.FeatureclassToFeatureclass_conversion("TR_ROADS.shp", "aaa.mdb", "roads")

    End Sub


This code created the the MDB OK, but again crashes on the final line (an MDA error is also displayed via visual studio).

Can anyone help me get to the bottom of this?

Regards. Rob.
0 Kudos