private static PointSymbolizer CreatePointSymbolizer(PointStyle style) { var symbolizer = new PointSymbolizer(style.Color, MapDataHelper.Convert(style.Symbol), style.Size); symbolizer.SetOutline(style.StrokeColor, style.StrokeThickness); return(symbolizer); }
public void createPointShape() { //map.Cursor = cursor //map.Cursor = Cursors.Cross; //set the shape type to the classlevel string variable //we are going to use this variable in select case statement shapeType = "Point"; pointF = new FeatureSet(FeatureType.Point); //set projection pointF.Projection = map.Projection; //initialize the featureSet attribute table DataColumn column = new DataColumn("ID"); pointF.DataTable.Columns.Add(column); //add the featureSet as map layer MapPointLayer pointLayer = (MapPointLayer)map.Layers.Add(pointF); //Create a new symbolizer PointSymbolizer symbol = new PointSymbolizer(Color.Red, DotSpatial.Symbology.PointShape.Ellipse, 3); //Set the symbolizer to the point layer pointLayer.Symbolizer = symbol; //Set the legendText as point pointLayer.LegendText = "My Point"; //Set left mouse click as true pointmouseClick = true; }
public void ConvertLayerProperties_MapPointDataWithStyle_ConvertsStyleToMapPointLayer( [Values(KnownColor.AliceBlue, KnownColor.Azure)] KnownColor color, [Values(1, 5)] int width, [Values(PointSymbol.Circle, PointSymbol.Square)] PointSymbol pointStyle) { // Setup var converter = new MapPointDataConverter(); var mapPointLayer = new MapPointLayer(); Color expectedColor = Color.FromKnownColor(color); var mapPointData = new MapPointData("test", new PointStyle { Color = expectedColor, Size = width, Symbol = pointStyle, StrokeColor = expectedColor, StrokeThickness = 1 }); // Call converter.ConvertLayerProperties(mapPointData, mapPointLayer); // Assert PointShape expectedPointShape = pointStyle == PointSymbol.Circle ? PointShape.Ellipse : PointShape.Rectangle; var expectedSymbolizer = new PointSymbolizer(expectedColor, expectedPointShape, width); expectedSymbolizer.SetOutline(expectedColor, 1); AssertAreEqual(expectedSymbolizer, mapPointLayer.Symbolizer); }
private IPointCategory GetPointCategory(PointSymbolizer pointSymbolizer, string filterExpression, string legendText) { return(new PointCategory(pointSymbolizer) { FilterExpression = filterExpression, LegendText = legendText }); }
/// <summary> /// Deserializes the layer. /// </summary> /// <param name="layer">The layer.</param> /// <param name="pointLayer">The point layer.</param> internal static void DeserializeLayer(dynamic layer, MapPointLayer pointLayer) { if (UseAlternateParser(layer)) { // TODO: write alternate parser for this layer information. return; } LegacyPointType typeOfPoint = (LegacyPointType)Enum.ToObject(typeof(LegacyPointType), Convert.ToInt32(layer.ShapeFileProperties["PointType"])); PointSymbolizer pointSymbolizer; if (ConvertLegacyPointTypeToPointShape(typeOfPoint) == PointShape.Undefined) { pointSymbolizer = new PointSymbolizer(); } else { var color = LegacyDeserializer.GetColor(layer.ShapeFileProperties["Color"]); var width = Convert.ToDouble(layer.ShapeFileProperties["LineOrPointSize"]); pointSymbolizer = new PointSymbolizer(color, ConvertLegacyPointTypeToPointShape(typeOfPoint), width); } pointLayer.Symbolizer = pointSymbolizer; }
/// <summary> /// 创建点文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void createPointShapefileToolStripMenuItem_Click(object sender, EventArgs e) { //Change the cursor style map1.Cursor = Cursors.Cross; //set the shape type to the classlevel string variable //we are going to use this variable in select case statement shapeType = "Point"; //set projection pointF.Projection = map1.Projection; //initialize the featureSet attribute table DataColumn column = new DataColumn("ID"); pointF.DataTable.Columns.Add(column); //add the featureSet as map layer MapPointLayer pointLayer = (MapPointLayer)map1.Layers.Add(pointF); //Create a new symbolizer PointSymbolizer symbol = new PointSymbolizer(Color.Red, DotSpatial.Symbology.PointShape.Ellipse, 3); //Set the symbolizer to the point layer pointLayer.Symbolizer = symbol; //Set the legentText as point pointLayer.LegendText = "point"; //Set left mouse click as true pointmouseClick = true; }
public static void DrawPoint(PointSymbolizer symbolizer, Graphics g, Point point, MapViewport map) { if (point == null) { return; } symbolizer.Render(map, point, g); }
private static PointSymbolizer CreateExpectedSymbolizer(PointStyle expectedPointStyle) { PointShape expectedPointShape = MapDataHelper.Convert(expectedPointStyle.Symbol); var expectedSymbolizer = new PointSymbolizer(expectedPointStyle.Color, expectedPointShape, expectedPointStyle.Size); expectedSymbolizer.SetOutline(expectedPointStyle.StrokeColor, expectedPointStyle.StrokeThickness); return(expectedSymbolizer); }
public void ConvertLayerProperties_MapPointDataWithThemeAndMetaDataNameNotInFeatures_OnlyAddsDefaultCategory() { // Setup const string metadataAttribute = "Meta"; var random = new Random(21); var theme = new MapTheme <PointCategoryTheme>("Other Meta", new[] { new PointCategoryTheme(ValueCriterionTestFactory.CreateValueCriterion(), new PointStyle { Color = Color.FromKnownColor(random.NextEnum <KnownColor>()), Size = random.Next(1, 48), Symbol = random.NextEnum <PointSymbol>(), StrokeColor = Color.FromKnownColor(random.NextEnum <KnownColor>()), StrokeThickness = random.Next(1, 48) }) }); var pointStyle = new PointStyle { Color = Color.FromKnownColor(random.NextEnum <KnownColor>()), Size = random.Next(1, 48), Symbol = random.NextEnum <PointSymbol>(), StrokeColor = Color.FromKnownColor(random.NextEnum <KnownColor>()), StrokeThickness = random.Next(1, 48) }; var mapPointData = new MapPointData("test", pointStyle, theme) { Features = new[] { CreateMapFeatureWithMetaData(metadataAttribute) } }; var mapPointLayer = new MapPointLayer(); var converter = new MapPointDataConverter(); // Call converter.ConvertLayerProperties(mapPointData, mapPointLayer); // Assert PointSymbolizer expectedSymbolizer = CreateExpectedSymbolizer(pointStyle); IPointScheme appliedScheme = mapPointLayer.Symbology; Assert.AreEqual(1, appliedScheme.Categories.Count); IPointCategory baseCategory = appliedScheme.Categories[0]; AssertAreEqual(expectedSymbolizer, baseCategory.Symbolizer); Assert.IsNull(baseCategory.FilterExpression); }
private void LbxItemsDrawItem(object sender, DrawItemEventArgs e) { if (e.Index == -1) { return; } // prepare to draw the rectangle for symbol display and selection Rectangle outer = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { e.Graphics.FillRectangle(SystemBrushes.Highlight, outer); } else { Brush b = new SolidBrush(BackColor); e.Graphics.FillRectangle(b, outer); b.Dispose(); } Rectangle inner = new Rectangle(e.Bounds.X + 5, e.Bounds.Y + 1, e.Bounds.Width - 10, e.Bounds.Height - 3); e.Graphics.FillRectangle(Brushes.White, inner); e.Graphics.DrawRectangle(Pens.Black, inner); // draw the symbolizer itself PointSymbolizer pointSym = lbxItems.Items[e.Index] as PointSymbolizer; if (pointSym != null) { DrawPointSymbolizer(pointSym, e.Graphics, inner); return; } LineSymbolizer lineSym = lbxItems.Items[e.Index] as LineSymbolizer; if (lineSym != null) { DrawLineSymbolizer(lineSym, e.Graphics, inner); return; } PolygonSymbolizer polySym = lbxItems.Items[e.Index] as PolygonSymbolizer; if (polySym != null) { DrawPolygonSymbolizer(polySym, e.Graphics, inner); } }
private void btnStartEditNode_Click(object sender, RoutedEventArgs e) { //显示选中要素的结点列表,并提示用户选择需编辑结点 //if (btnStartEditNode.Content.ToString() == "Select editing node") //{ MessageBox.Show("Please select the nodes that you want to edit,left button to select,right button to move"); //注销事件 m_CurrentFeaLyr.SelectionChanged -= M_CurrentFeaLyr_SelectionChanged; MainWindow.m_AddFeaType = Enum.FeaType.MovePoint; MainWindow.m_DotMap.FunctionMode = FunctionMode.Select; MainWindow.m_DotMap.Cursor = System.Windows.Forms.Cursors.Cross; if (m_CurrentFeaLyr.Selection.Count > 0) { m_CurrentFeaLyr.ZoomToSelectedFeatures(); } //复制结点图层 AllPointLayer = MainWindow.m_DotMap.Layers.Where(t => t.LegendText == "AllNodes").FirstOrDefault() as FeatureLayer; if (AllPointLayer == null) { FeatureSet PointSet = new FeatureSet(FeatureType.Point); for (int i = 0; i < Points.Count; i++) { IFeature pFea = PointSet.AddFeature(Points[i]); PointList[i].Feature = pFea; } PointSet.Name = "AllNodes"; PointSet.Projection = MainWindow.m_DotMap.Projection; AllPointLayer = MainWindow.m_DotMap.Layers.Add(PointSet) as FeatureLayer; PointSymbolizer symbol = new PointSymbolizer(System.Drawing.Color.Red, DotSpatial.Symbology.PointShape.Ellipse, 5); AllPointLayer.Symbolizer = symbol; PointSet.SaveAs(TempPath, true); } btnStartEditNode.IsEnabled = false; //} //else//保存 //{ // (m_CurrentFeaLyr as FeatureLayer).FeatureSet.Save(); // MessageBox.Show("Save successfully!"); // btnStartEditNode.Content = "Select editing node"; // MainWindow.m_AddFeaType = Enum.FeaType.None; // MainWindow.m_DotMap.FunctionMode = FunctionMode.None; // MainWindow.m_DotMap.Cursor = System.Windows.Forms.Cursors.Default; // var layer = MainWindow.m_DotMap.Layers.Where(u => u.LegendText == "AllNodes").FirstOrDefault(); // if (layer != null) // MainWindow.m_DotMap.Layers.Remove(layer); // this.Close(); //} }
private void DrawPointSymbolizer(PointSymbolizer sym, Graphics g, Rectangle rect) { if (sym != null) { g.Clear(Color.White); Matrix shift = g.Transform; shift.Translate(rect.Width / 2, rect.Height / 2); g.Transform = shift; double scale = 1; if (sym.ScaleMode == ScaleMode.Geographic || sym.GetSize().Height > (rect.Height - 6)) { scale = (rect.Height - 6) / sym.GetSize().Height; } sym.Draw(g, scale); } }
private void MakeComplexSymbol(IMapPointLayer alayer) { //Objective: Yellow stars in a Blue Circle /* * Complex symbols can be created, simply by adding symbols to the Symbolizer.Symbols list. * There are three basic kinds of symbols, Simple, Character and Image based. * These have some common characteristics, like the Angle, Offset and Size, * which are stored on the base class. * In the derived classes, the characteristics that are specific to the sub‐class control * those aspects of symbology. * For creating new symbols, the Subclass can be used. * For working with individual symbols in the collection, you may need to test what type of * symbol you are working with before you will be able to control its properties. */ PointSymbolizer lPS = new PointSymbolizer(Color.Blue, DotSpatial.Symbology.PointShape.Ellipse, 16); lPS.Symbols.Add(new SimpleSymbol(Color.Yellow, DotSpatial.Symbology.PointShape.Star, 10)); alayer.Symbolizer = lPS; }
private Bitmap CreateDefaultSymbol(Color color, int symbolSize) { double scaleSize = 1; Size2D size = new Size2D(symbolSize, symbolSize); Bitmap normalSymbol = new Bitmap((int)(size.Width * scaleSize) + 1, (int)(size.Height * scaleSize) + 1); Graphics bg = Graphics.FromImage(normalSymbol); Random rnd = new Random(); Color randomColor = Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)); PointSymbolizer sym = new PointSymbolizer(randomColor, PointShape.Rectangle, 4); PointCategory category = new PointCategory(sym); bg.SmoothingMode = category.Symbolizer.Smoothing ? SmoothingMode.AntiAlias : SmoothingMode.None; Matrix trans = bg.Transform; trans.Translate(((float)(size.Width * scaleSize) / 2 - 1), (float)(size.Height * scaleSize) / 2 - 1); bg.Transform = trans; category.Symbolizer.Draw(bg, 1); return(normalSymbol); }
public void ConvertLayerProperties_MapPointDataWithThemeAndMetaDataNameInFeatures_ConvertDataToMapPointLayer() { // Setup const string metadataAttribute = "Meta"; var random = new Random(21); var unequalCriterion = new ValueCriterion(ValueCriterionOperator.UnequalValue, "unequal value"); var equalCriterion = new ValueCriterion(ValueCriterionOperator.EqualValue, "equal value"); var theme = new MapTheme <PointCategoryTheme>(metadataAttribute, new[] { new PointCategoryTheme(equalCriterion, new PointStyle { Color = Color.FromKnownColor(random.NextEnum <KnownColor>()), Size = random.Next(1, 48), Symbol = random.NextEnum <PointSymbol>(), StrokeColor = Color.FromKnownColor(random.NextEnum <KnownColor>()), StrokeThickness = random.Next(1, 48) }), new PointCategoryTheme(unequalCriterion, new PointStyle { Color = Color.FromKnownColor(random.NextEnum <KnownColor>()), Size = random.Next(1, 48), Symbol = random.NextEnum <PointSymbol>(), StrokeColor = Color.FromKnownColor(random.NextEnum <KnownColor>()), StrokeThickness = random.Next(1, 48) }) }); var pointStyle = new PointStyle { Color = Color.FromKnownColor(random.NextEnum <KnownColor>()), Size = random.Next(1, 48), Symbol = random.NextEnum <PointSymbol>(), StrokeColor = Color.FromKnownColor(random.NextEnum <KnownColor>()), StrokeThickness = random.Next(1, 48) }; var mapPointData = new MapPointData("test", pointStyle, theme) { Features = new[] { CreateMapFeatureWithMetaData(metadataAttribute) } }; var mapPointLayer = new MapPointLayer(); var converter = new MapPointDataConverter(); // Call converter.ConvertLayerProperties(mapPointData, mapPointLayer); // Assert PointSymbolizer expectedSymbolizer = CreateExpectedSymbolizer(pointStyle); IPointScheme appliedScheme = mapPointLayer.Symbology; Assert.AreEqual(3, appliedScheme.Categories.Count); IPointCategory baseCategory = appliedScheme.Categories[0]; AssertAreEqual(expectedSymbolizer, baseCategory.Symbolizer); Assert.IsNull(baseCategory.FilterExpression); IPointCategory equalSchemeCategory = appliedScheme.Categories[1]; string expectedFilter = $"[1] = '{equalCriterion.Value}'"; Assert.AreEqual(expectedFilter, equalSchemeCategory.FilterExpression); PointStyle expectedCategoryStyle = theme.CategoryThemes.ElementAt(0).Style; expectedSymbolizer = CreateExpectedSymbolizer(expectedCategoryStyle); AssertAreEqual(expectedSymbolizer, equalSchemeCategory.Symbolizer); IPointCategory unEqualSchemeCategory = appliedScheme.Categories[2]; expectedFilter = $"NOT [1] = '{unequalCriterion.Value}'"; Assert.AreEqual(expectedFilter, unEqualSchemeCategory.FilterExpression); expectedCategoryStyle = theme.CategoryThemes.ElementAt(1).Style; expectedSymbolizer = CreateExpectedSymbolizer(expectedCategoryStyle); AssertAreEqual(expectedSymbolizer, unEqualSchemeCategory.Symbolizer); }
private void btnOK_Click(object sender, RoutedEventArgs e) { if (this.cboLayer.Text == "") { MessageBox.Show("Please select a polyline layer"); return; } IFeatureLayer layer = m_Layers[this.cboLayer.SelectedIndex]; IFeatureSet feaset = (layer as FeatureLayer).FeatureSet; ProgressBox p = new ProgressBox(0, 100, "Suspension point check progress"); p.ShowPregress(); p.SetProgressValue(0); p.SetProgressDescription("Checking suspension point..."); Dictionary <int, List <GeoAPI.Geometries.IPoint> > AllPoints = new Dictionary <int, List <GeoAPI.Geometries.IPoint> >();//线图层所有端点 for (int i = 0; i < feaset.Features.Count; i++) { IFeature pFea = feaset.Features[i]; if (pFea.Geometry.GeometryType == "LineString") { GeoAPI.Geometries.Coordinate coord1 = pFea.Geometry.Coordinates[0]; GeoAPI.Geometries.IPoint pPoint1 = new NetTopologySuite.Geometries.Point(coord1); int count = pFea.Geometry.Coordinates.Count() - 1; GeoAPI.Geometries.Coordinate coord2 = pFea.Geometry.Coordinates[count]; GeoAPI.Geometries.IPoint pPoint2 = new NetTopologySuite.Geometries.Point(coord2); AllPoints.Add(pFea.Fid, new List <GeoAPI.Geometries.IPoint>() { pPoint1, pPoint2 }); } else//多线 { for (int j = 0; j < pFea.Geometry.NumGeometries; j++) { var geometry = pFea.Geometry.GetGeometryN(j); GeoAPI.Geometries.Coordinate coord1 = geometry.Coordinates[0]; GeoAPI.Geometries.IPoint pPoint1 = new NetTopologySuite.Geometries.Point(coord1); int count = geometry.Coordinates.Count() - 1; GeoAPI.Geometries.Coordinate coord2 = geometry.Coordinates[count]; GeoAPI.Geometries.IPoint pPoint2 = new NetTopologySuite.Geometries.Point(coord2); if (AllPoints.ContainsKey(pFea.Fid)) { if (!AllPoints[pFea.Fid].Contains(pPoint1)) { AllPoints[pFea.Fid].Add(pPoint1); } if (!AllPoints[pFea.Fid].Contains(pPoint2)) { AllPoints[pFea.Fid].Add(pPoint2); } } else { AllPoints.Add(pFea.Fid, new List <GeoAPI.Geometries.IPoint>() { pPoint1, pPoint2 }); } } } } List <GeoAPI.Geometries.IPoint> resultPoint = new List <GeoAPI.Geometries.IPoint>(); double pi = Math.Round((double)(1.0 * 100 / feaset.Features.Count), 2); int number = 1; foreach (var value in AllPoints) { p.SetProgressValue(number * pi); p.SetProgressDescription2(string.Format("{0} feature(s) is(are) checked, the remaining {1} feature(s) is(are) being queried", number, feaset.Features.Count - number)); number++; foreach (var point in value.Value) { bool IsSuspension = true; foreach (var fea in feaset.Features) { if (fea.Fid == value.Key) { continue; } //一旦相交,必不是悬点 if (fea.Geometry.Intersects(point)) { IsSuspension = false; break; } } if (IsSuspension && !resultPoint.Contains(point)) { resultPoint.Add(point); } } } AllPoints.Clear(); p.CloseProgress(); if (resultPoint.Count == 0) { MessageBox.Show(string.Format("{0} has no suspension point.", layer.LegendText)); } else { IFeatureSet pSet = new FeatureSet(FeatureType.Point); string[] Fields = new string[3] { "ID", "X", "Y" }; foreach (string field in Fields) { pSet.DataTable.Columns.Add(field); } int s = 0; foreach (var point in resultPoint) { IFeature pFea = pSet.AddFeature(point); pFea.DataRow[0] = s; pFea.DataRow[1] = point.X; pFea.DataRow[2] = point.Y; s++; } pSet.Projection = MainWindow.m_DotMap.Projection; pSet.Name = m_Layers[this.cboLayer.SelectedIndex].LegendText + "_suspenion points"; var feaLayer = MainWindow.m_DotMap.Layers.Add(pSet); PointSymbolizer symbol = new PointSymbolizer(System.Drawing.Color.Red, DotSpatial.Symbology.PointShape.Ellipse, 5); feaLayer.Symbolizer = symbol; MessageBox.Show(string.Format("{0} has {1} suspension point.", layer.LegendText, resultPoint.Count.ToString())); } this.Close(); }
/// <summary> /// Sets up the Table to work with the specified layer. This should be the copy, /// and not the original. /// </summary> /// <param name="layer"></param> public void Initialize(IFeatureLayer layer) { _original = layer.Symbology; _newScheme = _original.Copy(); _source = layer.DataSet; if (!layer.DataSet.AttributesPopulated) { if (layer.DataSet.NumRows() < 100000) { _source.FillAttributes(); // for small datasets, it is better to just load and cache it. } } if (_source.AttributesPopulated) { _expressionDialog.Table = _source.DataTable; } else { _expressionDialog.AttributeSource = _source; } _schemeType = GetSchemeType(layer); if (_schemeType != SymbolizerType.Polygon) { chkUseGradients.Visible = false; angGradientAngle.Visible = false; } else { chkUseGradients.Visible = true; angGradientAngle.Visible = true; } if (_schemeType == SymbolizerType.Point) { IPointScheme ps = _newScheme as IPointScheme; if (ps != null) { IPointSymbolizer sym; if (ps.Categories.Count == 0 || ps.Categories[0].Symbolizer == null) { sym = new PointSymbolizer(); } else { sym = ps.Categories[0].Symbolizer; } _ignoreRefresh = true; featureSizeRangeControl1.SizeRange = new FeatureSizeRange(sym, _newScheme.EditorSettings.StartSize, _newScheme.EditorSettings.EndSize); featureSizeRangeControl1.Initialize(new SizeRangeEventArgs(_newScheme.EditorSettings.StartSize, _newScheme.EditorSettings.EndSize, sym, _newScheme.EditorSettings.UseSizeRange)); featureSizeRangeControl1.Scheme = ps; featureSizeRangeControl1.Visible = true; _ignoreRefresh = false; } } else if (_schemeType == SymbolizerType.Line) { ILineScheme ls = _newScheme as ILineScheme; if (ls != null) { ILineSymbolizer sym; if (ls.Categories.Count == 0 || ls.Categories[0].Symbolizer == null) { sym = new LineSymbolizer(); } else { sym = ls.Categories[0].Symbolizer; } _ignoreRefresh = true; featureSizeRangeControl1.SizeRange = new FeatureSizeRange(sym, _newScheme.EditorSettings.StartSize, _newScheme.EditorSettings.EndSize); featureSizeRangeControl1.Initialize(new SizeRangeEventArgs(_newScheme.EditorSettings.StartSize, _newScheme.EditorSettings.EndSize, sym, _newScheme.EditorSettings.UseSizeRange)); featureSizeRangeControl1.Scheme = ls; featureSizeRangeControl1.Visible = true; _ignoreRefresh = false; } } else { featureSizeRangeControl1.Visible = false; } UpdateFields(); if (_newScheme.EditorSettings.ClassificationType != ClassificationType.Quantities) return; nudCategoryCount.Enabled = true; tabScheme.Visible = true; dgvCategories.Height = 217; UpdateStatistics(false, null); }
private PointSymbolizer CreatePointSymbolizer(NodePropertyValue[] properties) { PointSymbolizer symPoint = new PointSymbolizer(); int pointType = properties[0].Name.StartsWith("point-") ? 0 : 1; bool isArrow = HasPropertyValue(properties, "marker-file", "shape://arrow"); if (pointType == 1 && isArrow) pointType = 2; ExternalGraphicSymbol pointSymbol = null; MarkGraphicSymbol markSymbol = null; GlyphGraphicSymbol glyphSymbol = null; LabelPlacementInfo lpi = new LabelPlacementInfo(); if (pointType == 0 || (!isArrow && HasProperty(properties ,"marker-file"))) { pointSymbol = new ExternalGraphicSymbol(); symPoint.Graphic.GraphicSymbols.Add(pointSymbol); lpi.Placement = "centroid"; lpi.Symbolizer = (int)SymbolizerType.Point; } else if (pointType == 1) { markSymbol = new MarkGraphicSymbol(); symPoint.Graphic.GraphicSymbols.Add(markSymbol); lpi.Symbolizer = (int)SymbolizerType.Marker; } else { glyphSymbol = new GlyphGraphicSymbol(); symPoint.Graphic.GraphicSymbols.Add(glyphSymbol); lpi.Symbolizer = (int)SymbolizerType.Marker; } float width = 10F, height = 0F; NodePropertyValue pv = null; try { int nProps = properties.Length; for (int i = 0; i < nProps; i++) { pv = properties[i]; if (pointType == 0) { switch (pv.Name) { case "point-file": pointSymbol.Path = ToPath(pv.Value); break; case "point-allow-overlap": symPoint.LabelBehaviour.AllowOverlap = Convert.ToBoolean(pv.Value); break; case "point-ignore-placement": symPoint.LabelBehaviour.CollisionDetectable = !Convert.ToBoolean(pv.Value); break; case "point-opacity": pointSymbol.Opacity = Convert.ToSingle(pv.Value); break; case "point-placement": lpi.Placement = pv.Value; break; case "point-transform": UnsupportedProperty(pv); break; case "point-comp-op": //UnsupportedProperty(pv.Name); AddProperty(symPoint, "comp-op", pv.Value); break; } } else { switch (pv.Name) { case "marker-file": if (pointSymbol != null) pointSymbol.Path = ToPath(pv.Value); else if (glyphSymbol != null) { if (FontUtility.IsFontInstalled("DejaVu Sans")) { glyphSymbol.TextStyle.Font.Name = "DejaVu Sans"; glyphSymbol.TextStyle.Font.Stretch = 1.2F; glyphSymbol.Unicode = 8594; } else if (FontUtility.IsFontInstalled("Segoe UI")) { glyphSymbol.TextStyle.Font.Name = "Segoe UI"; glyphSymbol.Unicode = 2192; } } break; case "marker-opacity": float value = Convert.ToSingle(pv.Value); if (pointSymbol != null) pointSymbol.Opacity = value; else if (symPoint.Graphic != null) symPoint.Graphic.Opacity /*markSymbol.Opacity*/ = value; if (value == 0.0F) symPoint.Enabled = false; break; case "marker-line-color": Color clr = ColorUtility.FromHtml(pv.Value); if (markSymbol != null) markSymbol.Stroke.Color = clr; else if (glyphSymbol != null) glyphSymbol.TextStyle.Halo.Color = clr; break; case "marker-line-width": if (markSymbol != null) markSymbol.Stroke.Width = Convert.ToSingle(pv.Value); else if (glyphSymbol != null) glyphSymbol.TextStyle.Halo.Radius = Convert.ToSingle(pv.Value); break; case "marker-line-opacity": if (markSymbol != null) markSymbol.Stroke.Opacity = Convert.ToSingle(pv.Value); else if (glyphSymbol != null) glyphSymbol.TextStyle.Halo.Opacity = Convert.ToSingle(pv.Value); break; case "marker-placement": lpi.Placement = pv.Value; if ((glyphSymbol != null || markSymbol != null) && lpi.Placement.Equals("line")) lpi.Placement = "line-point-pattern"; break; case "marker-multi-policy": // TODO break; case "marker-type": markSymbol.WellKnownName = pv.Value; break; case "marker-width": width = Convert.ToSingle(pv.Value); if (glyphSymbol != null) glyphSymbol.TextStyle.Font.Size = width; break; case "marker-height": height = Convert.ToSingle(pv.Value); break; case "marker-fill-opacity": if (markSymbol != null) markSymbol.Fill.Opacity = Convert.ToSingle(pv.Value); else if (glyphSymbol != null) glyphSymbol.TextStyle.Opacity = Convert.ToSingle(pv.Value); break; case "marker-fill": clr = ColorUtility.FromHtml(pv.Value); if (markSymbol != null) markSymbol.Fill.Color = clr; else if (glyphSymbol != null) glyphSymbol.TextStyle.Color = clr; break; case "marker-allow-overlap": symPoint.LabelBehaviour.AllowOverlap = Convert.ToBoolean(pv.Value); break; case "marker-ignore-placement": symPoint.LabelBehaviour.CollisionDetectable = !Convert.ToBoolean(pv.Value); break; case "marker-spacing": lpi.Properties.Add(new KeyValuePair<string, string>(pv.Name, pv.Value)); break; case "marker-max-error": // TODO break; case "marker-transform": ApplySVGTransformation(symPoint.Graphic, pv.Value); break; case "marker-clip": symPoint.Clip = Convert.ToBoolean(pv.Value); break; case "marker-smooth": symPoint.Clip = Convert.ToBoolean(pv.Value); break; case "marker-geometry-transform": UnsupportedProperty(pv); break; case "marker-comp-op": UnsupportedProperty(pv); AddProperty(symPoint, "comp-op", pv.Value); break; } } } } catch (Exception ex) { ThrowParsingException(ex, pv); } if (height == 0F) height = width; if (markSymbol != null) markSymbol.Size = new SizeF(width, height); else if (glyphSymbol != null) symPoint.Graphic.Size = new SizeF(width, 6); symPoint.LabelPlacement = CreateLabelPlacement(lpi); return symPoint; }
public static void DrawMultiPoint(PointSymbolizer symbolizer, Graphics g, MultiPoint points, MapViewport map) { symbolizer.Render(map, points, g); }
private void lbxItems_DrawItem(object sender, DrawItemEventArgs e) { if (e.Index == -1) { return; } //prepare to draw the rectangle for symbol display and selection Rectangle outer = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { e.Graphics.FillRectangle(SystemBrushes.Highlight, outer); } else { Brush b = new SolidBrush(BackColor); e.Graphics.FillRectangle(b, outer); b.Dispose(); } Rectangle inner = new Rectangle(e.Bounds.X + 5, e.Bounds.Y + 1, e.Bounds.Width - 10, e.Bounds.Height - 3); e.Graphics.FillRectangle(Brushes.White, inner); e.Graphics.DrawRectangle(Pens.Black, inner); //draw the symbolizer itself PointSymbolizer pointSym = lbxItems.Items[e.Index] as PointSymbolizer; if (pointSym != null) { DrawPointSymbolizer(pointSym, e.Graphics, inner); return; } LineSymbolizer lineSym = lbxItems.Items[e.Index] as LineSymbolizer; if (lineSym != null) { DrawLineSymbolizer(lineSym, e.Graphics, inner); return; } PolygonSymbolizer polySym = lbxItems.Items[e.Index] as PolygonSymbolizer; if (polySym != null) { DrawPolygonSymbolizer(polySym, e.Graphics, inner); return; } //IFeatureSymbolizer sym = lbxItems.Items[e.Index] as IFeatureSymbolizer; //if (sym == null) return; //Matrix old = e.Graphics.Transform; //Matrix shift = e.Graphics.Transform; //Size2D size = _symbolizers.GetBoundingSize(); //double scaleSize = 1; //if (_scaleMode == ScaleModes.Geographic || size.Height > 14) //{ // scaleSize = (ItemHeight - 6) / size.Height; //} //shift.Translate(e.Bounds.Left + e.Bounds.Width / 2, e.Bounds.Top + e.Bounds.Height / 2); ////shift.Translate(-(float)(size.Width * scaleSize / 2), -(float)(size.Height * scaleSize / 2)); //e.Graphics.Transform = shift; //sym.Draw(e.Graphics, scaleSize); //e.Graphics.Transform = old; }
private static IPointScheme CreateSymbology(string servCode, IFeatureSet featureSet) { Debug.Assert(featureSet != null); var scheme = new PointScheme(); scheme.ClearCategories(); var settings = scheme.EditorSettings; settings.ClassificationType = ClassificationType.Custom; const string valueField = "ValueCount"; // Find min/max value in valueField var minValue = int.MaxValue; var maxValue = int.MinValue; foreach (DataRow row in featureSet.DataTable.Rows) { int value; try { value = Convert.ToInt32(row[valueField]); } catch { value = 0; } if (value < minValue) { minValue = value; } if (value > maxValue) { maxValue = value; } } if (minValue == int.MaxValue) { minValue = 0; } if (maxValue == int.MinValue) { maxValue = 0; } // Calculate number of categories int categoriesCount; var length = maxValue - minValue; if (length < 50) { categoriesCount = 1; } else if (length < 100) { categoriesCount = 2; } else { categoriesCount = 3; } var categorieStep = (maxValue - minValue) / categoriesCount + 1; // value step in filter const int imageStep = 5; var imageSize = 5; var imageHelper = new WebServices.ServiceIconHelper(Settings.Instance.SelectedHISCentralURL); // we need it only to get image var image = imageHelper.GetImageForService(servCode); const string seriesID = "SeriesID"; var needDownloadedCategories = featureSet.DataTable.Columns.Contains(seriesID); for (int i = 0; i < categoriesCount; i++) { var min = minValue - 1; var max = minValue + categorieStep; if (max > maxValue) { max = maxValue; } minValue = max + 1; imageSize += imageStep; var baseFilter = string.Format("[{0}] > {1} and [{0}] <= {2}", valueField, min, max); var filterEx = needDownloadedCategories ? baseFilter + string.Format(" AND ([{0}] is null)", seriesID) : baseFilter; var legendText = string.Format("({0}, {1}]", min, max); var mySymbolizer = new PointSymbolizer(image, imageSize); var myCategory = new PointCategory(mySymbolizer) { FilterExpression = filterEx, LegendText = legendText, SelectionSymbolizer = new PointSymbolizer(image, imageSize + 2) }; myCategory.SelectionSymbolizer.SetFillColor(Color.Yellow); scheme.AddCategory(myCategory); // add category for downloaded if (needDownloadedCategories) { mySymbolizer = new PointSymbolizer(image, imageSize); mySymbolizer.SetOutline(Color.Green, 3); filterEx = string.Format("{0} AND not([{1}] is null)", baseFilter, seriesID); legendText = myCategory.LegendText + " (downloaded)"; var categorieForDownload = new PointCategory(mySymbolizer) { FilterExpression = filterEx, LegendText = legendText, SelectionSymbolizer = new PointSymbolizer(image, imageSize + 2) }; categorieForDownload.SelectionSymbolizer.SetFillColor(Color.Yellow); scheme.AddCategory(categorieForDownload); } } return(scheme); }
private void UpdateSymbology(IFeatureLayer mapLayer, string columnName) { var scheme = new PointScheme(); scheme.ClearCategories(); var settings = scheme.EditorSettings; settings.ClassificationType = ClassificationType.Custom; var colors = new[] { Color.Aqua, Color.Blue, Color.Brown, Color.Cyan, Color.Fuchsia, Color.LightSalmon, Color.Olive, Color.Wheat, Color.DodgerBlue }; // Find min/max value in valueField var minValue = double.MaxValue; var maxValue = double.MinValue; foreach (DataRow row in mapLayer.DataSet.DataTable.Rows) { double value; try { value = Convert.ToDouble(row[columnName]); } catch { value = 0; } if (value < minValue) { minValue = value; } if (value > maxValue) { maxValue = value; } } const double EPSILON = 0.00001; if (Math.Abs(minValue - double.MaxValue) < EPSILON) { minValue = 0.0; } if (Math.Abs(maxValue - double.MinValue) < EPSILON) { maxValue = 0.0; } var fracLength = maxValue - minValue > 10? 0 : 1; // Set number of categories const int categoriesCount = 3; var categorieStep = (maxValue - minValue) / categoriesCount; // value step in filter const int imageStep = 5; var imageSize = 10; // start image size var imageColor = colors[new Random().Next(0, colors.Length - 1)]; for (int i = 0; i < categoriesCount; i++) { var min = minValue + categorieStep * i; var max = min + categorieStep; if (max >= maxValue) { max = maxValue + 1; } min = Math.Round(min, fracLength); max = Math.Round(max, fracLength); // Fix possible round problems on interval borders if (i == 0 && min > minValue) { min--; } if (i == categoriesCount - 1 && max < maxValue) { max++; } imageSize += imageStep; var baseFilter = string.Format("[{0}] >= {1} and [{0}] < {2}", columnName, fracLength == 0 ? (int)min : min, fracLength == 0 ? (int)max : max); var legendText = string.Format("[{0}, {1})", fracLength == 0 ? (int)min : min, fracLength == 0 ? (int)max : max); var mySymbolizer = new PointSymbolizer(imageColor, PointShape.Ellipse, imageSize); var myCategory = new PointCategory(mySymbolizer) { FilterExpression = baseFilter.Replace(",", "."), LegendText = legendText, }; scheme.AddCategory(myCategory); } mapLayer.Symbology = scheme; }
public void ExerciseWmcFromCodeTest() { ViewContext context = new ViewContext(); // Context -> General context.General.Window.Width = 500; context.General.Window.Height = 300; context.General.BoundingBox.SRS = "EPSG:4326"; context.General.BoundingBox.MinX = -180; context.General.BoundingBox.MinY = -90; context.General.BoundingBox.MaxX = 180; context.General.BoundingBox.MaxY = 90; context.General.Title = "EOS Data Gateways"; context.General.KeywordList.Add("EOS"); context.General.KeywordList.Add("EOSDIS"); context.General.KeywordList.Add("NASA"); context.General.KeywordList.Add("CCRS"); context.General.KeywordList.Add("CEOS"); context.General.KeywordList.Add("OGC"); context.General.Abstract = "Map View of EOSDIS partners locations"; context.General.LogoURL.Width = 130; context.General.LogoURL.Height = 74; context.General.LogoURL.Format = "image/gif"; context.General.LogoURL.OnlineResource.Type = "simple"; context.General.LogoURL.OnlineResource.Href = "http://redhook.gsfc.nasa.gov/~imswww/pub/icons/logo.gif"; context.General.DescriptionURL.Format = "text/html"; context.General.DescriptionURL.OnlineResource.Type = "simple"; context.General.DescriptionURL.OnlineResource.Href = "http://eos.nasa.gov/imswelcome"; context.General.ContactInformation.ContactPersonPrimary.ContactPerson = "Tom Kralidis"; context.General.ContactInformation.ContactPersonPrimary.ContactOrganisation = "Canada Centre for Remote Sensing"; context.General.ContactInformation.ContactPosition = "Systems Scientist"; context.General.ContactInformation.ContactAddress.AddressType = "postal"; context.General.ContactInformation.ContactAddress.Address = "615 Booth Street, room 650"; context.General.ContactInformation.ContactAddress.City = "Ottawa"; context.General.ContactInformation.ContactAddress.StateOrProvince = "Ontario"; context.General.ContactInformation.ContactAddress.Country = "Canada"; context.General.ContactInformation.ContactVoiceTelephone = "+01 613 947 1828"; context.General.ContactInformation.ContactFacsimileTelephone = "+01 613 947 2410"; context.General.ContactInformation.ContactElectronicMailAddress = "*****@*****.**"; context.Version = "1.0"; context.Id = "TEST"; // Context -> Layer Layer layer = new Layer(); layer.Queryable = 1; layer.Hidden = 0; layer.Server.Service = GeospatialServices.Ogc.Common.ServiceNames.WMS; layer.Server.Version = "1.0.7"; layer.Title = "The GLOBE Program Visualization Server"; layer.Server.OnlineResource.Type = "simple"; layer.Server.OnlineResource.Href = "http://globe.digitalearth.gov/viz-bin/wmt.cgi"; layer.Name = "NATIONAL"; layer.Title = "National Boundaries"; layer.Abstract = "Context layer: National Boundaries"; layer.SRS = "EPSG:4326"; // Context -> Layer -> Format layer.FormatList.Add(new Format("GIF", 1)); // Context -> Layer -> Style Style style1 = new Style(); style1.Current = 1; style1.Name = "default"; style1.LegendURL.Width = 16; style1.LegendURL.Height = 16; style1.LegendURL.Format = "image/gif"; style1.LegendURL.OnlineResource.Type = "simple"; style1.LegendURL.OnlineResource.Href = "http://mapserv2.esrin.esa.it/cubestor/cubeserv.cgi?VERSION=1.1.0&REQUEST=GetLegendIcon&LAYER=WORLD_MODIS_1KM:MapAdmin&SPATIAL_TYPE=RASTER&STYLE=default&FORMAT=image//gif"; // Context -> Layer -> Style -> Named Layer NamedLayer namedLayer = new NamedLayer(); namedLayer.Name = "Roads"; // Context -> Layer -> Style -> Named Layer -> Named Styles namedLayer.NamedStyles.Add(new NamedStyle("Casing")); namedLayer.NamedStyles.Add(new NamedStyle("Centerline")); // Context -> Layer -> Style -> Named Layer -> User Style UserStyle userStyle1 = new UserStyle(); // Context -> Layer -> Style -> Named Layer -> User Style -> FeatureTypeStyle FeatureTypeStyle featureTypeStyle1 = new FeatureTypeStyle(); Rule rule1 = new Rule(); // Context -> Layer -> Style -> Named Layer -> User Style -> FeatureTypeStyle -> Rule -> Symbolizers BaseSymbolizer[] symbolizers = new BaseSymbolizer[6]; SymbolizerTypes[] symbolizerSelections = new SymbolizerTypes[6]; // Line Symbolizer LineSymbolizer lineSymbolizer = new LineSymbolizer(); lineSymbolizer.Geometry.PropertyName = "center-line"; lineSymbolizer.Stroke.SvgParameters.Add(new SvgParameter("stroke", "#0000ff")); lineSymbolizer.Stroke.SvgParameters.Add(new SvgParameter("stroke-width", "2")); symbolizers[0] = lineSymbolizer; symbolizerSelections[0] = SymbolizerTypes.LineSymbolizer; // Polygon Symbolizer PolygonSymbolizer polygonSymbolizer = new PolygonSymbolizer(); polygonSymbolizer.Geometry.PropertyName = "the_area"; polygonSymbolizer.Fill.SvgParameters.Add(new SvgParameter("fill", "#aaaaff")); polygonSymbolizer.Stroke.SvgParameters.Add(new SvgParameter("stroke", "#0000aa")); symbolizers[1] = polygonSymbolizer; symbolizerSelections[1] = SymbolizerTypes.PolygonSymbolizer; // Point Symbolizer PointSymbolizer pointSymbolizer = new PointSymbolizer(); // Point Symbolizer - > External Graphic 1 ExternalGraphic externalGraphic1 = new ExternalGraphic(); externalGraphic1.OnlineResource.Type = "simple"; externalGraphic1.OnlineResource.Href = "http://www.vendor.com/geosym/2267.svg"; externalGraphic1.Format = "image/svg+xml"; pointSymbolizer.Graphic.ExternalGraphics.Add(externalGraphic1); // Point Symbolizer - > External Graphic 2 ExternalGraphic externalGraphic2 = new ExternalGraphic(); externalGraphic2.OnlineResource.Type = "simple"; externalGraphic2.OnlineResource.Href = "http://www.vendor.com/geosym/2267.png"; externalGraphic2.Format = "image/png"; pointSymbolizer.Graphic.ExternalGraphics.Add(externalGraphic2); pointSymbolizer.Graphic.Size = 15.0; symbolizers[2] = pointSymbolizer; symbolizerSelections[2] = SymbolizerTypes.PointSymbolizer; // Text Symbolizer TextSymbolizer textSymbolizer = new TextSymbolizer(); textSymbolizer.Geometry.PropertyName = "locatedAt"; textSymbolizer.Label = @"ogc:PropertyName[hospitalName]"; textSymbolizer.Font.SvgParameters.Add(new SvgParameter("font-family", "Arial")); textSymbolizer.Font.SvgParameters.Add(new SvgParameter("font-family", "Sans-Serif")); textSymbolizer.Font.SvgParameters.Add(new SvgParameter("font-style", "italic")); textSymbolizer.Font.SvgParameters.Add(new SvgParameter("font-size", "10")); textSymbolizer.Fill.SvgParameters.Add(new SvgParameter("fill", "#000000")); textSymbolizer.LabelPlacement.PointPlacement = new PointPlacement(); textSymbolizer.LabelPlacement.PointPlacement.AnchorPoint.AnchorPointX = 456; textSymbolizer.LabelPlacement.PointPlacement.AnchorPoint.AnchorPointY = 123; textSymbolizer.LabelPlacement.PointPlacement.Rotation = 180; textSymbolizer.LabelPlacement.PointPlacement.Displacement.DisplacementX = 111; textSymbolizer.LabelPlacement.PointPlacement.Displacement.DisplacementY = 222; textSymbolizer.LabelPlacement.LinePlacement = new LinePlacement(); textSymbolizer.LabelPlacement.LinePlacement.Gap = 12; textSymbolizer.LabelPlacement.LinePlacement.GeneraliseLine = 3; textSymbolizer.LabelPlacement.LinePlacement.InitialGap = 3; textSymbolizer.LabelPlacement.LinePlacement.IsAligned = 0; textSymbolizer.LabelPlacement.LinePlacement.IsRepeated = 1; textSymbolizer.LabelPlacement.LinePlacement.PerpendicularOffset = 5; textSymbolizer.Halo.Fill = new Fill(); textSymbolizer.Halo.Fill.SvgParameters.Add(new SvgParameter("fill", "#000000")); textSymbolizer.Halo.Radius = 3; symbolizers[3] = textSymbolizer; symbolizerSelections[3] = SymbolizerTypes.TextSymbolizer; // Raster Symbolizer 1 RasterSymbolizer rasterSymbolizer1 = new RasterSymbolizer(); rasterSymbolizer1.Opacity = 1.0; rasterSymbolizer1.OverlapBehaviour = OverlapBehaviourTypes.Average; rasterSymbolizer1.ColourMap.Categorize.LookupValue = "Rasterdata"; rasterSymbolizer1.ColourMap.Categorize.Values.Add("#00ff00"); rasterSymbolizer1.ColourMap.Categorize.Thresholds.Add(-417); rasterSymbolizer1.ColourMap.Categorize.Values.Add("#00fa00"); rasterSymbolizer1.ColourMap.Categorize.Thresholds.Add(-333); symbolizers[4] = rasterSymbolizer1; symbolizerSelections[4] = SymbolizerTypes.RasterSymbolizer; // Raster Symbolizer 2 RasterSymbolizer rasterSymbolizer2 = new RasterSymbolizer(); rasterSymbolizer2.Opacity = 1.0; rasterSymbolizer2.OverlapBehaviour = OverlapBehaviourTypes.LatestOnTop; rasterSymbolizer2.ChannelSelection.RedChannel.SourceChannelName = "1"; rasterSymbolizer2.ChannelSelection.GreenChannel.SourceChannelName = "2"; rasterSymbolizer2.ChannelSelection.GreenChannel.ContrastEnhancement.GammaValue = 2.5; rasterSymbolizer2.ChannelSelection.BlueChannel.SourceChannelName = "3"; rasterSymbolizer2.ColourMap.Interpolate.FallBackValue = "#dddddd"; rasterSymbolizer2.ColourMap.Interpolate.LookupValue = "Rasterdata"; rasterSymbolizer2.ColourMap.Interpolate.InterpolationPoints.Add(new InterpolationPoint(0, "#000000")); rasterSymbolizer2.ColourMap.Interpolate.InterpolationPoints.Add(new InterpolationPoint(255, "#ffffff")); rasterSymbolizer2.ContrastEnhancement.GammaValue = 1; rasterSymbolizer2.Geometry.PropertyName = "Coastlines"; symbolizers[5] = rasterSymbolizer2; symbolizerSelections[5] = SymbolizerTypes.RasterSymbolizer; rule1.SymbolizerSelections = symbolizerSelections; rule1.Symbolizers = symbolizers; featureTypeStyle1.Rules.Add(rule1); Rule rule2 = new Rule(); rule2.ElseFilter = new ElseFilter(); featureTypeStyle1.Rules.Add(rule2); Rule rule3 = new Rule(); GeospatialServices.Ogc.Wmc.PropertyIsEqualTo propEqualTo = new PropertyIsEqualTo(); propEqualTo.Literal.Value = "NEW YORK"; propEqualTo.PropertyName = "SALES_AREA"; //BaseComparisonOps ComparisonOps[] = new BaseComparisonOps[2]; rule3.Filter.FilterExpression = propEqualTo; featureTypeStyle1.Rules.Add(rule3); userStyle1.FeatureTypeStyles.Add(featureTypeStyle1); namedLayer.UserStyles.Add(userStyle1); // Context - > Layer -> Style -> User Layer UserLayer userLayer = new UserLayer(); userLayer.Name = "Lakes and Rivers"; UserStyle userStyle = new UserStyle("Default"); userStyle.FeatureTypeStyles.Add(featureTypeStyle1); userLayer.UserStyles = new List <UserStyle>(); userLayer.UserStyles.Add(userStyle); style1.SLD.StyledLayerDescriptor.NamedLayers.Add(namedLayer); style1.SLD.StyledLayerDescriptor.UserLayers.Add(userLayer); layer.StyleList.Add(style1); context.Layers.Add(layer); }
void CratePvPole(double xSpacing, IMapFeatureLayer BLineFeLyr) { project.NumPvPanel = 0; IMapRasterLayer demLyr; Raster dem4Pv = new Raster(); double poleH = 1; //Default pole height = 1 m. double z0 = 0; try { poleH = Convert.ToDouble(txtPoleHeight.Text); } catch { MessageBox.Show("Pole height value error"); txtPoleHeight.Text = "1"; poleH = 1; } if (project.LyrDEM != -1 & chkDEM.Checked == true) { demLyr = pvMap.Layers[project.LyrDEM] as IMapRasterLayer; if (demLyr == null) { MessageBox.Show("Error: DEM Data is not correct"); return; } int mRow = demLyr.Bounds.NumRows; int mCol = demLyr.Bounds.NumColumns; dem4Pv = (Raster)demLyr.DataSet; Coordinate ptReference = new Coordinate(project.UtmE, project.UtmN); RcIndex rc = dem4Pv.ProjToCell(ptReference); //RcIndex rc = demLyr.DataSet.ProjToCell(ptReference); if (rc.Column < 0 | rc.Row < 0) { z0 = 0; } else { z0 = dem4Pv.Value[rc.Row, rc.Column]; //z0 = demLyr.DataSet.Value[rc.Row, rc.Column]; } } //------------------------------------------------------------------------------------------------ // Create pole posion from baseline shapefile //------------------------------------------------------------------------------------------------ int nShp = BLineFeLyr.DataSet.NumRows(); // get Number of Feature double dx = xSpacing; //m. FeatureSet fs; fs = new FeatureSet(FeatureType.Point); //--------------------------------------------------------- fs.DataTable.Columns.Add(new DataColumn("x", typeof(double))); fs.DataTable.Columns.Add(new DataColumn("y", typeof(double))); fs.DataTable.Columns.Add(new DataColumn("w", typeof(double))); fs.DataTable.Columns.Add(new DataColumn("h", typeof(double))); fs.DataTable.Columns.Add(new DataColumn("Azimuth", typeof(double))); fs.DataTable.Columns.Add(new DataColumn("Ele_Angle", typeof(double))); fs.DataTable.Columns.Add(new DataColumn("ele", typeof(double))); //--------------------------------------------------------- for (int i = 0; i < nShp; i++) //Line shape { IFeature BLineFe = BLineFeLyr.DataSet.GetFeature(i); if (chkSystemSpacing.Checked == true) { dx = Convert.ToDouble(txtDx.Text); } else { try { object val = BLineFe.DataRow["spacing"]; dx = (double)val; if (dx <= 0) { MessageBox.Show("Error: Spacing data incorrect."); return; } } catch { MessageBox.Show("Error: Spacing data not found."); project.Verify[5] = false; return; } } xSpacing = dx; double sumSegment = 0; double sumL = 0; double iniSegment = 0; double LastSegment = 0; for (int n = 0; n < BLineFe.NumPoints - 1; n++) //Line segment { double x1 = BLineFe.Coordinates[n].X; double y1 = BLineFe.Coordinates[n].Y; double x2 = BLineFe.Coordinates[n + 1].X; double y2 = BLineFe.Coordinates[n + 1].Y; double LastL = sumL; double dL; sumL += Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2)); sumSegment = LastSegment; if (sumSegment + xSpacing <= sumL | sumSegment == 0) { for (double Segment = sumSegment; Segment <= sumL; Segment += xSpacing) { dL = Segment - LastL; Coordinate poleLocation = util.PointOnTheLine(x1, y1, x2, y2, dL); if (poleLocation != null) { LastSegment += xSpacing; double poleHeight = Convert.ToDouble(txtPoleHeight.Text); //Coordinate poleLocation = new Coordinate(pt.X, pt.Y, poleHeight); IPoint poleFe = new DotSpatial.Topology.Point(poleLocation); IFeature ifea = fs.AddFeature(poleFe); project.NumPvPanel++; //------------------------------------------------------ ifea.DataRow.BeginEdit(); ifea.DataRow["x"] = poleLocation.X; ifea.DataRow["y"] = poleLocation.Y; ifea.DataRow["w"] = 0; ifea.DataRow["h"] = 0; ifea.DataRow["Azimuth"] = 0; ifea.DataRow["Ele_Angle"] = 0; if (project.LyrDEM != -1 & chkDEM.Checked == true) { RcIndex rc = dem4Pv.ProjToCell(poleLocation); double z = 0; if (rc.Column < 0 | rc.Row < 0) { z = 0; } else { z = dem4Pv.Value[rc.Row, rc.Column]; } //demLyr.DataSet if (radioAboveAssumeDatum.Checked == true) { ifea.DataRow["ele"] = poleH; } else { ifea.DataRow["ele"] = z - z0 + poleH; } } else { ifea.DataRow["ele"] = poleH; } ifea.DataRow.EndEdit(); } } } } } // next alignment shape fs.Projection = pvMap.Projection; //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs.Name = "Panel Positon"; fs.Filename = project.Path + "\\Temp\\" + fs.Name + ".shp"; //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs.SaveAs(fs.Filename, true); util.removeDupplicateLyr(fs.Name, pvMap); PointSymbolizer p = new PointSymbolizer(Color.Yellow, DotSpatial.Symbology.PointShape.Hexagon, 6); p.ScaleMode = ScaleMode.Simple; MapPointLayer kasem = new MapPointLayer(fs); kasem.Symbolizer = p; pvMap.Layers.Add(kasem); //loadLayerList(); //pvMap.MapFrame.DrawingLayers.Clear(); util.ClearGraphicMap(pvMap); project.LyrPoleName = fs.Name; /* * MapPointLayer rangeRingAxis; * rangeRingAxis = new MapPointLayer(fs); * pvMap.MapFrame.DrawingLayers.Add(rangeRingAxis); * pvMap.MapFrame.Invalidate(); */ //project.Verify[5] = true; //updateArea(); }
public void TestLayerGetImage() { List <string> fileNames = new List <string>() { @"E:\LC\数据\line1.shp", //@"E:\LC\数据\polygon.shp" , //@"E:\LC\数据\双流\2014年裁剪影像.img" }; foreach (var fileName in fileNames) { using (var layer = LayerManager.Default.OpenLayer(fileName)) { if (layer is IFeatureLayer featureLayer) { var lineSymbolizer = featureLayer.DefaultCategory.Symbolizer as ILineSymbolizer; if (lineSymbolizer != null) { var marker = new PointSymbolizer(); marker.Symbols[0] = new PointSimpleSymbol(Color.Red, PointShape.Triangle, 10) { UseOutLine = false }; ILineSymbol symbol = new LineMarkerSymbol { Color = Color.Black, Width = 3, Marker = marker }; lineSymbolizer.Symbols[0] = symbol; lineSymbolizer.Symbols.Insert(0, new LineSimpleSymbol()); } } Rectangle rectangle = new Rectangle(0, 0, 256, 256); using (var image = new Bitmap(rectangle.Width, rectangle.Height)) { //var marker = new PointSymbolizer(); //marker.Symbols[0] = new PointSimpleSymbol(Color.Red, PointShape.Triangle, 10) //{ // UseOutLine = false //}; //SizeF size = marker.Size; //int imgWidth = (int)Math.Ceiling(size.Width); //int imgHeight = (int)Math.Ceiling(size.Height); ////Image markerImage = Image.Load(@"C:\Users\lc156\Desktop\arrow.png"); //Image markerImage = new Bitmap(imgWidth, imgHeight); //marker.Symbols[0].Angle = -45; //using (Graphics g = Graphics.FromImage(markerImage)) //{ // marker.DrawLegend(g, new Rectangle(0, 0, imgWidth, imgHeight)); //} //var brush = new TextureBrush(markerImage); //float[] dashPattern = null; //var pen = new Pen(brush, size.Height) //{ // DashPattern= dashPattern //}; //using (Graphics g = Graphics.FromImage(image)) //{ // var points = new PointF[] { new PointF(0, 255), new PointF(255, 0) }; // //var points = new PointF[] { new PointF(0, 0), new PointF(255, 255) }; // //var points = new PointF[] { new PointF(0, 128), new PointF(255, 128) }; // g.DrawLines(pen, points); // g.DrawLines(new Pen(Color.Blue, 1), points); // //marker.DrawPoint(x, 1, new PointF(128, 128)); // //lineSymbolizer.DrawLine(x, 1, new PointF[] { new PointF(0, 128), new PointF(128, 128) }.ToPath()); //} var extent = layer.Extent.Copy(); ViewHelper.GetViewEnvelope(extent, rectangle); using (Graphics g = Graphics.FromImage(image)) { MapArgs mapArgs = new MapArgs(rectangle, extent, g); layer.Draw(g, rectangle, extent); } image.Save(@"C:\Users\lc156\Desktop\tmp\123.png"); } } } }