FeatureSet behaving different to Shape File on Map

Sep 25, 2012 at 3:45 AM

I have a feature set that I create at runtime that is then added to a layer on a map. This all works fine, but when I use the "select" function mode on the map to select the layer features, the features remain selected even when I click on another feature. Once selected I have to deselect the features using the mouse +ctrl and then call the map.refresh() method.

However, if I save the same featureset to a shape file and then load the shape file onto the map the selection process works as intended. I click on a layer feature and any other features previously selected become deselected. As I cannot guarantee that users will have write access, saving to an external file first is not an option.

My code is shown below. If I uncomment the two comments below I get the result I need, but I don't think users of my application will have permission to save the shape file at that location.


    Public Sub createBTLayer()
        Dim f As New DotSpatial.Data.Feature()
        Dim fs As New DotSpatial.Data.FeatureSet(DotSpatial.Topology.FeatureType.Point)
        Dim layerName As String = "BT"
        fs.Name = layerName
        fs.DataTable.Columns.Add(New DataColumn("ID", GetType(Int16)))
        fs.DataTable.Columns.Add(New DataColumn("MapName", GetType(String)))
        fs.DataTable.Columns.Add(New DataColumn("Name", GetType(String)))
        fs.DataTable.Columns.Add(New DataColumn("FirstRec", GetType(String)))
        fs.DataTable.Columns.Add(New DataColumn("LastRec", GetType(String)))

        Dim siteDates As List(Of String) = getListOfString("SELECT btsiteid, MIN(timeindex), MAX(timeindex) from tblBTrecords GROUP BY btsiteid", 3)
        For Each aSite In siteDates
            Dim timeCols = aSite.Split(",")
            Dim siteCols = getListOfString("SELECT mapname, name, x, y FROM tblBTsites WHERE btsiteid=" & timeCols(0), 4)(0).Split(",")
            Dim coord As DotSpatial.Topology.Coordinate = New DotSpatial.Topology.Coordinate
            coord = New DotSpatial.Topology.Coordinate(Integer.Parse(siteCols(2)), Integer.Parse(siteCols(3)))
            Dim pt As New DotSpatial.Topology.Point(coord)
            f = New DotSpatial.Data.Feature(pt)
            Dim feature = fs.AddFeature(f)
            feature.DataRow(0) = Int16.Parse(timeCols(0))
            feature.DataRow(1) = siteCols(0)
            feature.DataRow(2) = siteCols(1)
            feature.DataRow(3) = convertFromUnixTime(Integer.Parse(timeCols(1))).ToString
            feature.DataRow(4) = convertFromUnixTime(Integer.Parse(timeCols(2))).ToString
        fs.Projection = Map.Projection
        'fs.SaveAs(Application.StartupPath & "\BT.shp", True)

        'fs = FeatureSet.Open(Application.StartupPath & "\BT.shp")
        Dim lyr = Map.Layers.Add(fs)
        With lyr
            .LegendText = "BT"
            .SelectionEnabled = True
            .LegendItemVisible = False
            .Symbolizer = New PointSymbolizer(Color.SteelBlue, Symbology.PointShape.Star, 15)
            .SelectionSymbolizer = New PointSymbolizer(Color.LightBlue, Symbology.PointShape.Star, 20)
        End With
        Dim labelSymbol As New LabelSymbolizer
        With labelSymbol
            .FontSize = 12
            .FontFamily = "Tahoma"
            .FontColor = Color.SteelBlue
            .OffsetX = 30
            .OffsetY = 30
            .PreventCollisions = True
        End With
        Map.AddLabels(lyr, "[MapName]", "[ID] >0", labelSymbol, 7500)
        lyr = m_map.Layers.Add(fs)