Ejemplo n.º 1
0
        /// <summary>
        /// Gets the FeatureLayer that is used for the selection tests.
        /// </summary>
        /// <param name="cat">Reference to the second category.</param>
        /// <returns>The FeatureLayer.</returns>
        private static IFeatureLayer GetFeatureLayer(out PolygonCategory cat)
        {
            // load layer with us states
            ShapefileLayerProvider provider = new ShapefileLayerProvider();
            var fl = (IFeatureLayer)provider.OpenLayer(Path.Combine(@"TestFiles", "50mil_us_states.shp"), false, null, null);

            Assert.IsNotNull(fl);

            // add two categories for testing category.SelectionEnabled
            PolygonScheme scheme = new PolygonScheme();

            scheme.ClearCategories();
            scheme.AddCategory(new PolygonCategory(Color.LightBlue, Color.DarkBlue, 1)
            {
                FilterExpression = "[FIPS] >= 10",
                LegendText       = ">= 10"
            });
            cat = new PolygonCategory(Color.Pink, Color.DarkRed, 1)
            {
                FilterExpression = "[FIPS] < 10",
                LegendText       = "< 10"
            };
            scheme.AddCategory(cat);
            fl.Symbology = scheme;
            Assert.IsTrue(cat.SelectionEnabled, "Categories must be initialized with SelectionEnabled = true.");
            return(fl);
        }
Ejemplo n.º 2
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;
                }
            }
        }
Ejemplo n.º 3
0
        private void btnFilterByPopState_Click(object sender, EventArgs e)
        {
            //check the number of layers from map control

            if (map1.Layers.Count > 0)
            {
                //Delacre a MapPolygonLayer
                MapPolygonLayer stateLayer = default(MapPolygonLayer);

                //Type cast the FirstLayer of MapControl to MapPolygonLayer
                stateLayer = (MapPolygonLayer)map1.Layers[0];

                //Check the MapPolygonLayer ( Make sure that it has a polygon layer)
                if (stateLayer == null)
                {
                    MessageBox.Show("The layer is not a polygon layer.");
                }
                else
                {
                    //!!!-------------------- this line is necessary otherwise the code doesn't work------------------------!!!!!!!!!!!!!!!!!!!!
                }
                stateLayer.DataSet.FillAttributes();

                //Create a new PolygonScheme
                PolygonScheme scheme = new PolygonScheme();

                //Create a new PolygonCategory
                PolygonCategory category = new PolygonCategory(Color.Yellow, Color.Red, 1);

                //Declare a filter string
                //[POP1990],[STATE_NAME] are attributes from the attribute table of the given shape file.

                string filter = "[POP1990] > 10000000 OR [STATE_NAME] = 'Idaho'";

                //Set/Assign the filter expression to PolygonCategory
                category.FilterExpression = filter;

                //Set the Legend Text
                category.LegendText = "population > 10 Million";

                //Add the PolygonCategory in to the PolygonScheme
                scheme.AddCategory(category);

                //Set the scheme in to the MapPolygonLayer's symbology
                stateLayer.Symbology = scheme;
            }
            else
            {
                MessageBox.Show("Please add a layer to the map.");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Translates the given style as polygon style and adds it to the given polygon 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 TranslatePolygonStyle(PolygonScheme scheme, string style)
        {
            if (string.IsNullOrWhiteSpace(style))
            {
                return;
            }

            var tools = GetToolNames(style);

            Color  col      = Color.Black;
            Color  fillCol  = Color.White;
            double numWidth = 1;

            foreach (var tool in tools)
            {
                switch (tool.Key)
                {
                case "PEN":
                {
                    var myStyle = tool.Value.Substring(4);
                    col      = GetColor(ref myStyle, Parameters.Color);
                    numWidth = GetWidth(ref myStyle);
                    break;
                }

                case "BRUSH":
                {
                    var myStyle = tool.Value.Substring(6);
                    fillCol = GetColor(ref myStyle, Parameters.BrushForeColor);
                    break;
                }
                }
            }

            var cat = new PolygonCategory(fillCol, col, numWidth)
            {
                FilterExpression = $"[style] = '{style}'",
                LegendText       = style,
                Symbolizer       =
                {
                    ScaleMode = ScaleMode.Simple,
                    Smoothing = false
                }
            };

            scheme.AddCategory(cat);
        }
Ejemplo n.º 5
0
        private void ColorMap()
        {
            try
            {
                FeatureLayer fl = mainMap.Layers[0] as FeatureLayer;
                PolygonCategoryCollection pcc      = new PolygonCategoryCollection();
                PolygonScheme             myScheme = new PolygonScheme();

                myScheme.Categories = new PolygonCategoryCollection();


                string strrow       = "";
                int    iRegionColor = 0;

                foreach (BenMAPRollback brb in _monitorRollbackLine.BenMAPRollbacks)
                {
                    if (brb.SelectRegions.Count != 0)
                    {
                        iRegionColor += brb.SelectRegions.Count;
                    }
                }
                foreach (BenMAPRollback brb in _monitorRollbackLine.BenMAPRollbacks)
                {
                    if (brb.SelectRegions.Count != 0)
                    {
                        foreach (RowCol rc in brb.SelectRegions)
                        {
                            if (iRegionColor != dicMyColorIndex.Count)
                            {
                                if (strrow == "")
                                {
                                    strrow = dicMyColorIndex[rc.Col + "," + rc.Row].ToString();
                                }
                                else
                                {
                                    strrow += "," + dicMyColorIndex[rc.Col + "," + rc.Row].ToString();
                                }
                            }
                            PolygonCategory pcin = new PolygonCategory();

                            pcin.FilterExpression = string.Format("[{0}]={1} ", "MyColorIndex", dicMyColorIndex[rc.Col + "," + rc.Row].ToString());
                            pcin.Symbolizer.SetOutline(Color.Black, 1);
                            string[] strColor = brb.DrawingColor.Split(new char[] { ',' });
                            pcin.Symbolizer.SetFillColor(Color.FromArgb(Convert.ToInt32(strColor[0]), int.Parse(strColor[1]), int.Parse(strColor[2])));
                            myScheme.Categories.Add(pcin);
                        }
                    }
                }


                if (myScheme.Categories.Count > 0)
                {
                    if (iRegionColor != dicMyColorIndex.Count)
                    {
                        PolygonCategory pcin = new PolygonCategory();
                        pcin.FilterExpression = string.Format("[{0}] not in({1})", "MyColorIndex", strrow);

                        pcin.Symbolizer.SetFillColor(Color.White);
                        pcin.Symbolizer.SetOutline(Color.Black, 1);
                        myScheme.Categories.Add(pcin);
                    }
                    (fl as IFeatureLayer).Symbology = myScheme;
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
            }
        }
Ejemplo n.º 6
0
        private void MonitorRollbackSettings2_Load(object sender, EventArgs e)
        {
            try
            {
                if (CommonClass.GBenMAPGrid == null)
                {
                    return;
                }
                mainMap.ProjectionModeReproject = ActionMode.Never;
                mainMap.ProjectionModeDefine    = ActionMode.Never;
                if (_monitorRollbackLine.RollbackGrid is ShapefileGrid)
                {
                    if (File.Exists(CommonClass.DataFilePath + @"\Data\Shapefiles\" + CommonClass.MainSetup.SetupName + "\\" + (_monitorRollbackLine.RollbackGrid as ShapefileGrid).ShapefileName + ".shp"))
                    {
                        mainMap.Layers.Add(CommonClass.DataFilePath + @"\Data\Shapefiles\" + CommonClass.MainSetup.SetupName + "\\" + (_monitorRollbackLine.RollbackGrid as ShapefileGrid).ShapefileName + ".shp");
                    }
                }
                else if (_monitorRollbackLine.RollbackGrid is RegularGrid)
                {
                    if (File.Exists(CommonClass.DataFilePath + @"\Data\Shapefiles\" + CommonClass.MainSetup.SetupName + "\\" + (_monitorRollbackLine.RollbackGrid as RegularGrid).ShapefileName + ".shp"))
                    {
                        mainMap.Layers.Add(CommonClass.DataFilePath + @"\Data\Shapefiles\" + CommonClass.MainSetup.SetupName + "\\" + (_monitorRollbackLine.RollbackGrid as RegularGrid).ShapefileName + ".shp");
                    }
                }
                PolygonLayer playerRegion = mainMap.Layers[mainMap.Layers.Count - 1] as PolygonLayer;
                playerRegion.DataSet.DataTable.Columns.Add("MyColorIndex", typeof(int));
                for (int i = 0; i < playerRegion.DataSet.DataTable.Rows.Count; i++)
                {
                    playerRegion.DataSet.DataTable.Rows[i]["MyColorIndex"] = i;
                    dicMyColorIndex.Add(Convert.ToInt32(playerRegion.DataSet.DataTable.Rows[i]["COL"]).ToString() + "," + Convert.ToInt32(playerRegion.DataSet.DataTable.Rows[i]["ROW"]).ToString(), i);
                }
                Color             cRegion           = Color.Transparent;
                PolygonSymbolizer TransparentRegion = new PolygonSymbolizer(cRegion);

                TransparentRegion.OutlineSymbolizer = new LineSymbolizer(Color.Black, 1); playerRegion.Symbolizer = TransparentRegion;

                lstMonitorValues = DataSourceCommonClass.GetMonitorData(_monitorRollbackLine.GridType, _monitorRollbackLine.Pollutant, _monitorRollbackLine);
                IFeatureSet  fsPoints = new FeatureSet();
                MonitorValue mv       = null;
                Feature      feature  = null;
                List <DotSpatial.Topology.Coordinate> lstCoordinate = new List <DotSpatial.Topology.Coordinate>();
                List <double> fsInter = new List <double>();
                if (lstMonitorValues != null && lstMonitorValues.Count > 0)
                {
                    PolygonScheme   myScheme = new PolygonScheme();
                    PolygonCategory pcin     = new PolygonCategory();
                    pcin.Symbolizer.SetFillColor(Color.Red);
                    myScheme.Categories.Add(pcin);
                    DotSpatial.Topology.Point point;
                    for (int i = 0; i < lstMonitorValues.Count; i++)
                    {
                        mv      = lstMonitorValues[i];
                        point   = new DotSpatial.Topology.Point(mv.Longitude, mv.Latitude);
                        feature = new Feature(point);
                        fsPoints.AddFeature(feature);
                    }
                    mainMap.Layers.Add(fsPoints);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Deserializes the layer.
        /// </summary>
        /// <param name="layer">The layer.</param>
        /// <param name="polyLayer">The poly layer.</param>
        internal static void DeserializeLayer(dynamic layer, MapPolygonLayer polyLayer)
        {
            if (UseAlternateParser(layer))
            {
                DeserializeLayerAlternateVersion(layer.ShapefileProperties, polyLayer);
                return;
            }
            var polySymbolizer = new PolygonSymbolizer();
            var outlineColor   = LegacyDeserializer.GetColor(layer.ShapeFileProperties["OutLineColor"]);
            var outlineWidth   = Convert.ToDouble(layer.ShapeFileProperties["LineOrPointSize"]);

            polySymbolizer.SetOutline(outlineColor, outlineWidth);
            if (Convert.ToBoolean(layer.ShapeFileProperties["DrawFill"]))
            {
                Color color        = LegacyDeserializer.GetColor(layer.ShapeFileProperties["Color"]);
                float transparency = Convert.ToSingle(layer.ShapeFileProperties["TransparencyPercent"]);
                color = color.ToTransparent(transparency);
                polySymbolizer.SetFillColor(color);
            }
            else
            {
                polySymbolizer.SetFillColor(Color.Transparent);
            }

            polyLayer.Symbolizer = polySymbolizer;
            try
            {
                int fieldIndex = Convert.ToInt32(layer.ShapeFileProperties.Legend["FieldIndex"]);

                // we have to clear the categories or the collection ends up with a default item
                polyLayer.Symbology.Categories.Clear();

                foreach (var colorBreak in layer.ShapeFileProperties.Legend.ColorBreaks.Elements())
                {
                    PolygonCategory category;

                    string startValue = colorBreak["StartValue"];
                    string endValue   = colorBreak["EndValue"];

                    if (startValue == endValue)
                    {
                        category = new PolygonCategory(LegacyDeserializer.GetColor(colorBreak["StartColor"]), LegacyDeserializer.GetColor(colorBreak["StartColor"]), 0);
                        category.FilterExpression = String.Format("[{0}] = '{1}'", polyLayer.DataSet.DataTable.Columns[fieldIndex].ColumnName, startValue);
                        category.LegendText       = startValue;
                    }
                    else
                    {
                        category = new PolygonCategory(LegacyDeserializer.GetColor(colorBreak["StartColor"]), LegacyDeserializer.GetColor(colorBreak["EndColor"]), 0, GradientType.Linear, outlineColor, outlineWidth);
                        category.FilterExpression = String.Format("'{2}' >= [{0}] >= '{1}'", polyLayer.DataSet.DataTable.Columns[fieldIndex].ColumnName, startValue, endValue);
                        category.LegendText       = String.Format("{0} - {1}", startValue, endValue);
                    }
                    category.LegendText        = startValue;
                    category.LegendItemVisible = Convert.ToBoolean(colorBreak["Visible"]);
                    polyLayer.Symbology.AddCategory(category);
                }

                // it took too a lot of work to figure out that we would need to do this...
                polyLayer.ApplyScheme(polyLayer.Symbology);
            }
            catch (RuntimeBinderException)
            {
                // ignore and continue.
                // this means the legend is not available.
            }
        }
Ejemplo n.º 8
0
        public void SelectionTest()
        {
            IMap map = new Map();

            // load layer with us states
            IMapLayer     ml = map.AddLayer(Path.Combine(_folder, "50mil_us_states.shp"));
            IFeatureLayer fl = ml as IFeatureLayer;

            Assert.IsNotNull(fl);

            // add two categories for testing category.SelectionEnabled
            PolygonScheme scheme = new();

            scheme.ClearCategories();
            scheme.AddCategory(new PolygonCategory(Color.LightBlue, Color.DarkBlue, 1)
            {
                FilterExpression = "[FIPS] >= 10",
                LegendText       = ">= 10"
            });
            var cat = new PolygonCategory(Color.Pink, Color.DarkRed, 1)
            {
                FilterExpression = "[FIPS] < 10",
                LegendText       = "< 10"
            };

            scheme.AddCategory(cat);
            fl.Symbology = scheme;
            Assert.IsTrue(cat.SelectionEnabled, "Categories must be initialized with SelectionEnabled = true.");

            // load the second layer for testing the layers SelectionEnabled property
            IMapLayer ml2 = map.AddLayer(Path.Combine(_folder, "50m_admin_0_countries.shp"));

            ml2.SelectionEnabled = false;
            IFeatureLayer fl2 = ml2 as IFeatureLayer;

            Assert.IsNotNull(fl2);

            // select the first area
            Envelope e = new(-72, -66, 40, 48);

            Assert.IsTrue(map.Select(e, e, ClearStates.False));
            Assert.AreEqual(7, fl.Selection.Count, "Error selecting 50mil_us_states");
            Assert.AreEqual(0, fl2.Selection.Count, "Error selecting 50m_admin_0_countries");

            // invert a slighly larger area, ignoring the features of the second category
            cat.SelectionEnabled = false;
            Envelope e2 = new(-78, -66, 40, 48);

            Assert.IsTrue(map.InvertSelection(e2, e2));
            Assert.AreEqual(4, fl.Selection.Count, "Error inverting selection 50mil_us_states");
            Assert.AreEqual(0, fl2.Selection.Count, "Error inverting selection 50m_admin_0_countries");

            // add another area allowing the second layer to be selected too
            ml2.SelectionEnabled = true;
            Envelope e3 = new(-89, -77, 24, 33);

            Assert.IsTrue(map.Select(e3, e3, ClearStates.False));
            Assert.AreEqual(9, fl.Selection.Count, "Error adding to selection 50mil_us_states");
            Assert.AreEqual(2, fl2.Selection.Count, "Error adding to selection 50m_admin_0_countries");
            ml2.SelectionEnabled = false;

            // unselect the whole area ignoring the second layer and the deactivated category
            Envelope e4 = new(-89, -66, 24, 48);

            Assert.IsTrue(map.UnSelect(e4, e4));
            Assert.AreEqual(1, fl.Selection.Count, "Error unselecting 50mil_us_states");
            Assert.AreEqual(2, fl2.Selection.Count, "Error unselecting 50m_admin_0_countries");
        }
Ejemplo n.º 9
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);
            }
        }
Ejemplo n.º 10
0
        private bool DrawMonitorMap()
        {
            try
            {
                IFeatureSet fsPoints = new FeatureSet();
                fsPoints.DataTable.Columns.Add("Name");
                fsPoints.DataTable.Columns.Add("Description");
                fsPoints.DataTable.Columns.Add("Longitude");
                fsPoints.DataTable.Columns.Add("Latitude");
                string[] tmps = new string[_lstMonitorPoints[0].dicMetricValues.Count];
                _lstMonitorPoints[0].dicMetricValues.Keys.CopyTo(tmps, 0);
                for (int i = 0; i < tmps.Length; i++)
                {
                    fsPoints.DataTable.Columns.Add(tmps[i]);
                }
                MonitorValue      mv            = null;
                Feature           feature       = null;
                List <Coordinate> lstCoordinate = new List <Coordinate>();
                List <double>     fsInter       = new List <double>();
                mainMap.Layers.Clear();
                mainMap.ProjectionModeReproject = ActionMode.Never;
                mainMap.ProjectionModeDefine    = ActionMode.Never;
                mainMap.Layers.Clear();
                if (File.Exists(this._gridShapeFile))
                {
                    mainMap.Layers.Add(this._gridShapeFile);
                }
                if (this._lstMonitorPoints != null && this.LstMonitorPoints.Count > 0)
                {
                    PolygonScheme   myScheme = new PolygonScheme();
                    PolygonCategory pcin     = new PolygonCategory();
                    pcin.Symbolizer.SetFillColor(Color.Red);
                    myScheme.Categories.Add(pcin);
                    DotSpatial.Topology.Point point;
                    for (int i = 0; i < LstMonitorPoints.Count; i++)
                    {
                        mv      = LstMonitorPoints[i];
                        point   = new DotSpatial.Topology.Point(mv.Longitude, mv.Latitude);
                        feature = new Feature(point);

                        fsPoints.AddFeature(feature);

                        fsPoints.DataTable.Rows[i]["Name"]      = mv.MonitorName;
                        fsPoints.DataTable.Rows[i]["Latitude"]  = mv.Latitude;
                        fsPoints.DataTable.Rows[i]["Longitude"] = mv.Longitude;
                        for (int col = 0; col < tmps.Length; col++)
                        {
                            fsPoints.DataTable.Rows[i][tmps[col]] = mv.dicMetricValues[tmps[col]];
                        }
                    }
                    mainMap.Layers.Add(fsPoints);
                    mainMap.Layers[0].LegendText = "Air quality grid";
                    mainMap.Layers[1].LegendText = "Monitors";
                }
                PolygonLayer      player      = mainMap.Layers[0] as PolygonLayer;
                float             f           = 0.9f;
                Color             c           = Color.Transparent;
                PolygonSymbolizer Transparent = new PolygonSymbolizer(c);
                Transparent.OutlineSymbolizer = new LineSymbolizer(Color.DarkBlue, 1); player.Symbolizer = Transparent;
                LayerObject = null;
                return(true);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                return(false);
            }
        }
Ejemplo n.º 11
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;
                }
            }
        }
Ejemplo n.º 12
0
        //-------------------------------------------------------
        public MapPolygonLayer AddFieldLayer(string Fieldname)
        {
            MapPolygonLayer MyLayer = null;

            if (MapDataTable != null)
            {
                if (MapDataTable.Columns.Contains(Fieldname))
                {
                    try
                    {
                        DataColumn DC = MapDataTable.Columns[Fieldname];

                        MyLayer = AddProviderShapeFile(Fieldname); //(MapPolygonLayer)ProviderMap.AddLayer(DataPath + ShapeFilename);
                        if (MyLayer == null)
                        {
                            MessageBox.Show("The Base ShapeFile is not a polygon layer.");
                        }
                        else
                        {
                            // Get the years
                            string yrfield = WaterSimManager_DB.rdbfSimYear;

                            // MyLayer.DataSet.FillAttributes();

                            DataTable  LayerDT   = MyLayer.DataSet.DataTable;
                            DataColumn AddColumn = new DataColumn(DC.ColumnName, DC.DataType);
                            LayerDT.Columns.Add(AddColumn);

                            foreach (DataRow DR in LayerDT.Rows)
                            {
                                Boolean found  = false;
                                string  pfcode = DR["Provider"].ToString().Trim(); // Get the Provider Field code for this SHape File Record
                                // find this code in Scenario DataTable
                                foreach (DataRow ScnDR in MapDataTable.Rows)
                                {
                                    if (ScnDR[yrfield].ToString().Trim() == MapTargetYear)
                                    {
                                        string Scnpfcode = ScnDR[WaterSimManager_DB.rdbfProviderCode].ToString().Trim(); // "PRVDCODE"
                                        if (pfcode == Scnpfcode)
                                        {
                                            DR[Fieldname] = ScnDR[Fieldname].ToString();
                                            found         = true;
                                            break;
                                        }
                                        if (!found)
                                        {
                                            if (DC.DataType == System.Type.GetType("System.String"))
                                            {
                                                DR[Fieldname] = "";
                                            }
                                            else
                                            {
                                                DR[Fieldname] = 0;
                                            }
                                        }
                                    } //= provider
                                }     // = target year
                            }
                            //MyLayer.DataSet.FillAttributes();

                            if (DC.DataType == System.Type.GetType("System.String"))
                            {
                                PolygonScheme FldScheme = new PolygonScheme();
                                FldScheme.EditorSettings.ClassificationType = ClassificationType.UniqueValues;
                                ////Set the UniqueValue field name
                                FldScheme.EditorSettings.FieldName = Fieldname;
                                // Create Catagories based on data
                                FldScheme.CreateCategories(LayerDT);
                                MyLayer.Symbology = FldScheme;
                            }
                            else
                            {
                                PolygonScheme FldScheme = new PolygonScheme();
                                FldScheme.EditorSettings.ClassificationType = ClassificationType.Quantities;
                                FldScheme.EditorSettings.IntervalMethod     = IntervalMethod.StandardDeviation;
                                FldScheme.EditorSettings.NumBreaks          = 8;
                                FldScheme.EditorSettings.FieldName          = Fieldname;
                                FldScheme.AppearsInLegend = true;
                                FldScheme.CreateCategories(LayerDT);
                                PolygonCategory NullCat = new PolygonCategory(Color.WhiteSmoke, Color.DarkBlue, 1);
                                NullCat.FilterExpression = "[" + Fieldname + "] = NULL";
                                NullCat.LegendText       = "[" + Fieldname + "] = NULL";
                                FldScheme.AddCategory(NullCat);
                                MyLayer.Symbology = FldScheme;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("Error Loading Shape File:[ " + DataPath + ShapeFilename + "] :" + e.Message);
                    }
                }
            }
            return(MyLayer);
        }