Select to view content in your preferred language

Selection set to Feature Class

5722
11
04-18-2010 06:12 PM
JeffGiesler
Occasional Contributor
Hello  Everyone,
I have a quick question.  I am trying to get a set of selected values from a map layer and get them into a feature class.  I have the selected Item in IFeatureSeletion.SelectionSet and I would like to get it into IfeatureClass.  Can this be done simply thriough a cast or do I need to export it.  I hope someone can help.
Cheers,
Jeff
0 Kudos
11 Replies
DerekLoi
New Contributor III
I suspect it is because you are using the IFeatureDataConverter2.

I just did a quick test with IExportOperation instead, in an Add-In, and it does export joined fields.



Hi Jeff,
IExportOperation does not exist in ArcEngine.  Thats why I could only use the IFeatureDataConverter interface.  Any other ideas?
Derek

edit:
I debugged my code and it looks like the:
fieldChecker.Validate(inputFeatureClass.Fields, out enumFieldError, out shapefileFields);

is removing the joined fields from the IDisplayTable before it does the conversion.
I'll have to research more and will report back if i find anything...
0 Kudos
DerekLoi
New Contributor III
ok i figured it out... Jeff - Thanks for your help.
looks like my problem was with the casting of the input featureclass/displaytable.  It has nothing to do with the IFieldChecker interface.
so if anyone is interested here's the corrected code to export selected features of a sde featureclass with joined fields to a shapefile

/// <summary>
/// Exports the selected features of a layer in the Map Control to a Shapefile
/// </summary>
/// <param name="pLayer">mapcontrol layer</param>
/// <param name="inputPath">input IDisplayTable</param>
/// <param name="outputPath">output shapefile full path</param>
public void ExportJoinLyrToShapefile(IDisplayTable pInDispTable, string inputName, string outputPath)
{
 IFeatureClass inputFeatureClass = (IFeatureClass)pInDispTable.DisplayTable;
 IDataset inputDataset = (IDataset)inputFeatureClass;
 IDatasetName inputDatasetName = (IDatasetName)inputDataset.FullName;

 // Get the layer's selection set (the selected/highlighted features of the layer in the mapcontrol)
 IFeatureSelection featureSelection = (IFeatureSelection)pInDispTable;
 ISelectionSet selectionSet = featureSelection.SelectionSet;

 // Create a feature class name for the output shapefile and open the output's workspace
 IWorkspaceFactory shpWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
 IWorkspace shpWorkspace = shpWorkspaceFactory.OpenFromFile(outputPath, 0);
 IDataset shpWorkspaceDataset = (IDataset)shpWorkspace;
 IWorkspaceName workspaceName = (IWorkspaceName)shpWorkspaceDataset.FullName;
 IFeatureClassName shpFeatureClassName = new FeatureClassNameClass();
 IDatasetName shpDatasetName = (IDatasetName)shpFeatureClassName;
 shpDatasetName.WorkspaceName = workspaceName;
 shpDatasetName.Name = "Shapefile_Name";

 // Use the IFieldChecker interface to make sure all of the field names are valid for the output shapefile.
 IFieldChecker fieldChecker = new FieldCheckerClass();
 IFields shapefileFields = null;
 IEnumFieldError enumFieldError = null;
 fieldChecker.InputWorkspace = inputDataset.Workspace;
 fieldChecker.ValidateWorkspace = shpWorkspace;
 fieldChecker.Validate(inputFeatureClass.Fields, out enumFieldError, out shapefileFields);

 // We also need to retrieve the GeometryDef from the input feature class.
 int shapeFieldPosition = inputFeatureClass.FindField(inputFeatureClass.ShapeFieldName);
 IFields inputFields = inputFeatureClass.Fields;
 IField shapeField = inputFields.get_Field(shapeFieldPosition);
 IGeometryDef geometryDef = shapeField.GeometryDef;

 // Now we create a feature data converter to "Export" the selected features to a shapefile
 IFeatureDataConverter2 featureDataConverter2 = new FeatureDataConverterClass();
 IEnumInvalidObject enumInvalidObject = featureDataConverter2.ConvertFeatureClass(inputDatasetName, null, selectionSet, 
  null, shpFeatureClassName, geometryDef, shapefileFields, "", 1000, 0);
}
0 Kudos