This project has moved and is read-only. For the latest updates, please go here.

Add Feature To SelectionLayer in SharpMap 1.1

Topics: SharpMap v0.9 / v1.x
Jul 10, 2014 at 1:59 PM
I want to highlight a feature by adding it to a selection layer.
The right feature is found, but after the MyMapControl.Refresh I got the following error:
Message: "Attribute data is not supported by the GeometryProvider."
StackTrace: SharpMap.Data.Providers.GeometryProvider.OnExecuteIntersectionQuery(IGeometry geom, FeatureDataSet ds)

Here is my Eventhandler
Private Sub Map_MouseClick(ByVal sender As Object, ByVal e As MouseEventArgs)
    Dim p As GeoAPI.Geometries.Coordinate = MyMapControl.Map.ImageToWorld(System.Drawing.Point.op_Implicit(New System.Drawing.Point(CInt(e.Location.X), CInt(e.Location.Y))))
    Dim ds As New SharpMap.Data.FeatureDataSet()

    Dim layer As SharpMap.Layers.VectorLayer = TryCast(MyMapControl.Map.FindLayer("States").FirstOrDefault(), VectorLayer)
    If Not layer.DataSource.IsOpen Then
    End If

    Dim box = New GeoAPI.Geometries.Envelope(p)
    layer.DataSource.ExecuteIntersectionQuery(box, ds)

    If ds.Tables.Count > 0 Then
        Dim selectionLayer = New SharpMap.Layers.VectorLayer("Selection")
        selectionLayer.DataSource = New GeometryProvider(ds.Tables(0))
        selectionLayer.Style.Fill = New System.Drawing.SolidBrush(System.Drawing.Color.DarkCyan)
        MyMapControl.Map.Layers.Insert(0, selectionLayer)
    End If
End Sub
I'm using the MapBox control and SharpMap 1.1

Thanks for any help
Jul 11, 2014 at 9:55 AM
You should use the GeometryFeatureProvider when dealing with features... please note that mapbox already provides the query tool, this gives you all the features "around" the clicked point.
Jul 15, 2014 at 10:03 AM
Edited Jul 16, 2014 at 1:37 PM
Thanks for your answer.
I tried the query tools QueryBox and QueryPoint. QueryBox works fine, but setting Tools to QueryPoint the data parameter of the eventhandler of the MapQueried event never has any geometries.

Now I want to select features by drawing a polygon. Here the ExecuteIntersectionQuery method delivers no table. What's wrong with my code:
Public Sub SelectFeatureByGeometry(ByVal geometry As IGeometry)
    Dim featureList = New SharpMap.Data.FeatureDataSet()
    Dim layer As SharpMap.Layers.VectorLayer = TryCast(Map.FindLayer("Tatsächliche_Nutzung").FirstOrDefault(), VectorLayer)
    If TypeOf layer Is ICanQueryLayer Then
        layer.DataSource.ExecuteIntersectionQuery(geometry, featureList)
    End If
    If featureList.Tables.Count > 0 Then
        SelectionLayer.DataSource = New GeometryFeatureProvider(featureList.Tables(0))
    End If
End Sub
Thanks for any help
Jul 18, 2014 at 10:43 AM
Problem found: The problem
QueryByPoint calls OnExecuteIntersectionQuery using IGeometry , QueryByBox calls ExecuteIntersectionQuery using Envelope
Bug is described in descriped Bug