This project is read-only.

Changing symbols on MapPointLayer

Apr 23, 2012 at 11:58 PM

I have the following layer:

            vesselsDataTable = new AISDataSet.Message1DataTable();
            vesselsFeatureSet = new FeatureSet(FeatureType.Point);
            vesselsFeatureSet.Projection = KnownCoordinateSystems.Projected.World.WebMercator;
            vesselsFeatureSet.DataTable = vesselsDataTable;

I want to create PointCategories in order to have diffent symbols for the features that belong this layer. For this reasons I have created the following functions:

        private PointSymbolizer getPointSymbolizer(Color symbolColor, DotSpatial.Symbology.PointShape symbolShape, double symbolSize)
        {
            IList<ISymbol> symbolsList = new CopyList<ISymbol>();
            ISimpleSymbol symbol = new SimpleSymbol(symbolColor, symbolShape, symbolSize) { UseOutline = true, OutlineColor = Color.Black };
            symbolsList.Add(symbol);
            PointSymbolizer pointSymbolizer = new PointSymbolizer()
            {
                Smoothing = true,
                Symbols = symbolsList
            };

            return pointSymbolizer;
        }

        private IPointCategory getPointCategory(PointSymbolizer pointSymbolizer, string filterExpression, string legendText)
        {
            return new PointCategory(pointSymbolizer)
            {
                FilterExpression = filterExpression,
                LegendText = legendText
            };
        }

I use use these function to create categories that I add to my feature layer that change the symbol depending to the NavigationalStatus property of every feature:

            PointSymbolizer vesselsSymbolizerUnderWay = getPointSymbolizer(Color.LightGray, Symbology.PointShape.Triangle, 8);
            IPointCategory vesselsUnderWayCategory = getPointCategory(vesselsSymbolizerUnderWay, "[NavigationalStatus] = 0", "Under Way");

            PointSymbolizer vesselsSymbolizerAtAnchor = getPointSymbolizer(Color.LightPink, Symbology.PointShape.Rectangle, 8);
            IPointCategory vesselsAtAnchorCategory = getPointCategory(vesselsSymbolizerAtAnchor, "[NavigationalStatus] >= 1", "At Anchor");

            vesselsLayer = new MapPointLayer(vesselsFeatureSet);
            vesselsLayer.LegendText = "Vessels";

            vesselsLayer.Symbology.Categories.Clear();
            vesselsLayer.Symbology.Categories.Add(vesselsUnderWayCategory);
            vesselsLayer.Symbology.Categories.Add(vesselsAtAnchorCategory);
            vesselsLayer.ApplyScheme(vesselsLayer.Symbology);
            vesselsLayer.DataSet.InvalidateVertices();

Allthough the code does not produce any errors, all the features in the layer, have the same symbol; If I change the order that the categories are added, the features' symbol is always from the first category added. It looks like the FilterExpression property in each category is not used!

Does any one have any pointers on this?

 

Thanks,
George J.

Apr 27, 2012 at 12:22 AM

Hi, they asked me to check on this for you, but I have been out of the loop for some time here so you'll have to forgive me if it takes a minute to get back into the swing of things.

So before we get into anything too technical like actually running tests or whatever, let me ask if you know for sure that the [NavigationalStatus] field is actually a number field of some kind and not a string field.  If the field type were string, then the criteria might even still work, but would need to look like [NavigationalStatus] = '0' or whatever.

Secondly, your method for getPointSymbolizer seems like it might be handled using the constructor?

PointSymbolizer p = new PointSymbolizer(...);

It doesn't sound like that's a problem though since when you swap the order, you can change the symbol.  That implies that it's just the filter that doesn't work correctly.  Check the data type and if that isn't it maybe I can run a test or something.

 

Ted

 

 

Apr 28, 2012 at 1:42 AM

Hi,

The [NavigationalStatus] attribute exists and its type is UInt32. Changing my filter to "[NavigationalStatus] = '0'" doesn't make any diferrence.

You can find my code in http://sharpais.codeplex.com/SourceControl/changeset/changes/68905 - it a working progress, but you can run it, and make any test you like.

Today for some reason, the labels from the features have disappeared... Only the first feature, the one inserted into featuresset while the forming was loading, has a label...

 

Regards,
George J.

May 6, 2012 at 8:49 AM

Hi Ted,

I have made several changes to my code - I have implemented a DotSpatial plug-in providing the same functionality. The categories seem to work now.

Although, layer labeling does not work as expected. Invalidating the map does not create labels for the new features.

 

George J.