Error in Intersection Query for GeometryFeatureProvider

Topics: SharpMap v0.9 / v1.x
May 13, 2015 at 7:13 AM
Edited May 28, 2015 at 11:31 PM
This is a bug in Sharpmap:
Intersection query for geometryfeatureProvider not work properly: ExecuteIntersectionQuery does not use the geometries, are using his boundingbox !!
Here the code:
    'Create layer with a triangle
    Dim coord(3) As GeoAPI.Geometries.Coordinate
    coord(0) = New GeoAPI.Geometries.Coordinate(50, 100)
    coord(1) = New GeoAPI.Geometries.Coordinate(0, 0)
    coord(2) = New GeoAPI.Geometries.Coordinate(100, 0)
    coord(3) = New GeoAPI.Geometries.Coordinate(50, 100)
    Dim fdt As New SharpMap.Data.FeatureDataTable
    fdt.Columns.Add(New System.Data.DataColumn("gid", System.Type.GetType("System.UInt32")))
    fdt.Columns.Add(New System.Data.DataColumn("name", System.Type.GetType("System.String")))
    Dim fdr As SharpMap.Data.FeatureDataRow = fdt.NewRow
    fdr.ItemArray = New Object() {1, "triangle"}
    Dim gf As New NetTopologySuite.Geometries.GeometryFactory
    fdr.Geometry = gf.CreatePolygon(coord)
    fdt.AddRow(fdr)
    Dim gfp As New SharpMap.Data.Providers.GeometryFeatureProvider(fdt)
    Dim layer As New SharpMap.Layers.VectorLayer("test")
    layer.DataSource = gfp

    'TEST 1: point into the triangle  ---- > Result: 1 geometry located (GOOD)
    Dim ds1 As New SharpMap.Data.FeatureDataSet
    layer.ExecuteIntersectionQuery(New GeoAPI.Geometries.Envelope(50, 51, 50, 49), ds1)
    If ds1.Tables(0).Rows.Count > 0 Then
        MsgBox("OK", MsgBoxStyle.Exclamation, "Test 1")
    Else
        MsgBox("WRONG", MsgBoxStyle.Exclamation, "Test 1")
    End If

    'TEST 2: point outside the triangle but into his boundingbox ----> Result: 1 geometry located (WRONG)
    Dim ds2 As New SharpMap.Data.FeatureDataSet
    layer.ExecuteIntersectionQuery(New GeoAPI.Geometries.Envelope(0, 1, 100, 99), ds2)
    If ds2.Tables(0).Rows.Count > 0 Then
        MsgBox("WRONG", MsgBoxStyle.Exclamation, "Test 2")
    Else
        MsgBox("OK", MsgBoxStyle.Exclamation, "Test 2")
    End If