ThinkGeo.com    |     Documentation    |     Premium Support

GetAllFeatures(ReturningColumnsType.AllColumns)

The client we are doing GIS for provides the SHP and DBF files for us to use.


We need a way to do a lookup based on a column in the DBF to find the corresponding Feature ID so can place a marker on it.


Sounds simple enough.

But when I try to iterate through the features, it keeps telling me that a key with that value already exists.



For Each feature As Feature In shpMuni.QueryTools.GetAllFeatures(ReturningColumnsType.NoColumns)



 This will iterate through, but if I add any column names in the curly braces or use AllColumns, that's when I get the error.


Any thoughts?


Thanks.


Kirk



Kirk, 



You can try the method ShapeFileFeatureSource.ExecuteQuery(SQLSatement), which I think is more convenient for your requirement. 



For your specific issue(isn't an issue if you try the above way though), could you get all features and set it to a variable first and then use that variable in the iterate. In the current way, the GetAllFeatures method will be execute again and again in the iterate. Codes should be like this: 


Dim allFeatures as Collection = shpMuni.QueryTools.GetAllFeatures(ReturningColumnsType.NoColumns) 
For Each feature as Feature In allFeatures 

Thanks, 



Ben 

 



Kirk,


 To add to Ben’s comments you can look through the columns as well. See the sample code below.




            ' Create and open our layer
            Dim worldLayer As New ShapeFileFeatureLayer("..\..\SampleData\Data\Countries02.shp")            
            worldLayer.Open()

            ' Let's loop through the column and write them to the debug so we know what we
            ' can request
            Dim columns As Collection(Of FeatureSourceColumn) = worldLayer.QueryTools.GetColumns()
            For Each column As FeatureSourceColumn In columns
                Debug.WriteLine(column.ColumnName)
            Next

            ' Return all the features and bring back the country name
            Dim features As Collection(Of Feature) = worldLayer.QueryTools.GetAllFeatures(New String() {"cntry_name"})

            ' Make sure to close the layer when we are done with it
            worldLayer.Close()

            ' Loop through your results to find what you are looking for.
            For Each feature As Feature In features
                If feature.ColumnValues("cntry_name") = "Canada" Then
                    MessageBox.Show("Found it!")
                End If
            Next