This project is read-only.

Adding line to the same layer

Dec 27, 2011 at 7:48 AM


Iam using dotspatial for interfacing it with GPS using c#. The problem is that can i add/append the line to the same layer

instead of creating layer for every line. For example suppose i want to plot a path of a vehicle using GPS, is there any

way to append the path on the same layer??

Thanks in advance... :)

Dec 27, 2011 at 8:43 PM
Edited Dec 27, 2011 at 8:49 PM

This is small method to add a geometry in a layer

   private void AddLine(IMapLayer layer, IGeometry geometry, int id){

          IFeatureSet ifea= (IFeatureSet) layer.DataSet;

          IFeature fear = ifea.AddFeature(geometry);

           fear.DataRow["ID"] = id;



If you want to see the new feature in the map,  you should run the instruction _map.ResetBuffer();

Dec 28, 2011 at 5:04 AM


I have the exact same application and I am using the following approach:

I first create a layer for the GPS track:

        //Create GPS Track Layer
        GPSTrackFeatureSet = new FeatureSet(FeatureType.Line) { Projection = Map.Projection };
        column = new DataColumn("LineId", typeof(int));
        var gpsTrackLayer = Map.Layers.Add(GPSTrackFeatureSet);
        gpsTrackLayer.DataSet.Name = "GPSTrackLayer";
        var lineSymbol = new LineSymbolizer(Color.Green, 2);
        gpsTrackLayer.Symbolizer = lineSymbol;
        gpsTrackLayer.LegendText = "GPS Track";
        var lineArray = new List<Coordinate>();
        var lineGeometry = new LineString(lineArray);
        GPSTrackFeature = GPSTrackFeatureSet.AddFeature(lineGeometry);
        GPSTrackFeature.DataRow["LineId"] = 1;

and then I execute to following whenever the GPS position changes (the Coordinate is created from the current GPS position):

        if (GPSTrackFeature.Coordinates.Count >= 2) {

followed by map.ResetBuffer();