Querying Data from Maps

Topics: SharpMap Project, SharpMap v0.9 / v1.x
Jun 1, 2015 at 3:09 PM
Edited Jun 1, 2015 at 3:10 PM
I am able to Query the feature data however i am not able to make a gud envelope it requires me to zoom n click precisely on the point also the values +- 10000 are not very useful in all coordinate systems.
i need an help for an efficient code for the mouseclick capture.
the need for this is due to MapQueried() gives a featuredatatable which is not containing multiple vector layers.

Heres my code can any one help??
   Public Function QueryFeatureData(ByRef map As SharpMap.Map, ByVal m As MouseEventArgs) As FeatureDataTable
    Dim fs = New FeatureDataSet
    Dim ft = New FeatureDataTable
    Dim ptClick As Coordinate = SharpMap.Utilities.Transform.MapToWorld(New PointF(m.X,   m.Y), frmMain.mapbxMain.Map)
    Dim dblZoom2 = 0.0001
    Dim dblZoom1 = frmMain.mapbxMain.Map.Zoom
    frmMain.mapbxMain.Map.Zoom = dblZoom2
    ptClick = SharpMap.Utilities.Transform.MapToWorld(New PointF(m.X, m.Y),frmMain.mapbxMain.Map)  
    Dim x = CDbl(ptClick.X)
    Dim y = CDbl(ptClick.Y)
    Dim env As Envelope = New Envelope(x - 10000, x + 10000, y - 10000, y + 10000)
    frmMain.mapbxMain.Map.Zoom = dblZoom1
    frmMain.mapbxMain.Refresh()


    For Each clayer In map.Layers
        Dim queryLayer As SharpMap.Layers.ICanQueryLayer = clayer
        If queryLayer.IsQueryEnabled Then
            If Not (queryLayer.GetType.ToString = "SharpMap.Layers.GdalRasterLayer") Then
                queryLayer.ExecuteIntersectionQuery(env, fs)
            End If
        End If
    Next
    ft = fs.Tables(0).Clone
    For Each dt In fs.Tables
        ft.Merge(dt)
    Next
    Return ft
End Function
Coordinator
Jun 1, 2015 at 3:30 PM
with MapBox.Map.PixelSize you have access to the world size of a pixel, that means you can set your query envelope to 5 px in each direction like this
Dim dblBuffer as Double = 5.0 * frmMain.mapbxMain.Map.PixelSize
Dim env as Envelope = new Envelope(x - dblBuffer, x + dblBuffer, y - dblBuffer, y + dblBuffer)
Jun 3, 2015 at 2:15 PM
thanks it has worked well

also wanted to ask is my routine for getting accurate world coordinates from MouseEventArgs correct
Dim ptClick As Coordinate = SharpMap.Utilities.Transform.MapToWorld(New PointF(m.X,   m.Y), frmMain.mapbxMain.Map)
Dim dblZoom2 = 0.0001
Dim dblZoom1 = frmMain.mapbxMain.Map.Zoom
frmMain.mapbxMain.Map.Zoom = dblZoom2
ptClick = SharpMap.Utilities.Transform.MapToWorld(New PointF(m.X, m.Y),frmMain.mapbxMain.Map)  
Dim x = CDbl(ptClick.X)
Dim y = CDbl(ptClick.Y)
Coordinator
Jun 5, 2015 at 8:01 AM
You must not change the Map.Zoom value when performing MapToWorld transformations.
For ExecuteIntersectionQuery, you set up the envelope like this:
Dim env As Envelope = new Envelope(ptClick).ExpandedBy(2.5 * frmMain.mapbxMain.Map.PixelSize)
Jun 11, 2015 at 8:24 AM
thanks again FObermaier