problem with queryLayer.ExecuteIntersectionQuery too polygon selected in one click

Topics: Algorithms, Italiano, SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0
Aug 27, 2015 at 12:38 PM
Image

how you can see in the image, when I click inside a polygon , other to select the polygon clicked , I select all polygons whose bounding rectangle enclosing my click.

How I can select only clicked polygon and not others?

this is my code:
    Private Sub Mouse_Click_Map(sender As Object, e As MouseEventArgs) Handles MapBox1.Click

        Dim p As Coordinate = MapBox1.Map.ImageToWorld(e.Location)
        Dim env As New Envelope(p)
        env.ExpandBy(0)
        Dim ds As FeatureDataSet = New FeatureDataSet()
        For Each Layer As Object In MapBox1.Map.Layers
            Dim queryLayer = TryCast(Layer, SharpMap.Layers.ICanQueryLayer)
            If Not queryLayer Is Nothing Then
                queryLayer.ExecuteIntersectionQuery(env, ds)
            End If
        Next


...
...
many thanks.
Coordinator
Aug 28, 2015 at 6:52 AM
Edited Aug 28, 2015 at 8:04 AM
You need to pass a geometry instead of an Envelope to ExecuteIntersectionQuery function.
REM ...

env.ExpandBy(MapBox1.Map.PixelSize * 2)
Dim geom As IGeometry = new MapBox1.Map.Factory.ToGeometry(env)

Dim ds As FeatureDataSet = New FeatureDataSet()
    For Each Layer As Object In MapBox1.Map.Layers
    Dim queryLayer = TryCast(Layer, SharpMap.Layers.ICanQueryLayer)
    If Not queryLayer Is Nothing Then
        queryLayer.ExecuteIntersectionQuery(geom, ds)
    End If
Next

REM ...
Aug 28, 2015 at 7:23 AM
great: it work fine.

only a small correction:
env.ExpandBy(MapBox1.Map.PixelSize * 2)
Dim geom As IGeometry = MapBox1.Map.Factory.ToGeometry(env)

Dim ds As FeatureDataSet = New FeatureDataSet()
    For Each Layer As Object In MapBox1.Map.Layers
    Dim queryLayer = TryCast(Layer, SharpMap.Layers.ICanQueryLayer)
    If Not queryLayer Is Nothing Then
        queryLayer.ExecuteIntersectionQuery(geo, ds)
    End If
Next
many thanks
Coordinator
Aug 28, 2015 at 8:05 AM
Edited Aug 28, 2015 at 8:05 AM
only a small correction:
Copy and paste..., sorry