This project is read-only.

Change the color of a line without rebuild the FeatureSet

Feb 19, 2014 at 9:49 AM
Edited Feb 24, 2014 at 4:15 PM
Hello

I have a featureset containing several thousands of feature lines(>20000). I am able using ILineLayer, LineScheme, LineSymbolizer, LineCategory to plot all my lines with a specific color.

I have to refresh quit often the map (about every 10 / 20 seconds), where with refreshing I mean change a color of some feature lines (let say 10 or 20 out of the 20000). Is there a way to speed up the refreshing without rebuilding the featureset?

This is my sub:
    /// <summary>
    /// Load all the segments with a specific size
    /// </summary>
    /// <param name="parLineSize">widht of the segments</param>
    /// <param name="parDataTable">datatable of segments</param>
    private void LoadSegments(int parLineSize, System.Data.DataTable parDataTable)
    {
        double tFromLat;
        double tFromLon;
        double tToLat;
        double tToLon;

        int tRowIndex;

        //declare some objects
        if (this.pMyFeatureSet != null)
        {
            this.pMyFeatureSet = null;
        }

        this.pMyFeatureSet = new FeatureSet();

        foreach (DataColumn Col in tDataTable.Columns)
        {
            this.pMyFeatureSet.DataTable.Columns.Add(new DataColumn(Col.ColumnName, Col.DataType));
        }


        // loop through the temporary datatable and load in the features and attributes
        tRowIndex = 0;
        foreach (DiViewMockuop.DiView.DrawingPoint tDP in this.pDrawingPoints)
        {
            // extract the data from the datatable
            tFromLat = tDP.StartPosX;
            tFromLon = tDP.StartPosY;
            tToLat = tDP.EndPosX;
            tToLon = tDP.EndPosY;

            Coordinate[] coord = new Coordinate[2];
            coord[0] = new Coordinate(tFromLat, tFromLon);
            coord[1] = new Coordinate(tToLat, tToLon);
            LineString ls = new LineString(coord);
            this.pMyFeatureSet.AddFeature(new Feature(FeatureType.Line, coord));

            // now update the feature's row with attributes
            for (int ColumnIndex = 0; ColumnIndex < tDataTable.Columns.Count; ColumnIndex++)
            {
                this.pMyFeatureSet.DataTable.Rows[tRowIndex][ColumnIndex] = tDataTable.Rows[tRowIndex][ColumnIndex];
            }
            tRowIndex++;
        }

        if (this.pDrawingPoints.Count > 0)
        {
            this.pMyFeatureSet.Projection = this.uxMap.Projection;
            ILineLayer myLineLayer = this.uxMap.Layers.Add(this.pMyFeatureSet) as ILineLayer;

            myLineLayer.LegendText = "RealSensor";

            DotSpatial.Controls.IMapLineLayer linkLayer;
            linkLayer = (DotSpatial.Controls.IMapLineLayer)myLineLayer;

            #region Create scale of colors for the polyline
            LineScheme linkScheme;
            linkScheme = new LineScheme();
            linkScheme.ClearCategories();
            linkScheme.EditorSettings.ClassificationType = ClassificationType.UniqueValues;
            linkScheme.EditorSettings.FieldName = "TypeOfLine";
            linkScheme.CreateCategories(linkLayer.DataSet.DataTable);
            linkScheme.ClearCategories();
            linkScheme.LegendText = "LINKS";

            LineSymbolizer pGray = new LineSymbolizer(Color.Gray, parLineSize);
            pGray.ScaleMode = ScaleMode.Simple;
            LineCategory myGray = new LineCategory(pGray);
            myGray.FilterExpression = "[TypeOfLine] = 0";
            myGray.LegendText = "Gray";

            LineSymbolizer pGreen = new LineSymbolizer(Color.LimeGreen, parLineSize);
            pGreen.ScaleMode = ScaleMode.Simple;
            LineCategory myGreen = new LineCategory(pGreen);
            myGreen.FilterExpression = "[TypeOfLine] = 1";
            myGreen.LegendText = "Green";

            LineSymbolizer pRed = new LineSymbolizer(Color.Red, parLineSize);
            pGreen.ScaleMode = ScaleMode.Simple;
            LineCategory myRed = new LineCategory(pRed);
            myRed.FilterExpression = "[TypeOfLine] = 2";
            myRed.LegendText = "Red";


            LineSymbolizer pYellow = new LineSymbolizer(Color.Yellow, parLineSize);
            pGreen.ScaleMode = ScaleMode.Simple;
            LineCategory myYellow = new LineCategory(pYellow);
            myYellow.FilterExpression = "[TypeOfLine] = 3";
            myYellow.LegendText = "Yellow";

            LineSymbolizer pBlue = new LineSymbolizer(Color.Blue, parLineSize);
            pBlue.ScaleMode = ScaleMode.Simple;
            LineCategory myBlue = new LineCategory(pBlue);
            myBlue.FilterExpression = "[TypeOfLine] = 4";
            myBlue.LegendText = "Blue";

            linkScheme.AddCategory(myGray);
            linkScheme.AddCategory(myGreen);
            linkScheme.AddCategory(myRed);
            linkScheme.AddCategory(myYellow);
            linkScheme.AddCategory(myBlue);
            linkLayer.Symbology = linkScheme;
            #endregion
        }
    }
I would like to change the color of some "segments" for example from green to red without redraw everything.

Thank you in advance for the support

Daniele