This project is read-only.

EditMode and refresh

Aug 12, 2014 at 9:42 PM
I'm creating a point FeatureSet entirely in memory. Symbology is created that varies based on an attribute and then for a series of times, the feature attribute values are changed in the FeatureSet. I would expect the symbols to update upon calling IMapFeatureLayer.AssignFastDrawnStates() and then IMap.MapFrame.Invalidate but nothing happens unless I recreate the symbology (which is inefficient way of doing things). Setting EditMode to false after creating the FeatureSet seems to fix this but the symbols are drawn funny in this case. My question is: how can I get the map to update the symbology when I change the attributes in a FeatureSet?

Here is the basic workflow of the code:
      this.featureSetInflow = new FeatureSet(DotSpatial.Topology.FeatureType.Point);
      this.featureSet = new FeatureSet(DotSpatial.Topology.FeatureType.Polygon);
      this.featureSet.Projection = DotSpatial.Projections.KnownCoordinateSystems.Projected.StatePlaneNad1927.NAD1927StatePlaneIllinoisEastFIPS1201;
      this.featureSetInflow.Projection = this.featureSet.Projection;

      // Create columns
      DataColumn valCol = new DataColumn("Val", typeof(double));
      valCol.ReadOnly = false;
      this.featureSetInflow.DataTable.Columns.Add(valCol);

      // Add to map
      this.mapLayerInflow = this.map1.Layers.Add(this.featureSetInflow);
      //this.mapLayerInflow.EditMode = false;
      this.mapLayerInflow.Symbolizer = new DotSpatial.Symbology.PointSymbolizer(MakeSymbol(this.animMinSize));

      this.map1.Refresh();
Animation code:
    // Initial call
    public void Reset()
    {
      this.BeginInvoke((MethodInvoker)
        delegate
        {
          SetInflowSymbology();
          this.map1.Refresh();
    }

    // Every time step
    public void SetResultsPosition(int pos)
    {
      var inflows = this.geom.GetInflows();

      //this.animMaxVal = 500;
      //this.animMaxSize = 30;
      //this.animMinSize = 10;

      int c = 0;
      foreach (var feat in this.featureSetInflow.Features)
      {
        if (inflows[c].FlowTs == null)
          continue;

        double flow = inflows[c++].FlowTs.LookupValueAtTime(pos * 3600);
        int size = (int)(flow / this.animMaxVal * (double)(this.animMaxSize - this.animMinSize)) + this.animMinSize;
        feat.DataRow["Val"] = size;
      }

      // If I do this, the symbology is updated with EditMode = true
      //SetInflowSymbology();

      this.BeginInvoke((MethodInvoker)
        delegate
        {
          this.mapLayerInflow.AssignFastDrawnStates();
          this.map1.MapFrame.Invalidate();
        });
    }
Subroutines used:
    private SimpleSymbol MakeSymbol(int size)
    {
      var s = new DotSpatial.Symbology.SimpleSymbol();
      s.PointShape = DotSpatial.Symbology.PointShape.Ellipse;
      s.SetColor(Color.Orange);
      s.OutlineColor = Color.Black;
      s.OutlineWidth = 0.5;
      s.UseOutline = true;
      s.Size = new DotSpatial.Symbology.Size2D(size, size);
      return s;
    }

    public bool SetInflowSymbology()
    {
      this.mapLayerInflow.Symbology.ClearCategories();
      var S = new PointScheme();
      S.EditorSettings.TemplateSymbolizer = new DotSpatial.Symbology.PointSymbolizer(MakeSymbol(this.animMinSize));
      for (int i = this.animMinSize; i <= this.animMaxSize; i++)
      {
        var pc = new PointCategory(MakeSymbol(i));
        pc.FilterExpression = "[Val] = " + i.ToString();
        S.AddCategory(pc);
      }
      this.mapLayerInflow.Symbology = S;
      return true;
    }
Aug 20, 2014 at 7:15 AM
I think you may have to apply one or more of the following:

MapLayer.DataSet.InitializeVertices();
MapLayer.AssignFastDrawnStates();
MapLayer.DataSet.UpdateExtent();
MapLayer.DataSet.InvalidateVertices();

I have a similar issue with symbols not displaying correctly when EditMode is set to False. Unfortunately when EditMode is set to True then your selection does not get highlighted. I don't have a solution for that one!

Rob :)