Exporting to a feature dataset within a file geodatabase

2049
4
02-17-2011 08:40 AM
ShaunConway
Occasional Contributor II
Hello,

I have the attached code which accepts a feature class as a parameter and saves a copy of this feature class as a new feature class in a file geodatabase. My problem is that I would like to save the exported feature class to a specific feature dataset within the target file geodatabase.

Can someone please share how this is accomplished?

thanks in advance 🙂

Dim pInFeatureClassName As IFeatureClassName
Dim pDataSet As IDataset
Dim pInDsName As IDatasetName
Dim pFSel As IFeatureSelection
Dim pSelSet As ISelectionSet
Dim pFeatureClassName As IFeatureClassName
Dim pOutDatasetName As IDatasetName
Dim pWorkspaceName As IWorkspaceName
Dim pExportOp As IExportOperation
Dim pFeatureLayer As IFeatureLayer


'Get the Featureclassname from the featureclass
Set pDataSet = pFC
Set pInFeatureClassName = pDataSet.FullName

'Define the output featureclass
'give it the name of the input feature class + exp
Set pFeatureClassName = New FeatureClassName
Set pOutDatasetName = pFeatureClassName
pOutDatasetName.Name = "scenario_" & frmSaveScenario.tbScenarioName & "_" & sType
 
Set pWorkspaceName = New WorkspaceName
pWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesGDB.FileGDBWorkspaceFactory"
pWorkspaceName.PathName = "\\tempest\shared\GIS\Community Development\Redistricting\Census\2000_Census.gdb"


Set pOutDatasetName.WorkspaceName = pWorkspaceName

'Give the output shapefile the same props as the input dataset
pFeatureClassName.FeatureType = pFC.FeatureType
pFeatureClassName.ShapeType = pFC.ShapeType
pFeatureClassName.ShapeFieldName = pFC.ShapeFieldName
'pFeatureClassName.FeatureDatasetName = pFC.FeatureDataset

Set pInDsName = pInFeatureClassName

'Export selected features
Set pExportOp = New ExportOperation
pExportOp.ExportFeatureClass pInDsName, Nothing, Nothing, Nothing, pOutDatasetName, 0
0 Kudos
4 Replies
NeilClemmons
Regular Contributor III
'pFeatureClassName.FeatureDatasetName = pFC.FeatureDataset

I don't know that I've ever tried it but this line looks like a type mismatch.  A dataset name object is required, not a dataset.  You can get the dataset name object from the workspace's DatasetNames.  You might also be able to use the name object from the dataset.
0 Kudos
ShaunConway
Occasional Contributor II
Thanks for the reply Neil. I've attached my updated code (at least the updated portion of it). I keep getting a "method or data member not found" error on the line

pFeatureClassName.FeatureDatasetName = pFc.FeatureDataset.Name


It appears it doesn't like pFeatureClassName.FeatureDatasetName

but it returns no errors on

pFeatureClassName.FeatureType = pFc.FeatureType
pFeatureClassName.ShapeType = pFc.ShapeType
pFeatureClassName.ShapeFieldName = pFc.ShapeFieldName


any suggestions?
0 Kudos
NeilClemmons
Regular Contributor III
It looks like you're using VBA or VB6.  If so, you usually need to use Set when assigning object values.  Also, you'll want to be sure that the feature class you're referencing is inside a feature dataset or its FeatureDataset property will be Nothing.  Your current code will error out if that's the case.

EDIT: Another possible thing to consider. You may need to use a dataset name object that comes from the workspace you're exporting into.  It may also be required that this feature dataset already exist in that workspace.  The exporter probably will not create it for you.
0 Kudos
ShaunConway
Occasional Contributor II
Thanks for the help everyone. Here is revamped code:

pFeatureClassName.FeatureType = pFc.FeatureType
pFeatureClassName.ShapeType = pFc.ShapeType
pFeatureClassName.ShapeFieldName = pFc.ShapeFieldName
Set pFeatureClassName.FeatureDatasetName = pFc.FeatureDataset.FullName


The code still bombed out if I used
Set pFeatureClassName.FeatureDatasetName = pFc.FeatureDataset.Name[

instead of
Set pFeatureClassName.FeatureDatasetName = pFc.FeatureDataset.FullName[


Its working now. Thanks again for the quick replies - I really appreciate the help.
0 Kudos