Problems with IQueryFilter and shp-File

634
2
04-08-2014 07:21 AM
UlfKliemand
New Contributor
Hello,

I want to get the selected features from a Layer.
Data:
tcKeyColumn= "INFOTEXT"
tcLayer= "flstkop3"
tcObjectIDs="FS3400400|FS3400500|"

This is my Code:
    Public Function SelectMapFeatures(ByRef tcKeyColumn As String, ByRef tcLayer As String, ByRef tcObjectIDs As String, ByRef tcDataframe As String) As Boolean
        Dim loMxDoc As IMxDocument = goApp.Document
        Dim lomap As IMap = loMxDoc.FocusMap
        Dim loActiveView As IActiveView
        Dim loFeatureLayer As IFeatureLayer
        Dim loFeatureSelection As IFeatureSelection
        Dim loLayer As ILayer = lomap.Layer(0)
        Dim loQueryFilter As IQueryFilter = New QueryFilter
        Dim lcClause As String
        Dim lcObjectID As String
        Dim lcZWstring As String
        Dim lcData As String
        Dim lnSelektionAnzahl As Integer
        Dim lnUebergabeObjektAnzahl As Integer
        Dim lnNewFLSTIndex As Integer
        Dim i As Integer
        Dim j As Long
        Dim llweiter As Boolean
        Dim tlnew As Boolean

        lcData = "x"
        SelectMapFeatures = False
        lnUebergabeObjektAnzahl = occurs(tcObjectIDs, "|")
        ReDim gcObjId(lnUebergabeObjektAnzahl)
        If Not tcDataframe = "" Then
            If Not ActivateDataframe((tcDataframe)) Then
                Exit Function
            End If

        End If
        lomap.ClearSelection()
        loActiveView = lomap
        For i = 0 To lomap.LayerCount - 1
            If TypeOf lomap.Layer(i) Is IGroupLayer Then
                Call Get_GroupLayerName(loMxDoc, tcLayer, loLayer)
                If Not loLayer Is Nothing Then
                    loFeatureLayer = loLayer
                    llweiter = True
                Else
                    llweiter = False
                End If
            Else
                If occurs(";" & UCase(tcLayer) & ";", ";" & UCase(GetLayerName(i)) & ";") Then
                    loFeatureLayer = lomap.Layer(i)
                    llweiter = True
                Else
                    llweiter = False
                End If
            End If
            If Not llweiter Then GoTo nexti
            tlnew = True
            lcClause = ""
            For j = 1 To lnUebergabeObjektAnzahl
                lcZWstring = token(tcObjectIDs, "|", j)
                lcObjectID = token(lcZWstring, "(", 1)
                lcClause = lcClause & Chr(91) & tcKeyColumn & Chr(93) & " = " & Chr(39) & lcObjectID & Chr(39) & " or "
            Next j
            lcClause = Left(lcClause, Len(lcClause) - 4)
            loQueryFilter.WhereClause = lcClause
            Dim pFSel As IFeatureSelection
            pFSel = loLayer
            loActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)
            If tlnew Then
                Try
                    pFSel.SelectFeatures(loQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, False)
                Catch ex As Exception
                    MsgBox("Fehler " & vbCrLf & ex.Message)
                End Try
            Else
                pFSel.SelectFeatures(loQueryFilter, esriSelectionResultEnum.esriSelectionResultAdd, False)
            End If
            tlnew = False
nexti:
        Next i
       loActiveView = Nothing
        lomap = Nothing
        loMxDoc = Nothing
End Function

When the layer where I select the features is in a Geodatabase it works good. If the layer is a shp-file I get the Error "Error HRESULT E_FAIL has been returned from a call to a COM component"
The original code was VB6 for ArcGIS 9.2, now it is VB.Net Express 2010 and ArcGis 10.2. With 9.2 it worked with Geodatabases and shp-Files.
May be I posted i lttle bit to much, but I tried a lot. Please, any Help. How can I get the selected features and get the values of a specified attribut when the features are in a shp-file?
0 Kudos
2 Replies
AhmedEl-Sisi
Occasional Contributor III
Get your Where Clause in Runtime and apply it on arcmap.
I think you enclose your Field name with " instead of [ as it throws error.

Read the following posts carefully:
The syntax of a SQL statement depends on the workspace type that is being used.

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/SQL_reference_for_query_expressions_us...
http://support.esri.com/en/knowledgebase/techarticles/detail/40355

Regards,
0 Kudos
UlfKliemand
New Contributor
Thank you very much Ahmed, this was the right hint. Now I can query shp-files and geodatabases, thanks a lot.
Regards
0 Kudos