Symbology sample code

Jan 7, 2011 at 6:40 PM
Edited Jan 10, 2011 at 9:31 AM

2 categories + the default turn op in the legend.
All points are unfortunately on the default , so the FilterExpression or something else is wrong.

Anny help is appreciated 


private void AddPoints()
{
    // Create the featureset if one hasn't been created yet.
    if (_myPoints == null) _myPoints = new FeatureSet(FeatureType.Point);

    _myPoints.DataTable.Columns.Add("ID", typeof(int));
    _myPoints.DataTable.Columns.Add("Category", typeof(string));
    _myPoints.Projection = KnownCoordinateSystems.Geographic.World.WGS1984;

    // Assume background layers have been added, and get the current map extents.
    double xmin = map1.Extent.MinX;
    double xmax = map1.Extent.MaxX;
    double ymin = map1.Extent.MinY;
    double ymax = map1.Extent.MaxY;

    // Randomly generate 10 points that are in the map extent
    Random rnd = new Random();
    for (int i = 0; i < 10; i++)
    {
        DotSpatial.Topology.Point p = new DotSpatial.Topology.Point();
        p.X = xmin + rnd.NextDouble() * (xmax - xmin);
        p.Y = ymin + rnd.NextDouble() * (ymax - ymin);
        IFeature currentFeature = _myPoints.AddFeature(p);
        currentFeature.DataRow["ID"] = i;
        currentFeature.DataRow["Category"] = i % 2 == 0 ? "Small" : "Large";
    }

    // Add a layer to the map, and we know it is a point layer so cast it specifically.
    IMapPointLayer pointLayer = map1.Layers.Add(_myPoints) as IMapPointLayer;

    // this removes the points, som nothein to show 
        pointLayer.Symbology.ClearCategories();

    //Create small Category
    PointCategory smallSize = new PointCategory(Color.Red, DotSpatial.Symbology.PointShape.Rectangle, 5);
    smallSize.FilterExpression = "[Category] = 'Small'";
    smallSize.LegendText = "Small";
    pointLayer.Symbology.AddCategory((IPointCategory)smallSize);

    //Create large Category
    PointCategory largeSize = new PointCategory(Color.Blue, DotSpatial.Symbology.PointShape.Star, 10);
    largeSize.FilterExpression = "[Category] = 'Large'";
    largeSize.LegendText = "Large";
    pointLayer.Symbology.AddCategory((IPointCategory)largeSize);
    pointLayer.DataSet.InvalidateVertices();
}
Jan 10, 2011 at 9:31 AM

Found the problem!
Forgot to call pointLayer.DataSet.InvalidateVertices();
Sample code is now working