Skip to main content
added 312 characters in body
Source Link
whuber
  • 70.2k
  • 16
  • 187
  • 282

Sorry for the formatting..

Public Function ExportjoinedShapefile(sLocation As String, ShpFilename As String) As IFeatureClass

Dim sProcName As String sProcName = "ExportFeatureLayer"

On Error GoTo EH

Public Function ExportjoinedShapefile(sLocation As String, ShpFilename As String) As IFeatureClass

Dim sProcName As String
sProcName = "ExportFeatureLayer"
    
On Error GoTo EH

    Dim pmxdoc As IMxDocument
    Set pmxdoc = ThisDocument
    
    Dim pmap As IMap
    Set pmap = pmxdoc.FocusMap
    
    Dim pflayer As IFeatureLayer
    Set pflayer = pmap.Layer(0)
    
    Set ExportFeatureLayer = Nothing

    Dim pInFc As IFeatureClass
    Set pInFc = pflayer.FeatureClass
    
    Dim pDispTable As IDisplayTable
    Set pDispTable = pflayer
    
    Dim pTable As ITable
    Set pTable = pDispTable.DisplayTable

' Get the FcName from the featureclass Dim pInDataset As IDataset Set pInDataset = pTable 'pInFc


  ' Get the FcName from the featureclass
    Dim pInDataset As IDataset
    Set pInDataset = pTable 'pInFc
    
    Dim pInDsName As IDatasetName
    Set pInDsName = pInDataset.FullName

' Create a new feature class name ' Define the output feature class name Dim pOutFeatureClassName As IFeatureClassName Set pOutFeatureClassName = New FeatureClassName

    
  ' Create a new feature class name
  ' Define the output feature class name
    Dim pOutFeatureClassName As IFeatureClassName
    Set pOutFeatureClassName = New FeatureClassName

    Dim pOutDatasetName As IDatasetName
    Set pOutDatasetName = pOutFeatureClassName

    pOutDatasetName.Name = ShpFilename   ' here you set the output shpfile name


    Dim pOutWorkspaceName As IWorkspaceName
    Set pOutWorkspaceName = New WorkspaceName

' output path of new shapefile pOutWorkspaceName.PathName = sLocation ' here is your location pOutWorkspaceName.WorkspaceFactoryProgID = "esriCore.ShapefileWorkspaceFactory.1" Set pOutDatasetName.WorkspaceName = pOutWorkspaceName

' output shapefile characteristics pOutFeatureClassName.FeatureType = esriFTSimple pOutFeatureClassName.ShapeType = pInFc.ShapeType pOutFeatureClassName.ShapeFieldName = "Shape"

' Export Dim pExportOp As IExportOperation Set pExportOp = New ExportOperation pExportOp.ExportFeatureClass pInDsName, Nothing, Nothing, Nothing, pOutDatasetName, 0

    
  ' output path of new shapefile
    pOutWorkspaceName.PathName = sLocation ' here is your location
    pOutWorkspaceName.WorkspaceFactoryProgID = "esriCore.ShapefileWorkspaceFactory.1"
    Set pOutDatasetName.WorkspaceName = pOutWorkspaceName

  ' output shapefile characteristics
    pOutFeatureClassName.FeatureType = esriFTSimple
    pOutFeatureClassName.ShapeType = pInFc.ShapeType
    pOutFeatureClassName.ShapeFieldName = "Shape"

  ' Export
    Dim pExportOp As IExportOperation
    Set pExportOp = New ExportOperation
    pExportOp.ExportFeatureClass pInDsName, Nothing, Nothing, Nothing, pOutDatasetName, 0

    Dim pOutFeatureClass As IFeatureClass

' get the feature classes from the name ' see pg 72 Vol2, Exploring ArcObjects Book Dim pOutName As IName Set pOutName = pOutFeatureClassName 'QI Set pOutFeatureClass = pOutName.Open

' ' maybe check if export was successful '

' set the function return Set ExportFeatureLayer = pOutFeatureClass

  ' get the feature classes from the name
  ' see pg 72 Vol2, Exploring ArcObjects Book
    Dim pOutName As IName
    Set pOutName = pOutFeatureClassName    'QI
    Set pOutFeatureClass = pOutName.Open
    
  '
  ' maybe check if export was successful
  '
  
  ' set the function return
    Set ExportFeatureLayer = pOutFeatureClass
    
    Exit Function

EH:

    
EH:

    MsgBox "Error number: " & CStr(Err.Number) & _
           vbCrLf & "Error description: " & Err.Description & _
           vbCrLf & "Location:" & sProcName, _
           vbExclamation + vbOKOnly, "Your Title"
           
End Function

End Function

Sorry for the formatting..

Public Function ExportjoinedShapefile(sLocation As String, ShpFilename As String) As IFeatureClass

Dim sProcName As String sProcName = "ExportFeatureLayer"

On Error GoTo EH

Dim pmxdoc As IMxDocument
Set pmxdoc = ThisDocument

Dim pmap As IMap
Set pmap = pmxdoc.FocusMap

Dim pflayer As IFeatureLayer
Set pflayer = pmap.Layer(0)

Set ExportFeatureLayer = Nothing

Dim pInFc As IFeatureClass
Set pInFc = pflayer.FeatureClass

Dim pDispTable As IDisplayTable
Set pDispTable = pflayer

Dim pTable As ITable
Set pTable = pDispTable.DisplayTable

' Get the FcName from the featureclass Dim pInDataset As IDataset Set pInDataset = pTable 'pInFc

Dim pInDsName As IDatasetName
Set pInDsName = pInDataset.FullName

' Create a new feature class name ' Define the output feature class name Dim pOutFeatureClassName As IFeatureClassName Set pOutFeatureClassName = New FeatureClassName

Dim pOutDatasetName As IDatasetName
Set pOutDatasetName = pOutFeatureClassName

pOutDatasetName.Name = ShpFilename   ' here you set the output shpfile name


Dim pOutWorkspaceName As IWorkspaceName
Set pOutWorkspaceName = New WorkspaceName

' output path of new shapefile pOutWorkspaceName.PathName = sLocation ' here is your location pOutWorkspaceName.WorkspaceFactoryProgID = "esriCore.ShapefileWorkspaceFactory.1" Set pOutDatasetName.WorkspaceName = pOutWorkspaceName

' output shapefile characteristics pOutFeatureClassName.FeatureType = esriFTSimple pOutFeatureClassName.ShapeType = pInFc.ShapeType pOutFeatureClassName.ShapeFieldName = "Shape"

' Export Dim pExportOp As IExportOperation Set pExportOp = New ExportOperation pExportOp.ExportFeatureClass pInDsName, Nothing, Nothing, Nothing, pOutDatasetName, 0

Dim pOutFeatureClass As IFeatureClass

' get the feature classes from the name ' see pg 72 Vol2, Exploring ArcObjects Book Dim pOutName As IName Set pOutName = pOutFeatureClassName 'QI Set pOutFeatureClass = pOutName.Open

' ' maybe check if export was successful '

' set the function return Set ExportFeatureLayer = pOutFeatureClass

Exit Function

EH:

MsgBox "Error number: " & CStr(Err.Number) & _
       vbCrLf & "Error description: " & Err.Description & _
       vbCrLf & "Location:" & sProcName, _
       vbExclamation + vbOKOnly, "Your Title"
       

End Function

Public Function ExportjoinedShapefile(sLocation As String, ShpFilename As String) As IFeatureClass

Dim sProcName As String
sProcName = "ExportFeatureLayer"
    
On Error GoTo EH

    Dim pmxdoc As IMxDocument
    Set pmxdoc = ThisDocument
    
    Dim pmap As IMap
    Set pmap = pmxdoc.FocusMap
    
    Dim pflayer As IFeatureLayer
    Set pflayer = pmap.Layer(0)
    
    Set ExportFeatureLayer = Nothing

    Dim pInFc As IFeatureClass
    Set pInFc = pflayer.FeatureClass
    
    Dim pDispTable As IDisplayTable
    Set pDispTable = pflayer
    
    Dim pTable As ITable
    Set pTable = pDispTable.DisplayTable

  ' Get the FcName from the featureclass
    Dim pInDataset As IDataset
    Set pInDataset = pTable 'pInFc
    
    Dim pInDsName As IDatasetName
    Set pInDsName = pInDataset.FullName
    
  ' Create a new feature class name
  ' Define the output feature class name
    Dim pOutFeatureClassName As IFeatureClassName
    Set pOutFeatureClassName = New FeatureClassName

    Dim pOutDatasetName As IDatasetName
    Set pOutDatasetName = pOutFeatureClassName

    pOutDatasetName.Name = ShpFilename   ' here you set the output shpfile name


    Dim pOutWorkspaceName As IWorkspaceName
    Set pOutWorkspaceName = New WorkspaceName
    
  ' output path of new shapefile
    pOutWorkspaceName.PathName = sLocation ' here is your location
    pOutWorkspaceName.WorkspaceFactoryProgID = "esriCore.ShapefileWorkspaceFactory.1"
    Set pOutDatasetName.WorkspaceName = pOutWorkspaceName

  ' output shapefile characteristics
    pOutFeatureClassName.FeatureType = esriFTSimple
    pOutFeatureClassName.ShapeType = pInFc.ShapeType
    pOutFeatureClassName.ShapeFieldName = "Shape"

  ' Export
    Dim pExportOp As IExportOperation
    Set pExportOp = New ExportOperation
    pExportOp.ExportFeatureClass pInDsName, Nothing, Nothing, Nothing, pOutDatasetName, 0

    Dim pOutFeatureClass As IFeatureClass
  ' get the feature classes from the name
  ' see pg 72 Vol2, Exploring ArcObjects Book
    Dim pOutName As IName
    Set pOutName = pOutFeatureClassName    'QI
    Set pOutFeatureClass = pOutName.Open
    
  '
  ' maybe check if export was successful
  '
  
  ' set the function return
    Set ExportFeatureLayer = pOutFeatureClass
    
    Exit Function
    
EH:

    MsgBox "Error number: " & CStr(Err.Number) & _
           vbCrLf & "Error description: " & Err.Description & _
           vbCrLf & "Location:" & sProcName, _
           vbExclamation + vbOKOnly, "Your Title"
           
End Function
Post Undeleted by ericoneal
Post Deleted by ericoneal
Source Link
ericoneal
  • 825
  • 4
  • 13

Sorry for the formatting..

Public Function ExportjoinedShapefile(sLocation As String, ShpFilename As String) As IFeatureClass

Dim sProcName As String sProcName = "ExportFeatureLayer"

On Error GoTo EH

Dim pmxdoc As IMxDocument
Set pmxdoc = ThisDocument

Dim pmap As IMap
Set pmap = pmxdoc.FocusMap

Dim pflayer As IFeatureLayer
Set pflayer = pmap.Layer(0)

Set ExportFeatureLayer = Nothing

Dim pInFc As IFeatureClass
Set pInFc = pflayer.FeatureClass

Dim pDispTable As IDisplayTable
Set pDispTable = pflayer

Dim pTable As ITable
Set pTable = pDispTable.DisplayTable

' Get the FcName from the featureclass Dim pInDataset As IDataset Set pInDataset = pTable 'pInFc

Dim pInDsName As IDatasetName
Set pInDsName = pInDataset.FullName

' Create a new feature class name ' Define the output feature class name Dim pOutFeatureClassName As IFeatureClassName Set pOutFeatureClassName = New FeatureClassName

Dim pOutDatasetName As IDatasetName
Set pOutDatasetName = pOutFeatureClassName

pOutDatasetName.Name = ShpFilename   ' here you set the output shpfile name


Dim pOutWorkspaceName As IWorkspaceName
Set pOutWorkspaceName = New WorkspaceName

' output path of new shapefile pOutWorkspaceName.PathName = sLocation ' here is your location pOutWorkspaceName.WorkspaceFactoryProgID = "esriCore.ShapefileWorkspaceFactory.1" Set pOutDatasetName.WorkspaceName = pOutWorkspaceName

' output shapefile characteristics pOutFeatureClassName.FeatureType = esriFTSimple pOutFeatureClassName.ShapeType = pInFc.ShapeType pOutFeatureClassName.ShapeFieldName = "Shape"

' Export Dim pExportOp As IExportOperation Set pExportOp = New ExportOperation pExportOp.ExportFeatureClass pInDsName, Nothing, Nothing, Nothing, pOutDatasetName, 0

Dim pOutFeatureClass As IFeatureClass

' get the feature classes from the name ' see pg 72 Vol2, Exploring ArcObjects Book Dim pOutName As IName Set pOutName = pOutFeatureClassName 'QI Set pOutFeatureClass = pOutName.Open

' ' maybe check if export was successful '

' set the function return Set ExportFeatureLayer = pOutFeatureClass

Exit Function

EH:

MsgBox "Error number: " & CStr(Err.Number) & _
       vbCrLf & "Error description: " & Err.Description & _
       vbCrLf & "Location:" & sProcName, _
       vbExclamation + vbOKOnly, "Your Title"
       

End Function