Example #1
0
        public void setSymbolizer()
        {
            double baseWidth        = 20.0;
            double baseOutlineWidth = 10.0;
            double adjWidth         = baseWidth;
            double adjOutlineWidth  = baseOutlineWidth;

            LineScheme rdScheme = new LineScheme();

            LineSymbolizer catSelSym = new LineSymbolizer();

            catSelSym.ScaleMode = ScaleMode.Geographic;
            catSelSym.SetWidth(adjWidth);
            catSelSym.SetOutline(Color.Blue, adjOutlineWidth);
            catSelSym.SetFillColor(Color.White);

            LineSymbolizer symDef = new LineSymbolizer();

            symDef.ScaleMode = ScaleMode.Geographic;
            symDef.SetWidth(adjWidth);
            symDef.SetOutline(Color.Black, adjOutlineWidth);
            symDef.SetFillColor(Color.Gray);

            LineCategory catDef = new LineCategory();

            catDef.LegendText = "No RSL Info";

            catDef.SelectionSymbolizer = catSelSym;
            catDef.Symbolizer          = symDef;
            rdScheme.AddCategory(catDef);

            int[] r = new int[30];
            int[] g = new int[30];
            int[] b = new int[30];

            if (Project.settings.GetValue("road_colors").Contains("t"))
            {
                if (moduleRoads.roadColors == "RSL")
                {
                    for (int rsl = 0; rsl <= 20; rsl++)
                    {
                        // create a category
                        LineCategory colorCat = new LineCategory();
                        colorCat.FilterExpression = "[TAMSROADRSL] = '" + rsl.ToString() + "'";

                        LineSymbolizer colorSym = new LineSymbolizer();
                        colorSym.ScaleMode = ScaleMode.Geographic;
                        colorSym.SetWidth(adjWidth);
                        colorSym.SetOutline(Color.DarkGray, adjOutlineWidth);

                        Color fillColor = Color.Gray;
                        if (rsl == 20 || rsl == 19)
                        {
                            fillColor = Color.Blue;
                        }
                        if (rsl <= 18 && rsl >= 16)
                        {
                            fillColor = Color.DeepSkyBlue;
                        }
                        if (rsl <= 15 && rsl >= 13)
                        {
                            fillColor = Color.Green;
                        }
                        if (rsl <= 12 && rsl >= 10)
                        {
                            fillColor = Color.LimeGreen;
                        }
                        if (rsl <= 9 && rsl >= 7)
                        {
                            fillColor = Color.Yellow;
                        }
                        if (rsl <= 6 && rsl >= 4)
                        {
                            fillColor = Color.Orange;
                        }
                        if (rsl <= 3 && rsl >= 1)
                        {
                            fillColor = Color.Red;
                        }
                        if (rsl == 0)
                        {
                            fillColor = Color.DarkRed;
                        }

                        if (selectedColors[fillColor])
                        {
                            colorSym.SetFillColor(fillColor);
                        }
                        else
                        {
                            continue;
                        }

                        colorCat.Symbolizer = colorSym;

                        // assign (default) selection symbolizer
                        colorCat.SelectionSymbolizer = catSelSym;

                        // done
                        rdScheme.AddCategory(colorCat);
                    }
                }

                if (moduleRoads.roadColors == "Treatment")
                {
                    DataTable nameToTreatment = Database.GetDataByQuery(Project.conn, "SELECT name, category FROM treatments;");
                    string[]  treatments      = new string[30];
                    int       j = 0;
                    foreach (DataRow row in nameToTreatment.Rows)
                    {
                        treatments[j] = row["name"].ToString();
                        if (row["category"].ToString() == "routine")
                        {
                            r[j] = 0;
                        }
                        g[j] = 0; b[j] = 255;
                        if (row["category"].ToString() == "patch")
                        {
                            r[j] = 50;
                        }
                        g[j] = 205; b[j] = 50;
                        if (row["category"].ToString() == "preventative")
                        {
                            r[j] = 255;
                        }
                        g[j] = 255; b[j] = 0;
                        if (row["category"].ToString() == "rehabilitation")
                        {
                            r[j] = 255;
                        }
                        g[j] = 0; b[j] = 0;
                        if (row["category"].ToString() == "reconstruction")
                        {
                            r[j] = 139;
                        }
                        g[j] = 0; b[j] = 0;
                        j++;
                    }
                    treatments[24] = "Routine"; r[24] = 0; g[24] = 0; b[24] = 255;
                    treatments[25] = "Patching"; r[25] = 50; g[25] = 205; b[25] = 50;
                    treatments[26] = "Preventative"; r[26] = 255; g[26] = 255; b[26] = 0;
                    treatments[27] = "Preventative with Patching"; r[27] = 255; g[27] = 165; b[27] = 0;
                    treatments[28] = "Rehabilitation"; r[28] = 255; g[28] = 0; b[28] = 0;
                    treatments[29] = "Reconstruction"; r[29] = 139; g[29] = 0; b[29] = 0;

                    for (int i = 0; i < treatments.Length; i++)
                    {
                        // TODO: Get this to work
                        Color fillColor = Color.Gray;
                        if (r[i] == 0 && g[i] == 0 && b[i] == 255)
                        {
                            fillColor = Color.Blue;
                        }
                        if (r[i] == 50 && g[i] == 205 && b[i] == 50)
                        {
                            fillColor = Color.LimeGreen;
                        }
                        if (r[i] == 255 && g[i] == 255 && b[i] == 0)
                        {
                            fillColor = Color.Yellow;
                        }
                        if (r[i] == 255 && g[i] == 165 && b[i] == 0)
                        {
                            fillColor = Color.Orange;
                        }
                        if (r[i] == 255 && g[i] == 0 && b[i] == 0)
                        {
                            fillColor = Color.Red;
                        }
                        if (r[i] == 139 && g[i] == 0 && b[i] == 0)
                        {
                            fillColor = Color.DarkRed;
                        }
                        if (!selectedColors[fillColor])
                        {
                            continue;
                        }

                        LineCategory colorCat = new LineCategory();
                        colorCat.FilterExpression = "[TAMSTREATMENT] = '" + treatments[i] + "'";

                        LineSymbolizer colorSym = new LineSymbolizer();
                        colorSym.ScaleMode = ScaleMode.Geographic;
                        colorSym.SetWidth(adjWidth);
                        colorSym.SetOutline(Color.DarkGray, adjOutlineWidth);
                        colorSym.SetFillColor(Color.FromArgb(r[i], g[i], b[i]));

                        colorCat.Symbolizer = colorSym;

                        // assign (default) selection symbolizer
                        colorCat.SelectionSymbolizer = catSelSym;

                        // done
                        rdScheme.AddCategory(colorCat);
                    }
                }
            }
            ((MapLineLayer)moduleRoads.Layer).ShowLabels = false;

            FeatureLayer roadFeatures = moduleRoads.Layer as FeatureLayer;

            if (!string.IsNullOrEmpty(Project.settings.GetValue("road_labels")))
            {
                string streetnames = "[" + Project.settings.GetValue(ModuleName + "_f_streetname") + "]";
                roadFeatures.AddLabels(streetnames, new Font("Tahoma", (float)8.0), moduleRoads.labelColor);
                roadFeatures.ShowLabels = Project.settings.GetValue("road_labels").Contains("true");
            }

            ((MapLineLayer)moduleRoads.Layer).Symbology = rdScheme;
            ((MapLineLayer)moduleRoads.Layer).ApplyScheme(rdScheme);
        }
Example #2
0
        private void SymbolizerLines(IMapFeatureLayer aLayer)
        {
            //Method 1. simple symbolizer
            aLayer.Symbolizer = new LineSymbolizer(Color.Brown, 1);

            //Method 2. Combined symbolizer
            LineSymbolizer road = new LineSymbolizer(Color.Yellow, 5);

            road.SetOutline(Color.Black, 1);
            aLayer.Symbolizer = road;

            /* Method 3. Symbology by unique values:
             * HueSatLight = true, then the ramp is created by adjusting the
             * hue, saturation and lightness between the start and end colors.
             * HueSatLight = false, then the red, blue and green values are ramped instead.
             *
             * In both cases, alpha (transparency) is ramped the same way.
             */
            LineScheme lScheme = new LineScheme();

            lScheme.EditorSettings.ClassificationType = ClassificationType.UniqueValues;
            lScheme.EditorSettings.FieldName          = "CARTO";
            lScheme.CreateCategories(aLayer.DataSet.DataTable);
            aLayer.Symbology = lScheme;

            //Method 4. Collapsible field name in legend via 'AppearsInLegend'
            LineScheme lScheme1 = new LineScheme();

            lScheme1.Categories.Clear(); //redundant???
            LineCategory lowCat = new LineCategory(Color.Blue, 2);

            lowCat.FilterExpression = "[CARTO] = 3";
            lowCat.LegendText       = "Low";
            LineCategory highCat = new LineCategory(
                Color.Red,
                Color.Black,
                6,
                DashStyle.Solid,
                LineCap.Triangle);;

            highCat.FilterExpression = "[CARTO] = 2";
            highCat.LegendText       = "High";
            lScheme1.AppearsInLegend = true;
            lScheme1.LegendText      = "CARTO";
            lScheme1.Categories.Add(lowCat);
            aLayer.Symbology = lScheme1;
            lScheme1.Categories.Add(highCat);

            /*Method 5. Lines with multiple strokes
             * Each individual LineSymbolizer is made up of at least one,
             * but potentially several strokes overlapping each other
             */
            LineSymbolizer multiStrokeSym = new LineSymbolizer();

            multiStrokeSym.Strokes.Clear(); //redundant???
            CartographicStroke ties = new CartographicStroke(Color.Brown);

            ties.DashPattern = new float[] { 1 / 6f, 2 / 6f };
            ties.Width       = 6;
            ties.EndCap      = LineCap.Flat;
            ties.StartCap    = LineCap.Flat;
            CartographicStroke rails = new CartographicStroke(Color.DarkGray);

            rails.CompoundArray = new float[] { .15f, .3f, .6f, .75f };
            rails.Width         = 6;
            rails.EndCap        = LineCap.Flat;
            rails.StartCap      = LineCap.Flat;
            multiStrokeSym.Strokes.Add(ties);
            multiStrokeSym.Strokes.Add(rails);
            aLayer.Symbolizer = multiStrokeSym;
        }