Select to view content in your preferred language

Using ConvertFeatureClass to Delete Fields

461
2
09-10-2010 02:10 PM
SyrusMesdaghi
New Contributor
Hi all,
I'm trying to use IFeatureDataConverter2.ConvertFeatureClass to duplicate a feature class AND remove some fields at the same time. I basically want to replicate the same exact functionality of the "Feature Class to Feature Class (conversion)". The FieldMap of the GP tool allows you to delete some mappings which will result in the output feature class not having the fields corresponding to the deleted field mappings. ConvertFeatureClass function also allows you to pass in an OutputFields which I believe is meant to allow the caller to select which fields will be copied. If I pass in a clone of the IFields retrieved from the input feature class, the conversion succeeds. However, if I delete even a single field in the cloned IFields, the conversion fails with an HRESULT: "0x8004020e Cannot modify or delete an object that was added using the COM+ Admin SDK"

My other workarounds would be to 1) use the GP tool  "Feature Class to Feature Class (conversion)" and figure out how to do the not-so-documented optional mappings which I have seen a bunch of posts on. Or 2) manually do the feature class copying by creating a feature class with only fields that I want to keep and then walk through the input feature class and copy the relevant fields.

FYI: the reason I want to use this approach to duplicate a feature class is because I'm trying to do an efficient DeleteFields. We're currently spending well over 2 hours deleting a few hundred fields one at a time using the DeleteField GP tool. Each delete takes 10-50 seconds without the time required to create/init/release the GP tool itself. Doing so one at a time results in the features' data being copy/shifted up to as many times the DeleteFields is executed. The "Feature Class to Feature Class (conversion)" GP tool sovles this problem and does the same thing in ArcCatalog in less than 2 minutes. I just want to do the same programmatically.

Regards, Syrus Mesdaghi
0 Kudos
2 Replies
JamesMacKay
Deactivated User
Hi Syrus,

Rather than modifying your field set, provide a query filter that has its Subfields property set to the subset you'd like to keep.

There's a bit more information here:
http://resources.esri.com/help/9.3/ArcGISDesktop/ArcObjects/esrigeodatabase/IFeatureDataConverter_Co...

And a lot more information here:
http://resources.esri.com/help/9.3/ArcGISDesktop/dotnet/84a1a5d7-3fa3-452e-976c-8bb57ea5de5b.htm

Cheers,
James
0 Kudos
SyrusMesdaghi
New Contributor
Thanks James, that did the trick.
-Syrus
0 Kudos