Skip to main content
deleted 31 characters in body
Source Link
Hornbydd
  • 44.6k
  • 5
  • 42
  • 84

I amwant to export witha query to SHP file but ifa Shapefile. If the query is empty I get an error and it don'twill not export, anyone here who. How can help me with this please how I can do nothing if the query is empty and export next query in the list?

I am export with query to SHP file but if the query is empty I get error and it don't export, anyone here who can help me with this please how I can do nothing if query is empty and export next query in the list

I want to export a query to a Shapefile. If the query is empty I get an error and it will not export. How can I do nothing if the query is empty and export next query in the list?

Added language tags
Source Link
Hornbydd
  • 44.6k
  • 5
  • 42
  • 84
  Public Sub Export_with_query(ByVal ep_layer, ByVal ep_name, ByVal ep_query)

    Dim pDoc As IMxDocument
    Dim pMap As IMap
    Dim pFLayer As IFeatureLayer
    Dim pFc As IFeatureClass
    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 pExportOp As ESRI.ArcGIS.GeoDatabaseUI.IExportOperation

    Try

        pDoc = My.ArcMap.Document
        pMap = pDoc.FocusMap
        pFLayer = pMap.Layer(ep_layer)
        pFc = pFLayer.FeatureClass

        'Get the FcName from the featureclass
        pDataset = pFc
        pINFeatureClassName = pDataset.FullName
        pInDsName = pINFeatureClassName

        'Get the selection set
        pFSel = pFLayer
        pSelSet = pFSel.SelectionSet

        Dim pQFilter As IQueryFilter

        pQFilter = New QueryFilter

        pQFilter.WhereClause = "TYPE =  '" & ep_query & "'"
        
        If pFc.FeatureCount(pQFilter) = 0 Then

            Exit Sub

        Else
        

        'Define the output feature class name
        pFeatureClassName = New FeatureClassName
        pOutDatasetName = pFeatureClassName
        pOutDatasetName.Name = ep_name
        pWorkspaceName = New WorkspaceName
        If Chk_default_path.Checked = True Then
            pWorkspaceName.PathName = "c:\map"
        Else
            pWorkspaceName.PathName = Txt_path.Text
        End If
        pWorkspaceName.WorkspaceFactoryProgID = _
              "esriCore.shapefileworkspacefactory.1"
        pOutDatasetName.WorkspaceName = pWorkspaceName
        'pFeatureClassName.FeatureType = esriFTSimple
        pFeatureClassName.FeatureType = ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple
        '  pFeatureClassName.ShapeType = esriGeometryAny
        pFeatureClassName.ShapeType = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryAny
        pFeatureClassName.ShapeFieldName = "Shape"

        'Export
        ' pExportOp = New ExportOperation
        pExportOp = New ESRI.ArcGIS.GeoDatabaseUI.ExportOperation
        ' pExportOp.ExportFeatureClass(pInDsName, Nothing, pSelSet, Nothing, pOutDatasetName, 0)

        pExportOp.ExportFeatureClass(pInDsName, pQFilter, pSelSet, Nothing, pOutDatasetName, 0)
        'pExportOp.ExportFeatureClass(pInFClassName, pQFilter, pSelSet, pGeomDef, pOutDatasetName, 0)
        '   End If


    Catch ex As Exception
        MessageBox.Show("Error exporting map: " & vbCrLf & ex.ToString)
    Finally

    End Try

End Sub

#End Region

  Public Sub Export_with_query(ByVal ep_layer, ByVal ep_name, ByVal ep_query)

    Dim pDoc As IMxDocument
    Dim pMap As IMap
    Dim pFLayer As IFeatureLayer
    Dim pFc As IFeatureClass
    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 pExportOp As ESRI.ArcGIS.GeoDatabaseUI.IExportOperation

    Try

        pDoc = My.ArcMap.Document
        pMap = pDoc.FocusMap
        pFLayer = pMap.Layer(ep_layer)
        pFc = pFLayer.FeatureClass

        'Get the FcName from the featureclass
        pDataset = pFc
        pINFeatureClassName = pDataset.FullName
        pInDsName = pINFeatureClassName

        'Get the selection set
        pFSel = pFLayer
        pSelSet = pFSel.SelectionSet

        Dim pQFilter As IQueryFilter
        pQFilter = New QueryFilter
        pQFilter.WhereClause = "TYPE =  '" & ep_query & "'"
        If pFc.FeatureCount(pQFilter) = 0 Then
            Exit Sub
        Else

        'Define the output feature class name
        pFeatureClassName = New FeatureClassName
        pOutDatasetName = pFeatureClassName
        pOutDatasetName.Name = ep_name
        pWorkspaceName = New WorkspaceName
        If Chk_default_path.Checked = True Then
            pWorkspaceName.PathName = "c:\map"
        Else
            pWorkspaceName.PathName = Txt_path.Text
        End If
        pWorkspaceName.WorkspaceFactoryProgID = _
              "esriCore.shapefileworkspacefactory.1"
        pOutDatasetName.WorkspaceName = pWorkspaceName
        'pFeatureClassName.FeatureType = esriFTSimple
        pFeatureClassName.FeatureType = ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple
        '  pFeatureClassName.ShapeType = esriGeometryAny
        pFeatureClassName.ShapeType = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryAny
        pFeatureClassName.ShapeFieldName = "Shape"

        'Export
        ' pExportOp = New ExportOperation
        pExportOp = New ESRI.ArcGIS.GeoDatabaseUI.ExportOperation
        ' pExportOp.ExportFeatureClass(pInDsName, Nothing, pSelSet, Nothing, pOutDatasetName, 0)

        pExportOp.ExportFeatureClass(pInDsName, pQFilter, pSelSet, Nothing, pOutDatasetName, 0)
        'pExportOp.ExportFeatureClass(pInFClassName, pQFilter, pSelSet, pGeomDef, pOutDatasetName, 0)
        '   End If

    Catch ex As Exception
        MessageBox.Show("Error exporting map: " & vbCrLf & ex.ToString)
    Finally
    End Try
End Sub
  Public Sub Export_with_query(ByVal ep_layer, ByVal ep_name, ByVal ep_query)

    Dim pDoc As IMxDocument
    Dim pMap As IMap
    Dim pFLayer As IFeatureLayer
    Dim pFc As IFeatureClass
    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 pExportOp As ESRI.ArcGIS.GeoDatabaseUI.IExportOperation

    Try

        pDoc = My.ArcMap.Document
        pMap = pDoc.FocusMap
        pFLayer = pMap.Layer(ep_layer)
        pFc = pFLayer.FeatureClass

        'Get the FcName from the featureclass
        pDataset = pFc
        pINFeatureClassName = pDataset.FullName
        pInDsName = pINFeatureClassName

        'Get the selection set
        pFSel = pFLayer
        pSelSet = pFSel.SelectionSet

        Dim pQFilter As IQueryFilter

        pQFilter = New QueryFilter

        pQFilter.WhereClause = "TYPE =  '" & ep_query & "'"
        
        If pFc.FeatureCount(pQFilter) = 0 Then

            Exit Sub

        Else
        

        'Define the output feature class name
        pFeatureClassName = New FeatureClassName
        pOutDatasetName = pFeatureClassName
        pOutDatasetName.Name = ep_name
        pWorkspaceName = New WorkspaceName
        If Chk_default_path.Checked = True Then
            pWorkspaceName.PathName = "c:\map"
        Else
            pWorkspaceName.PathName = Txt_path.Text
        End If
        pWorkspaceName.WorkspaceFactoryProgID = _
              "esriCore.shapefileworkspacefactory.1"
        pOutDatasetName.WorkspaceName = pWorkspaceName
        'pFeatureClassName.FeatureType = esriFTSimple
        pFeatureClassName.FeatureType = ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple
        '  pFeatureClassName.ShapeType = esriGeometryAny
        pFeatureClassName.ShapeType = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryAny
        pFeatureClassName.ShapeFieldName = "Shape"

        'Export
        ' pExportOp = New ExportOperation
        pExportOp = New ESRI.ArcGIS.GeoDatabaseUI.ExportOperation
        ' pExportOp.ExportFeatureClass(pInDsName, Nothing, pSelSet, Nothing, pOutDatasetName, 0)

        pExportOp.ExportFeatureClass(pInDsName, pQFilter, pSelSet, Nothing, pOutDatasetName, 0)
        'pExportOp.ExportFeatureClass(pInFClassName, pQFilter, pSelSet, pGeomDef, pOutDatasetName, 0)
        '   End If


    Catch ex As Exception
        MessageBox.Show("Error exporting map: " & vbCrLf & ex.ToString)
    Finally

    End Try

End Sub

#End Region

  Public Sub Export_with_query(ByVal ep_layer, ByVal ep_name, ByVal ep_query)

    Dim pDoc As IMxDocument
    Dim pMap As IMap
    Dim pFLayer As IFeatureLayer
    Dim pFc As IFeatureClass
    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 pExportOp As ESRI.ArcGIS.GeoDatabaseUI.IExportOperation

    Try

        pDoc = My.ArcMap.Document
        pMap = pDoc.FocusMap
        pFLayer = pMap.Layer(ep_layer)
        pFc = pFLayer.FeatureClass

        'Get the FcName from the featureclass
        pDataset = pFc
        pINFeatureClassName = pDataset.FullName
        pInDsName = pINFeatureClassName

        'Get the selection set
        pFSel = pFLayer
        pSelSet = pFSel.SelectionSet

        Dim pQFilter As IQueryFilter
        pQFilter = New QueryFilter
        pQFilter.WhereClause = "TYPE =  '" & ep_query & "'"
        If pFc.FeatureCount(pQFilter) = 0 Then
            Exit Sub
        Else

        'Define the output feature class name
        pFeatureClassName = New FeatureClassName
        pOutDatasetName = pFeatureClassName
        pOutDatasetName.Name = ep_name
        pWorkspaceName = New WorkspaceName
        If Chk_default_path.Checked = True Then
            pWorkspaceName.PathName = "c:\map"
        Else
            pWorkspaceName.PathName = Txt_path.Text
        End If
        pWorkspaceName.WorkspaceFactoryProgID = _
              "esriCore.shapefileworkspacefactory.1"
        pOutDatasetName.WorkspaceName = pWorkspaceName
        'pFeatureClassName.FeatureType = esriFTSimple
        pFeatureClassName.FeatureType = ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple
        '  pFeatureClassName.ShapeType = esriGeometryAny
        pFeatureClassName.ShapeType = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryAny
        pFeatureClassName.ShapeFieldName = "Shape"

        'Export
        ' pExportOp = New ExportOperation
        pExportOp = New ESRI.ArcGIS.GeoDatabaseUI.ExportOperation
        ' pExportOp.ExportFeatureClass(pInDsName, Nothing, pSelSet, Nothing, pOutDatasetName, 0)

        pExportOp.ExportFeatureClass(pInDsName, pQFilter, pSelSet, Nothing, pOutDatasetName, 0)
        'pExportOp.ExportFeatureClass(pInFClassName, pQFilter, pSelSet, pGeomDef, pOutDatasetName, 0)
        '   End If

    Catch ex As Exception
        MessageBox.Show("Error exporting map: " & vbCrLf & ex.ToString)
    Finally
    End Try
End Sub
edited tags; edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
added 101 characters in body
Source Link
Sigster
  • 109
  • 7
Loading
Source Link
Sigster
  • 109
  • 7
Loading