Exemplo n.º 1
0
        public void GetFillColor()
        {
            var theme = new CategorialTheme();
            var themeItem = new CategorialThemeItem {Style = new VectorStyle {Fill = new SolidBrush(Color.Red)}, Value = 1.0};
            theme.ThemeItems = new EventedList<IThemeItem>(new[] { themeItem });

            const int valueAsInt = 1;
            const float valueAsFloat = 1.0f;

            Assert.AreEqual(Color.Transparent, theme.GetFillColor(0.5));
            Assert.AreEqual(Color.Red, theme.GetFillColor(1.0));
            Assert.AreEqual(Color.Red, theme.GetFillColor(valueAsInt));
            Assert.AreEqual(Color.Red, theme.GetFillColor(valueAsFloat));
            Assert.AreEqual(Color.Red, theme.GetFillColor(new ConvertableObject()));
            Assert.AreEqual(Color.Transparent, theme.GetFillColor(1.5));
            Assert.AreEqual(Color.Transparent, theme.GetFillColor(new ComparableObject()));

            theme.ThemeItems = new EventedList<IThemeItem>();
            Assert.AreEqual(Color.Transparent, theme.GetFillColor(0.5));
            Assert.AreEqual(Color.Transparent, theme.GetFillColor(1.0));
            Assert.AreEqual(Color.Transparent, theme.GetFillColor(valueAsInt));
            Assert.AreEqual(Color.Transparent, theme.GetFillColor(valueAsFloat));
            Assert.AreEqual(Color.Transparent, theme.GetFillColor(new ConvertableObject()));
            Assert.AreEqual(Color.Transparent, theme.GetFillColor(1.5));
            Assert.AreEqual(Color.Transparent, theme.GetFillColor(new ComparableObject()));
        }
Exemplo n.º 2
0
        private static ITheme CreateCategorialTheme(Legend legend, Ranges <int> ranges)
        {
            int numberOfClasses = ranges.ranges.Count; //legend.ranges.Count;

            Color[]            colors       = new Color[numberOfClasses];
            float[]            positions    = new float[numberOfClasses];
            List <IComparable> values       = new List <IComparable>();
            string             attribute    = legend.columnName;
            VectorStyle        defaultStyle = null;
            List <string>      categories   = new List <string>();

            int i = 0;

            foreach (Range <int> range in ranges.ranges)
            {
                categories.Add(range.description);
                colors[i]    = range.color;
                positions[i] = ((float)i) / (numberOfClasses - 1);
                values.Add(range.intMaxValue);
                i++;
            }
            ColorBlend      blend = new ColorBlend(colors, positions);
            CategorialTheme theme = ThemeFactory.CreateCategorialTheme(attribute, defaultStyle, blend, numberOfClasses,
                                                                       values, categories);

            return(theme);
        }
Exemplo n.º 3
0
        public void GetFillColor()
        {
            var theme     = new CategorialTheme();
            var themeItem = new CategorialThemeItem {
                Style = new VectorStyle {
                    Fill = new SolidBrush(Color.Red)
                }, Value = 1.0
            };

            theme.ThemeItems = new EventedList <IThemeItem>(new[] { themeItem });

            const int   valueAsInt   = 1;
            const float valueAsFloat = 1.0f;

            Assert.AreEqual(Color.Transparent, theme.GetFillColor(0.5));
            Assert.AreEqual(Color.Red, theme.GetFillColor(1.0));
            Assert.AreEqual(Color.Red, theme.GetFillColor(valueAsInt));
            Assert.AreEqual(Color.Red, theme.GetFillColor(valueAsFloat));
            Assert.AreEqual(Color.Red, theme.GetFillColor(new ConvertableObject()));
            Assert.AreEqual(Color.Transparent, theme.GetFillColor(1.5));
            Assert.AreEqual(Color.Transparent, theme.GetFillColor(new ComparableObject()));

            theme.ThemeItems = new EventedList <IThemeItem>();
            Assert.AreEqual(Color.Transparent, theme.GetFillColor(0.5));
            Assert.AreEqual(Color.Transparent, theme.GetFillColor(1.0));
            Assert.AreEqual(Color.Transparent, theme.GetFillColor(valueAsInt));
            Assert.AreEqual(Color.Transparent, theme.GetFillColor(valueAsFloat));
            Assert.AreEqual(Color.Transparent, theme.GetFillColor(new ConvertableObject()));
            Assert.AreEqual(Color.Transparent, theme.GetFillColor(1.5));
            Assert.AreEqual(Color.Transparent, theme.GetFillColor(new ComparableObject()));
        }
Exemplo n.º 4
0
        private static themeCategory GetThemeCategorial(CategorialTheme theme)
        {
            var themeCategory = new themeCategory
            {
                columnName   = theme.AttributeName,
                defaultStyle = GetDefaultStyle(theme)
            };

            var catThemeItems = new List <themeItem>();

            foreach (var item in theme.ThemeItems)
            {
                // Add theme items (style and label) to the CategorialTheme
                var catThemeItem = new themeItem
                {
                    label = item.Label,
                    style = GetStyle(item)
                };

                catThemeItems.Add(catThemeItem);
            }

            themeCategory.categoryThemeItems = catThemeItems.ToArray();
            return(themeCategory);
        }
Exemplo n.º 5
0
        private static CategorialTheme GetCategorialTheme(theme theme)
        {
            var themeCategory = (themeCategory)theme.Item;
            var defaultStyle  = GetDefaultStyle(theme);

            var categorialTheme = new CategorialTheme(themeCategory.columnName, defaultStyle);

            foreach (themeItem catThemeItem in themeCategory.categoryThemeItems)
            {
                var categorialThemeItem = new CategorialThemeItem(catThemeItem.label, GetStyle(catThemeItem), null);
                categorialTheme.AddThemeItem(categorialThemeItem);
            }

            return(categorialTheme);
        }
Exemplo n.º 6
0
        public static CategorialTheme CreateCategorialTheme(string attribute, VectorStyle defaultStyle, ColorBlend blend, 
            int numberOfClasses, IList<IComparable> values, List<string> categories, int sizeMin, int sizeMax)
        {
            if (defaultStyle == null)
            {
                defaultStyle = new VectorStyle
                                   {
                                       GeometryType = typeof (IPolygon)
                                   };
            }

            var categorialTheme = new CategorialTheme(attribute, defaultStyle);

            for (int i = 0; i < numberOfClasses; i++)
            {
                string label = (categories != null)
                                   ? categories[i]
                                   : values[i].ToString();

                Color color = (numberOfClasses > 1)
                                  ? blend.GetColor((float) i/(numberOfClasses - 1))
                                  : ((SolidBrush) defaultStyle.Fill).Color;
                
                var vectorStyle = (VectorStyle) defaultStyle.Clone();

                var size = sizeMin + (sizeMax - sizeMin)*i/(float) numberOfClasses;

                if (defaultStyle.GeometryType == typeof(IPoint))
                {
                    vectorStyle.Fill = new SolidBrush(color);
                    vectorStyle.Line.Width = 16;
                    vectorStyle.Shape = defaultStyle.Shape;
                }
                else if ((defaultStyle.GeometryType == typeof(IPolygon)) || (defaultStyle.GeometryType == typeof(IMultiPolygon)))
                {
                    vectorStyle.Fill = new SolidBrush(color);
                }
                else if ((defaultStyle.GeometryType == typeof(ILineString)) || (defaultStyle.GeometryType == typeof(IMultiLineString)))
                {
                    vectorStyle.Line = CreatePen(color, size, defaultStyle.Line);
                }
                else
                {
                    vectorStyle.Fill = new SolidBrush(color);
                }

                CategorialThemeItem categorialThemeItem = (values[i] != null)
                                                              ? new CategorialThemeItem(label, vectorStyle, vectorStyle.LegendSymbol, values[i])
                                                              : new CategorialThemeItem(label, vectorStyle, vectorStyle.LegendSymbol);

                
                categorialTheme.AddThemeItem(categorialThemeItem);
            }

            return categorialTheme;
        }
Exemplo n.º 7
0
        private void AddQuadTreeEnvelopes(QTNode node, IMap map)
        {
            if (node.indexList != null)
            {
                //log.Debug(node.Bounds + ": " + string.Join(", ", node.indexList));

                var i = 0;
                foreach (var bound in node.boundsList)
                {
                    var id = node.indexList[i];

                    if (quadTreeEnvelopesLayer == null)
                    {
                        var featureCollection = new FeatureCollection {
                            Features = new List <Feature> {
                            }
                        };
                        quadTreeEnvelopesLayer = new VectorLayer
                        {
                            DataSource = featureCollection,
                            Style      = { Fill = Brushes.Transparent, Outline = { Width = 1, Color = Color.DarkGreen } },

                            Name       = Name + " quad tree, level: " + node.Level,
                            Selectable = false,
                            //UseQuadTree = true
                        };

                        var theme = new CategorialTheme("IsSelected", null);
                        theme.AddThemeItem(new CategorialThemeItem("true", new VectorStyle {
                            Fill = Brushes.Transparent, Outline = { Width = 3, Color = Color.FromArgb(200, 200, 100, 100) }
                        }, null));
                        theme.AddThemeItem(new CategorialThemeItem("false", new VectorStyle {
                            Fill = Brushes.Transparent, Outline = { Width = 3, Color = Color.FromArgb(50, 100, 200, 100) }
                        }, null));
                        quadTreeEnvelopesLayer.Theme = theme;

                        map.Layers.Insert(0, quadTreeEnvelopesLayer);
                        map.BringToFront(quadTreeEnvelopesLayer);
                    }

                    //if (!quadTreeEnvelopesLayer.DataSource.Features.Cast<IFeature>().Any(f => f.Attributes["ID"].Equals(id)))
                    {
                        var feature = new Feature {
                            Geometry = geometryFactory.ToGeometry(new Envelope(bound.X, bound.X + bound.Width, bound.Y, bound.Y + bound.Height))
                        };
                        feature.Attributes = new DictionaryFeatureAttributeCollection();
                        feature.Attributes["IsSelected"] = "false";
                        feature.Attributes["ID"]         = id;

                        quadTreeEnvelopesLayer.DataSource.Features.Add(feature);
                    }

                    i++;
                }
            }

            if (node.Children != null)
            {
                AddQuadTreeEnvelopes(node.Children[0], map);
                AddQuadTreeEnvelopes(node.Children[1], map);
                AddQuadTreeEnvelopes(node.Children[2], map);
                AddQuadTreeEnvelopes(node.Children[3], map);
            }
        }
Exemplo n.º 8
0
        private static themeCategory GetThemeCategorial(CategorialTheme theme)
        {
            var themeCategory = new themeCategory
                                    {
                                        columnName = theme.AttributeName,
                                        defaultStyle = GetDefaultStyle(theme)
                                    };

            var catThemeItems = new List<themeItem>();

            foreach (var item in theme.ThemeItems)
            {
                // Add theme items (style and label) to the CategorialTheme
                var catThemeItem = new themeItem
                                       {
                                           label = item.Label, 
                                           style = GetStyle(item)
                                       };

                catThemeItems.Add(catThemeItem);
            }

            themeCategory.categoryThemeItems = catThemeItems.ToArray();
            return themeCategory;
        }
Exemplo n.º 9
0
        private static CategorialTheme GetCategorialTheme(theme theme)
        {
            var themeCategory = (themeCategory)theme.Item;
            var defaultStyle = GetDefaultStyle(theme);
            
            var categorialTheme = new CategorialTheme(themeCategory.columnName, defaultStyle);

            foreach (themeItem catThemeItem in themeCategory.categoryThemeItems)
            {
                var categorialThemeItem = new CategorialThemeItem(catThemeItem.label, GetStyle(catThemeItem), null);
                categorialTheme.AddThemeItem(categorialThemeItem);
            }

            return categorialTheme;
        }