Exemplo n.º 1
0
        private void menu_Click(object sender, EventArgs e)
        {
            FormContour Frm = new FormContour();

            Frm.layers = App.Map.GetRasterLayers();

            if (Frm.layers.GetLength(0) <= 0)
            {
                MessageBox.Show("No raster layer found!");
                return;
            }

            if (Frm.ShowDialog() == DialogResult.OK)
            {
                IMapFeatureLayer fl = App.Map.Layers.Add(Frm.Contours);
                fl.LegendText = Frm.LayerName + " - Contours";

                int numlevs = Frm.lev.GetLength(0);

                switch (Frm.contourtype)
                {
                case (Contour.ContourType.Line):
                {
                    LineScheme ls = new LineScheme();
                    ls.Categories.Clear();

                    for (int i = 0; i < Frm.color.GetLength(0); i++)
                    {
                        LineCategory lc = new LineCategory(Frm.color[i], 2.0);

                        lc.FilterExpression = "[Value] = " + Frm.lev[i].ToString();
                        lc.LegendText       = Frm.lev[i].ToString();

                        ls.AddCategory(lc);
                    }

                    fl.Symbology = ls;
                }
                break;

                case (Contour.ContourType.Polygon):
                {
                    PolygonScheme ps = new PolygonScheme();
                    ps.Categories.Clear();

                    for (int i = 0; i < Frm.color.GetLength(0); i++)
                    {
                        PolygonCategory pc = new PolygonCategory(Frm.color[i], Color.Transparent, 0);
                        pc.FilterExpression = "[Lev] = " + i.ToString();
                        pc.LegendText       = Frm.lev[i].ToString() + " - " + Frm.lev[i + 1].ToString();

                        ps.AddCategory(pc);
                    }

                    fl.Symbology = ps;
                }
                break;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Translates the given style as line style and adds it to the given line scheme.
        /// </summary>
        /// <param name="scheme">The scheme the style gets added to.</param>
        /// <param name="style">The style that gets translated.</param>
        private static void TranslateLineStyle(LineScheme scheme, string style)
        {
            if (string.IsNullOrWhiteSpace(style))
            {
                return;
            }

            var mystyle = style;
            int index   = mystyle.IndexOf("(", StringComparison.Ordinal);

            if (index < 1)
            {
                return;
            }

            var toolname = mystyle.Substring(0, index);

            mystyle = mystyle.Substring(index + 1);

            Color     col       = Color.Black;
            double    width     = 1;
            DashStyle dashStyle = DashStyle.Solid;

            float[] pattern   = null;
            bool    invisible = true;

            switch (toolname)
            {
            case "PEN":
                col       = GetColor(ref mystyle, Parameters.Color);
                width     = GetWidth(ref mystyle);
                pattern   = GetPattern(ref mystyle);
                dashStyle = GetDashStyle(ref mystyle, out invisible);
                break;
            }

            if (pattern != null)
            {
                dashStyle = DashStyle.Custom;
            }
            if (invisible)
            {
                col = Color.Transparent;
            }

            var stroke = new CartographicStroke(col)
            {
                Width     = width,
                DashStyle = dashStyle
            };

            if (pattern != null)
            {
                stroke.DashPattern = pattern;
            }

            var symb = new LineSymbolizer
            {
                ScaleMode = ScaleMode.Simple,
                Smoothing = false,
                Strokes   =
                {
                    [0] = stroke
                }
            };

            var cat = new LineCategory
            {
                FilterExpression = $"[style] = '{style}'",
                LegendText       = style,
                Symbolizer       = symb
            };

            scheme.AddCategory(cat);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Translates the style strings from the list to DotSpatial style categories and adds them to the given layer.
        /// </summary>
        /// <param name="layer">The layer the styles get added to.</param>
        /// <param name="styles">The style strings that should get translated.</param>
        public static void TranslateStyles(IMapFeatureLayer layer, IList <string> styles)
        {
            var featureType = layer.DataSet.FeatureType;

            switch (featureType)
            {
            case FeatureType.MultiPoint:
            case FeatureType.Point:
            {
                // create the scheme
                var scheme = new PointScheme();
                scheme.Categories.Clear();
                scheme.EditorSettings.ClassificationType = ClassificationType.UniqueValues;
                scheme.EditorSettings.FieldName          = "style";
                scheme.LegendText = "Point";

                // add the default category
                var cat = new PointCategory(Color.Black, Symbology.PointShape.Rectangle, 5)
                {
                    LegendText = "default",
                    Symbolizer =
                    {
                        ScaleMode = ScaleMode.Simple,
                        Smoothing = false
                    }
                };
                scheme.AddCategory(cat);

                var labelLayer = new MapLabelLayer();
                labelLayer.Symbology.Categories.Clear();

                bool needsLabels = styles.Any(_ => !string.IsNullOrWhiteSpace(_) && _.StartsWith("LABEL"));

                foreach (var style in styles)
                {
                    TranslatePointStyle(scheme, labelLayer.Symbology, style);
                }

                // assign the scheme
                layer.Symbology = scheme;

                // assign the label layer if needed
                if (needsLabels)
                {
                    layer.LabelLayer = labelLayer;
                    layer.ShowLabels = true;
                    layer.LabelLayer.CreateLabels();
                }

                layer.DataSet.UpdateExtent();
                layer.DataSet.InitializeVertices();
                layer.AssignFastDrawnStates();

                break;
            }

            case FeatureType.Line:
            {
                // create the scheme
                var scheme = new LineScheme();
                scheme.Categories.Clear();
                scheme.EditorSettings.ClassificationType = ClassificationType.UniqueValues;
                scheme.EditorSettings.FieldName          = "style";
                scheme.LegendText = "Line";

                // add the default category
                var cat = new LineCategory(Color.Black, 1)
                {
                    LegendText = "default",
                    Symbolizer =
                    {
                        ScaleMode = ScaleMode.Simple,
                        Smoothing = false
                    }
                };
                scheme.AddCategory(cat);

                // add the categories from the file
                foreach (var style in styles)
                {
                    TranslateLineStyle(scheme, style);
                }

                // assign the scheme
                layer.Symbology = scheme;

                layer.DataSet.UpdateExtent();
                layer.DataSet.InitializeVertices();
                layer.AssignFastDrawnStates();

                break;
            }

            case FeatureType.Polygon:
            {
                // create the scheme
                var scheme = new PolygonScheme();
                scheme.Categories.Clear();
                scheme.EditorSettings.ClassificationType = ClassificationType.UniqueValues;
                scheme.EditorSettings.FieldName          = "style";
                scheme.LegendText = "Polygon";

                // add the default category
                var cat = new PolygonCategory(Color.GhostWhite, Color.Black, 1)
                {
                    LegendText = "default",
                    Symbolizer =
                    {
                        ScaleMode = ScaleMode.Simple,
                        Smoothing = false
                    }
                };
                scheme.AddCategory(cat);

                // add the categories from the file
                foreach (var style in styles)
                {
                    TranslatePolygonStyle(scheme, style);
                }

                // assign the scheme
                layer.Symbology = scheme;

                layer.DataSet.UpdateExtent();
                layer.DataSet.InitializeVertices();
                layer.AssignFastDrawnStates();

                break;
            }

            default: throw new ArgumentOutOfRangeException(nameof(featureType), featureType, null);
            }
        }
Exemplo n.º 5
0
        private void MenuClick(object sender, EventArgs e)
        {
            using (FormContour frm = new FormContour())
            {
                frm.Layers = App.Map.GetRasterLayers();
                if (frm.Layers.GetLength(0) <= 0)
                {
                    MessageBox.Show(Resources.NoRasterLayerFound);
                    return;
                }

                if (frm.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                IMapFeatureLayer fl = App.Map.Layers.Add(frm.Contours);
                fl.LegendText = frm.LayerName + " - Contours";

                int numlevs = frm.Lev.GetLength(0);

                switch (frm.Contourtype)
                {
                case Contour.ContourType.Line:
                {
                    LineScheme ls = new LineScheme();
                    ls.Categories.Clear();

                    for (int i = 0; i < frm.Color.GetLength(0); i++)
                    {
                        LineCategory lc = new LineCategory(frm.Color[i], 2.0)
                        {
                            FilterExpression = "[Value] = " + frm.Lev[i],
                            LegendText       = frm.Lev[i].ToString(CultureInfo.InvariantCulture)
                        };

                        ls.AddCategory(lc);
                    }

                    fl.Symbology = ls;
                }

                break;

                case Contour.ContourType.Polygon:
                {
                    PolygonScheme ps = new PolygonScheme();
                    ps.Categories.Clear();

                    for (int i = 0; i < frm.Color.GetLength(0); i++)
                    {
                        PolygonCategory pc = new PolygonCategory(frm.Color[i], Color.Transparent, 0)
                        {
                            FilterExpression = "[Lev] = " + i,
                            LegendText       = frm.Lev[i] + " - " + frm.Lev[i + 1]
                        };
                        ps.AddCategory(pc);
                    }

                    fl.Symbology = ps;
                }

                break;
                }
            }
        }