public void TestSymbolSelectionTheming() { //Create a map SharpMap.Map map = new SharpMap.Map(new System.Drawing.Size(720, 360)); //Create some random sample data SharpMap.Data.FeatureDataTable fdt = cd.CreatePointFeatureDataTableFromArrays(cd.GetRandomOrdinates(80, -180, 180), cd.GetRandomOrdinates(80, -90, 90), null); //Add rotation column and fill with random rotation values fdt.Columns.Add("Symbol", typeof(System.Byte[])); foreach (SharpMap.Data.FeatureDataRow row in fdt.Rows) row["Symbol"] = RandomSymbol((int)System.Math.Floor(cd.RandomNumberGenerator.NextDouble() * 360d)); //Create layer and datasource SharpMap.Layers.VectorLayer vl = new SharpMap.Layers.VectorLayer("Points", new SharpMap.Data.Providers.GeometryFeatureProvider(fdt)); //Create default style SharpMap.Styles.VectorStyle defaultStyle = new SharpMap.Styles.VectorStyle(); defaultStyle.Symbol = new System.Drawing.Bitmap(@"..\..\..\DemoWinForm\Resources\flag.png"); defaultStyle.SymbolScale = 0.5f; //Create theming class and apply to layer SymbolFromFeatureDataRowTheming srt = new SymbolFromFeatureDataRowTheming("Symbol", defaultStyle); vl.Theme = new SharpMap.Rendering.Thematics.CustomTheme(srt.GetRotatedSymol); map.Layers.Add(vl); map.ZoomToExtents(); System.Drawing.Image mapImage = map.GetMap(); mapImage.Save("SymbolFromFDR.bmp"); }
public MainWindow() : base(Gtk.WindowType.Toplevel) { try { GeoAPI.GeometryServiceProvider.Instance = new NtsGeometryServices(); Build(); Size mapSize = new Size(800, 500); myMap = new SharpMap.Map(mapSize); SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); style.Outline = new Pen(Color.Green, 1); style.EnableOutline = true; SharpMap.Layers.VectorLayer layWorld = new SharpMap.Layers.VectorLayer("States"); layWorld.DataSource = new SharpMap.Data.Providers.ShapeFile( @"data" + System.IO.Path.DirectorySeparatorChar + @"states.shp", true); layWorld.Style = style; myMap.Layers.Add(layWorld); myMap.MaximumZoom = 360; myMap.BackColor = Color.LightBlue; myMap.Center = new GeoAPI.Geometries.Coordinate(0, 0); myMap.Zoom = 360; Bitmap img = (Bitmap)myMap.GetMap(); image3.Pixbuf = ImageToPixbuf(img); } catch (Exception ex) { label1.Text = ex.Message; } }
public SharpMap.Styles.IStyle GetStyle(SharpMap.Data.FeatureDataRow fdr) { var retval = new SharpMap.Styles.VectorStyle(); if (fdr["Bearing"] == DBNull.Value) { var bmp = new System.Drawing.Bitmap(36, 36); using (var g = System.Drawing.Graphics.FromImage(bmp)) { g.Clear(System.Drawing.Color.Wheat); g.FillEllipse(System.Drawing.Brushes.Green, 0, 0, 36, 36); g.DrawEllipse(new System.Drawing.Pen(System.Drawing.Brushes.Yellow, 3), 4, 4, 28, 28); g.DrawString("H", new System.Drawing.Font("Arial", 18, System.Drawing.FontStyle.Bold), System.Drawing.Brushes.Yellow, new System.Drawing.RectangleF(2, 2, 34, 34), new System.Drawing.StringFormat { Alignment = System.Drawing.StringAlignment.Center, LineAlignment = System.Drawing.StringAlignment.Center }); } bmp.MakeTransparent(System.Drawing.Color.Wheat); retval.Symbol = bmp; } else { retval.Symbol = ColoredArrow(_brush); var rot = (Single)(Double)fdr["Bearing"]; retval.SymbolRotation = rot % 360f; } return(retval); }
public MainWindow() : base(Gtk.WindowType.Toplevel) { try { GeoAPI.GeometryServiceProvider.Instance = new NtsGeometryServices(); Build(); Size mapSize = new Size(800, 500); myMap = new SharpMap.Map(mapSize); SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); style.Outline = new Pen(Color.Green, 1); style.EnableOutline = true; SharpMap.Layers.VectorLayer layWorld = new SharpMap.Layers.VectorLayer("States"); layWorld.DataSource = new SharpMap.Data.Providers.ShapeFile( @"data" + System.IO.Path.DirectorySeparatorChar + @"states.shp", true); layWorld.Style = style; myMap.Layers.Add(layWorld); myMap.MaximumZoom = 360; myMap.BackColor = Color.LightBlue; myMap.Center = new GeoAPI.Geometries.Coordinate(0, 0); myMap.Zoom = 360; Bitmap img = (Bitmap)myMap.GetMap(); image3.Pixbuf = ImageToPixbuf(img); } catch (Exception ex) { label1.Text = ex.Message; } }
public static void Example2() { var map = new SharpMap.Map(new Size(1280, 1084)); SharpMap.Data.Providers.IProvider provider = new SharpMap.Data.Providers.ShapeFile( @"C:\temp\Data\niedersachsen.shp\railways.shp"); var style = new SharpMap.Styles.VectorStyle(); style.Line.Brush = Brushes.White; style.Line.DashPattern = new float[] { 4f, 4f }; style.Line.Width = 4; style.EnableOutline = true; style.Outline.Brush = Brushes.Black; style.Outline.Width = 6; var vl = new SharpMap.Layers.VectorLayer("Railways", provider) {Style = style}; map.Layers.Add(vl); var env = vl.Envelope; env.ExpandBy(-0.45f *env.Width, -0.45 * env.Height); map.ZoomToBox(env); var mapImage = map.GetMap(); mapImage.Save("Example2.png", System.Drawing.Imaging.ImageFormat.Png); }
private SharpMap.Styles.VectorStyle GetRoadCustomStyle(SharpMap.Data.FeatureDataRow row) { double zoom = MainMapImage.Map.Zoom; bool isPrimary = row["ROUTE_INTE"].ToString().Equals("14 (Primary Route)"); if (zoom > 10) { if (isPrimary) { SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); style.Line = new Pen(Color.DarkRed, 2.0f); return(style); } else { SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); style.Line = new Pen(Color.Transparent, 0.1f); return(style); } } else if (isPrimary) { SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); style.Line = new Pen(Color.DarkRed, 3.0f); return(style); } else { return(null); //Return null which will render the default style } }
//特征着色 private SharpMap.Styles.VectorStyle FeatureColoured(SharpMap.Data.FeatureDataRow row) { SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); string NAME = row["NAME"].ToString().ToLower(); if (NAME == featureName) { style.Fill = new System.Drawing.SolidBrush(Color.Green); style.Outline = new System.Drawing.Pen(Color.Transparent, 2); style.Line.Color = Color.Yellow; style.EnableOutline = true; return(style); } else { //style.Fill = new SolidBrush(Color.Transparent); //style.Outline = new Pen(Color.ForestGreen, 0.4f); //style.Line.Width = 1; //style.Line.Color = Color.Green; style.Fill = new System.Drawing.SolidBrush(Color.Transparent); style.Outline = new System.Drawing.Pen(Color.ForestGreen, 0.4f); style.Line.Color = Color.Green; style.EnableOutline = true; return(style); } }
/// <summary> /// 面状-公园绿地 /// </summary> /// <returns></returns> public static VectorStyle GreenParkStyle() { SharpMap.Styles.VectorStyle vs = new SharpMap.Styles.VectorStyle(); Brush brush = new SolidBrush(Color.FromArgb(199, 228, 185)); vs.Fill = brush; return(vs); }
/// <summary> /// 面状-空白地 /// </summary> /// <returns></returns> public static VectorStyle SpaceAreaStyle() { SharpMap.Styles.VectorStyle vs = new SharpMap.Styles.VectorStyle(); Brush brush = new SolidBrush(Color.FromArgb(240, 240, 240)); vs.Fill = brush; return(vs); }
/// <summary> /// 面状-蓝色河流 /// </summary> /// <returns></returns> public static VectorStyle BlueRiverStyle() { SharpMap.Styles.VectorStyle vs = new SharpMap.Styles.VectorStyle(); Brush brush = new SolidBrush(Color.FromArgb(153, 180, 207)); vs.Fill = brush; return(vs); }
public void TestRender() { var style = new SharpMap.Styles.GroupStyle(); var vStyle = new SharpMap.Styles.VectorStyle() { Enabled = true, PointColor = Brushes.Red, PointSize = 6 }; style.AddStyle(vStyle); vStyle = new SharpMap.Styles.VectorStyle() { Enabled = true, PointColor = Brushes.White, PointSize = 2, }; style.AddStyle(vStyle); Assert.AreEqual(2, style.Count); Assert.AreEqual(Color.Red, (style[0].PointColor as SolidBrush).Color); VectorLayer vLay = new VectorLayer("test"); vLay.Style = style; vLay.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; vLay.DataSource = new SharpMap.Data.Providers.GeometryProvider("POINT(0 0)"); Map m = new Map(new Size(11, 11)); m.BackColor = Color.White; m.ZoomToBox(new GeoAPI.Geometries.Envelope(-5, 5, -5, 5)); m.Layers.Add(vLay); var img = m.GetMap(); img.Save(@"c:\\temp\ren.png"); Bitmap bmp = img as Bitmap; Color c1 = bmp.GetPixel(5, 5); Assert.AreEqual(Color.White.ToArgb(), c1.ToArgb()); c1 = bmp.GetPixel(3, 5); Assert.AreEqual(Color.Red.ToArgb(), c1.ToArgb()); c1 = bmp.GetPixel(7, 5); Assert.AreEqual(Color.Red.ToArgb(), c1.ToArgb()); c1 = bmp.GetPixel(5, 3); Assert.AreEqual(Color.Red.ToArgb(), c1.ToArgb()); c1 = bmp.GetPixel(5, 7); Assert.AreEqual(Color.Red.ToArgb(), c1.ToArgb()); img.Dispose(); m.Dispose(); }
// This displays the GSHHG or GSHHS or whatever they call themselves this week world map. currently using the high def version // Note that these databases do not have meaningful attributes, so it is not possible to use a theme to display these // Instead, the rendoring style is assigned by layer. private void initializeToolStripMenuItem_Click(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; S57.InitializeBackgroundMap(ref mapBox1); #if false string GSHHGFileName = @"d:\Users\dwoodall\Documents\GSHHG\gshhg-shp-2.3.5-1\GSHHS_shp\f\GSHHS_f_L1.shp"; // this is the default area to be displayed. do not make it bigger unless you want to wait forever for it to render Envelope envelope = new Envelope(-75.0d, -80.0d, 23.0d, 28.0d); //ShapeFile GSHHGData = new ShapeFile(GSHHGFileName); SharpMap.Layers.VectorLayer GSHHGLayer = new SharpMap.Layers.VectorLayer("GSHHG"); GSHHGLayer.DataSource = new SharpMap.Data.Providers.ShapeFile(GSHHGFileName); //Create the style for Land SharpMap.Styles.VectorStyle landStyle = new SharpMap.Styles.VectorStyle(); landStyle.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.SaddleBrown); landStyle.Outline = new System.Drawing.Pen(System.Drawing.Color.Black); //Create the style for Water SharpMap.Styles.VectorStyle waterStyle = new SharpMap.Styles.VectorStyle(); waterStyle.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.LightBlue); //Create the default style SharpMap.Styles.VectorStyle defaultStyle = new SharpMap.Styles.VectorStyle(); defaultStyle.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Red); //Create the theme items Dictionary <string, SharpMap.Styles.IStyle> styles = new Dictionary <string, SharpMap.Styles.IStyle>(); styles.Add("land", landStyle); styles.Add("water", waterStyle); styles.Add("default", defaultStyle); //GSHHGLayer.Theme = null; GSHHGLayer.Style = landStyle; GSHHGLayer.Style.EnableOutline = true; //Console.WriteLine("GSHHG LayerName = " + GSHHGLayer.LayerName + " Theme = " + GSHHGLayer.Theme); //GSHHGLayer = S57.InitializeGSHHGMap(); mapBox1.Map.BackColor = System.Drawing.Color.LightBlue; mapBox1.Map.Layers.Add(GSHHGLayer); mapBox1.Map.ZoomToBox(envelope); mapBox1.Refresh(); mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan; #endif Cursor = Cursors.Default; }
public void TestRender() { var style = new SharpMap.Styles.GroupStyle(); var vStyle = new SharpMap.Styles.VectorStyle() { Enabled = true, PointColor = Brushes.Red, PointSize = 6 }; style.AddStyle(vStyle); vStyle = new SharpMap.Styles.VectorStyle() { Enabled = true, PointColor = Brushes.White, PointSize = 2 }; style.AddStyle(vStyle); Assert.AreEqual(2, style.Count); Assert.AreEqual(Color.Red, (style[0].PointColor as SolidBrush).Color); VectorLayer vLay = new VectorLayer("test"); vLay.Style = style; vLay.DataSource = new SharpMap.Data.Providers.FeatureProvider(GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory(4326).CreatePoint(new Coordinate(0, 0))); Map m = new Map(new Size(11, 11)); m.BackColor = Color.White; m.ZoomToBox(new GeoAPI.Geometries.Envelope(-5, 5, -5, 5)); m.Layers.Add(vLay); var img = m.GetMap(); //img.Save(@"c:\\temp\ren.png"); Bitmap bmp = img as Bitmap; Color c1 = bmp.GetPixel(5, 5); Assert.AreEqual(Color.White.ToArgb(), c1.ToArgb()); c1 = bmp.GetPixel(3, 5); Assert.AreEqual(Color.Red.ToArgb(), c1.ToArgb()); c1 = bmp.GetPixel(7, 5); Assert.AreEqual(Color.Red.ToArgb(), c1.ToArgb()); c1 = bmp.GetPixel(5, 3); Assert.AreEqual(Color.Red.ToArgb(), c1.ToArgb()); c1 = bmp.GetPixel(5, 7); Assert.AreEqual(Color.Red.ToArgb(), c1.ToArgb()); }
/// <summary> /// 线状-小路样式 /// </summary> /// <returns></returns> public static VectorStyle LittleRoadStyle() { SharpMap.Styles.VectorStyle vs = new SharpMap.Styles.VectorStyle(); System.Drawing.Pen pen0 = new Pen(Color.FromArgb(253, 253, 253), 3); System.Drawing.Pen pen1 = new Pen(Color.FromArgb(220, 220, 220), 5); Pen[] linePens = new Pen[2]; linePens[0] = pen1; linePens[1] = pen0; vs.Lines = linePens; return(vs); }
/// <summary> /// 线状-一级主干道样式 /// </summary> /// <returns></returns> public static VectorStyle Level1WayStyle() { SharpMap.Styles.VectorStyle vs = new SharpMap.Styles.VectorStyle(); System.Drawing.Pen pen0 = new Pen(Color.FromArgb(255, 238, 153), 5); System.Drawing.Pen pen1 = new Pen(Color.FromArgb(232, 193, 077), 8); Pen[] linePens = new Pen[2]; linePens[0] = pen1; linePens[1] = pen0; vs.Lines = linePens; return(vs); }
/// <summary> /// 线状-高速公路样式 /// </summary> /// <returns></returns> public static VectorStyle HightWayStyle() { SharpMap.Styles.VectorStyle vs = new SharpMap.Styles.VectorStyle(); System.Drawing.Pen pen0 = new Pen(Color.FromArgb(255, 187, 051), 5); System.Drawing.Pen pen1 = new Pen(Color.FromArgb(208, 161, 065), 8); Pen[] linePens = new Pen[2]; linePens[0] = pen1; linePens[1] = pen0; vs.Lines = linePens; return(vs); }
/// <summary> /// 线状-二级主干道样式 /// </summary> /// <returns></returns> public static VectorStyle Level2WayStyle() { SharpMap.Styles.VectorStyle vs = new SharpMap.Styles.VectorStyle(); System.Drawing.Pen pen0 = new Pen(Color.FromArgb(255, 255, 204), 4); System.Drawing.Pen pen1 = new Pen(Color.FromArgb(233, 214, 168), 7); Pen[] linePens = new Pen[2]; linePens[0] = pen1; linePens[1] = pen0; vs.Lines = linePens; return(vs); }
public SharpMap.Styles.VectorStyle GetRotatedSymol(GeoAPI.Features.IFeature row) { if (!System.String.IsNullOrEmpty(StyleRotationColumn)) { try { SharpMap.Styles.VectorStyle dataStyle = CloneStyle(DefaultStyle); dataStyle.SymbolRotation = System.Convert.ToSingle(row.Attributes[StyleRotationColumn]); return(dataStyle); } catch { } } return(null); }
public void TestRender() { var style = new SharpMap.Styles.GroupStyle(); var vStyle = new SharpMap.Styles.VectorStyle() { Enabled = true, PointColor = Brushes.Red, PointSize = 6 }; style.AddStyle(vStyle); vStyle = new SharpMap.Styles.VectorStyle() { Enabled = true, PointColor = Brushes.White, PointSize = 2 }; style.AddStyle(vStyle); Assert.AreEqual(2, style.Count); Assert.AreEqual(Color.Red, (style[0].PointColor as SolidBrush).Color); VectorLayer vLay = new VectorLayer("test"); vLay.Style = style; vLay.DataSource = new SharpMap.Data.Providers.GeometryProvider("POINT(0 0)"); Map m = new Map(new Size(11, 11)); m.BackColor = Color.White; m.ZoomToBox(new GeoAPI.Geometries.Envelope(-5, 5, -5, 5)); m.Layers.Add(vLay); var img = m.GetMap(); //img.Save(@"c:\\temp\ren.png"); Bitmap bmp = img as Bitmap; Color c1 = bmp.GetPixel(5, 5); Assert.AreEqual(Color.White.ToArgb(), c1.ToArgb()); c1 = bmp.GetPixel(3, 5); Assert.AreEqual(Color.Red.ToArgb(), c1.ToArgb()); c1 = bmp.GetPixel(7, 5); Assert.AreEqual(Color.Red.ToArgb(), c1.ToArgb()); c1 = bmp.GetPixel(5, 3); Assert.AreEqual(Color.Red.ToArgb(), c1.ToArgb()); c1 = bmp.GetPixel(5, 7); Assert.AreEqual(Color.Red.ToArgb(), c1.ToArgb()); }
public SharpMap.Styles.VectorStyle GetRotatedSymol(GeoAPI.Features.IFeature row) { if (!System.String.IsNullOrEmpty(SymbolColumn)) { try { SharpMap.Styles.VectorStyle dataStyle = CloneStyle(DefaultStyle); if (!row.IsNull(SymbolColumn)) { dataStyle.Symbol = new System.Drawing.Bitmap( new System.IO.MemoryStream((byte[])row.Attributes[SymbolColumn])); } return(dataStyle); } catch { } } return(null); }
private static SharpMap.Styles.VectorStyle CloneStyle(SharpMap.Styles.VectorStyle styleToClone) { SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle { Enabled = styleToClone.Enabled, MinVisible = styleToClone.MinVisible, MaxVisible = styleToClone.MaxVisible, Line = styleToClone.Line.Clone() as System.Drawing.Pen, Fill = styleToClone.Fill.Clone() as System.Drawing.Brush, Outline = styleToClone.Outline.Clone() as System.Drawing.Pen, EnableOutline = styleToClone.EnableOutline, Symbol = styleToClone.Symbol.Clone() as System.Drawing.Bitmap, SymbolOffset = styleToClone.SymbolOffset, SymbolRotation = styleToClone.SymbolRotation, SymbolScale = styleToClone.SymbolScale }; return(style); }
private static SharpMap.Styles.VectorStyle CloneStyle(SharpMap.Styles.VectorStyle styleToClone) { SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle { Enabled = styleToClone.Enabled, MinVisible = styleToClone.MinVisible, MaxVisible = styleToClone.MaxVisible, Line = styleToClone.Line.Clone() as System.Drawing.Pen, Fill = styleToClone.Fill.Clone() as System.Drawing.Brush, Outline = styleToClone.Outline.Clone() as System.Drawing.Pen, EnableOutline = styleToClone.EnableOutline, Symbol = styleToClone.Symbol.Clone() as System.Drawing.Bitmap, SymbolOffset = styleToClone.SymbolOffset, SymbolRotation = styleToClone.SymbolRotation, SymbolScale = styleToClone.SymbolScale }; return style; }
public void TestAddRemove() { var style = new SharpMap.Styles.GroupStyle(); var vStyle = new SharpMap.Styles.VectorStyle() { Enabled = true, PointColor = Brushes.Red, PointSize = 3 }; style.AddStyle(vStyle); vStyle = new SharpMap.Styles.VectorStyle() { Enabled = true, PointColor = Brushes.White, PointSize = 1 }; style.AddStyle(vStyle); Assert.AreEqual(2, style.Count); Assert.AreEqual(Color.Red, (style[0].PointColor as SolidBrush).Color); }
public void TestEnsureVisible() { //Create a map SharpMap.Map map = new SharpMap.Map(new System.Drawing.Size(720, 360)); //Create some random sample data SharpMap.Data.FeatureDataTable fdt = cd.CreatePointFeatureDataTableFromArrays(cd.GetRandomOrdinates(80, -180, 180), cd.GetRandomOrdinates(80, -90, 90), null); //Create layer and datasource SharpMap.Layers.VectorLayer vl = new SharpMap.Layers.VectorLayer("Points", new SharpMap.Data.Providers.GeometryFeatureProvider(fdt)); //Create default style SharpMap.Styles.VectorStyle defaultStyle = new SharpMap.Styles.VectorStyle(); defaultStyle.Symbol = new System.Drawing.Bitmap(@"..\..\..\DemoWinForm\Resources\flag.png"); defaultStyle.SymbolScale = 0.5f; //Create theming class and apply to layer SymbolRotationTheming srt = new SymbolRotationTheming("Rotation", defaultStyle); vl.Theme = new SharpMap.Rendering.Thematics.CustomTheme(srt.GetRotatedSymol); map.Layers.Add(vl); map.ZoomToExtents(); map.Zoom = 60; //2*30 map.Center = new SharpMap.Geometries.Point(0, 0); System.Console.WriteLine(map.Center); EnsureVisible(map, new SharpMap.Geometries.Point(-30, 0)); System.Console.WriteLine(map.Center); System.Console.WriteLine(); EnsureVisible(map, new SharpMap.Geometries.Point(15, 20)); System.Console.WriteLine(map.Center); System.Console.WriteLine(); EnsureVisible(map, new SharpMap.Geometries.Point(15, -20)); System.Console.WriteLine(map.Center); }
public static SharpMap.Layers.VectorLayer InitializeGSHHGMap() { SharpMap.Layers.VectorLayer GSHHGLayer = new SharpMap.Layers.VectorLayer("GSHHG"); GSHHGLayer.DataSource = new SharpMap.Data.Providers.ShapeFile(@"d:\Users\dwoodall\Documents\GSHHG\gshhg-shp-2.3.5-1\GSHHS_shp\f\GSHHS_f_L1.shp", true); //Create the style for Land SharpMap.Styles.VectorStyle landStyle = new SharpMap.Styles.VectorStyle(); landStyle.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(232, 232, 232)); //Create the style for Water SharpMap.Styles.VectorStyle waterStyle = new SharpMap.Styles.VectorStyle(); waterStyle.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(198, 198, 255)); //Create the theme items Dictionary <string, SharpMap.Styles.IStyle> styles = new Dictionary <string, SharpMap.Styles.IStyle>(); styles.Add("land", landStyle); styles.Add("water", waterStyle); //Assign the theme GSHHGLayer.Theme = new SharpMap.Rendering.Thematics.UniqueValuesTheme <string>("class", styles, landStyle); return(GSHHGLayer); //mapBox.Map.Layers.Add(vlay); //ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); //vlay.CoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator); //vlay.ReverseCoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator, ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84); //mapBox1.Map.BackgroundLayer.Add(new SharpMap.Layers.TileAsyncLayer( // new BruTile.Web.OsmTileSource(), "OSM")); //mapBox.Map.ZoomToExtents(); //mapBox.Refresh(); //mapBox.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan; //return mapBox; }
public void TestEnsureVisible() { //Create a map SharpMap.Map map = new SharpMap.Map(new System.Drawing.Size(720,360)); //Create some random sample data SharpMap.Data.FeatureDataTable fdt = cd.CreatePointFeatureDataTableFromArrays(cd.GetRandomOrdinates(80, -180, 180), cd.GetRandomOrdinates(80, -90, 90), null); //Create layer and datasource SharpMap.Layers.VectorLayer vl = new SharpMap.Layers.VectorLayer("Points", new SharpMap.Data.Providers.FeatureProvider(fdt)); //Create default style SharpMap.Styles.VectorStyle defaultStyle = new SharpMap.Styles.VectorStyle(); defaultStyle.Symbol = new System.Drawing.Bitmap(@"..\..\..\DemoWinForm\Resources\flag.png"); defaultStyle.SymbolScale = 0.5f; //Create theming class and apply to layer var srt = new SymbolRotationTheming("Rotation", defaultStyle); vl.Theme = new SharpMap.Rendering.Thematics.CustomTheme(srt.GetRotatedSymol); map.Layers.Add(vl); map.ZoomToExtents(); map.Zoom = 60; //2*30 map.Center = new GeoAPI.Geometries.Coordinate(0,0); System.Console.WriteLine(map.Center); EnsureVisible(map, new GeoAPI.Geometries.Coordinate(-30, 0)); System.Console.WriteLine(map.Center); System.Console.WriteLine(); EnsureVisible(map, new GeoAPI.Geometries.Coordinate(15, 20)); System.Console.WriteLine(map.Center); System.Console.WriteLine(); EnsureVisible(map, new GeoAPI.Geometries.Coordinate(15, -20)); System.Console.WriteLine(map.Center); }
//修改shp图层的外观,包括颜色和线宽 public void setShpLayer(string layername, Color color, int width) { ILayer layer = this.mapBox.Map.GetLayerByName(layername); if (layer != null) { SharpMap.Styles.VectorStyle vs = new SharpMap.Styles.VectorStyle(); //Line vs.Line.Color = color; vs.Line.Width = width; //Point vs.PointColor = new SolidBrush(color); vs.PointSize = width; //Polygon vs.Outline = new Pen(color, width); vs.Fill = new SolidBrush(Color.Transparent); vs.EnableOutline = true; (layer as VectorLayer).Style = vs; this.mapBox.Refresh(); } }
public void TestAddRemove() { var style = new SharpMap.Styles.GroupStyle(); var vStyle = new SharpMap.Styles.VectorStyle() { Enabled = true, PointColor = Brushes.Red, PointSize = 3 }; style.AddStyle(vStyle); vStyle = new SharpMap.Styles.VectorStyle() { Enabled = true, PointColor = Brushes.White, PointSize = 1 }; style.AddStyle(vStyle); Assert.AreEqual(2, style.Count); Assert.AreEqual(Color.Red, (style[0].PointColor as SolidBrush).Color); }
private SharpMap.Styles.VectorStyle GetStyleForShape(SharpMap.Data.FeatureDataRow row) { SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); if (bandStates.Contains(row.ItemArray[6])) { style.Fill = Brushes.Green; style.Outline = new Pen(Color.Black, 1); } else { style.Fill = Brushes.DarkRed; style.Outline = new Pen(Color.Black, 1); } if (!states.Contains(row.ItemArray[6])) //if (row.ItemArray[6].Equals("PR")) { style.Fill = Brushes.White; // ignore non-50 states for WAS award coloring style.Outline = new Pen(Color.White, 1); } //style.Line = new Pen(Color.Black, 1); style.EnableOutline = true; return(style); }
public static void Example2() { var map = new SharpMap.Map(new Size(1280, 1084)); SharpMap.Data.Providers.IProvider provider = new SharpMap.Data.Providers.ShapeFile( @"C:\temp\Data\niedersachsen.shp\railways.shp"); var style = new SharpMap.Styles.VectorStyle(); style.Line.Brush = Brushes.White; style.Line.DashPattern = new float[] { 4f, 4f }; style.Line.Width = 4; style.EnableOutline = true; style.Outline.Brush = Brushes.Black; style.Outline.Width = 6; var vl = new SharpMap.Layers.VectorLayer("Railways", provider) { Style = style }; map.Layers.Add(vl); var env = vl.Envelope; env.ExpandBy(-0.45f * env.Width, -0.45 * env.Height); map.ZoomToBox(env); var mapImage = map.GetMap(); mapImage.Save("Example2.png", System.Drawing.Imaging.ImageFormat.Png); }
public void TestSymbolSelectionTheming() { //Create a map SharpMap.Map map = new SharpMap.Map(new System.Drawing.Size(720, 360)); //Create some random sample data SharpMap.Data.FeatureDataTable fdt = cd.CreatePointFeatureDataTableFromArrays(cd.GetRandomOrdinates(80, -180, 180), cd.GetRandomOrdinates(80, -90, 90), null); //Add rotation column and fill with random rotation values fdt.Columns.Add("Symbol", typeof(System.Byte[])); foreach (SharpMap.Data.FeatureDataRow row in fdt.Rows) { row["Symbol"] = RandomSymbol((int)System.Math.Floor(cd.RandomNumberGenerator.NextDouble() * 360d)); } //Create layer and datasource SharpMap.Layers.VectorLayer vl = new SharpMap.Layers.VectorLayer("Points", new SharpMap.Data.Providers.FeatureProvider(fdt)); //Create default style SharpMap.Styles.VectorStyle defaultStyle = new SharpMap.Styles.VectorStyle(); defaultStyle.Symbol = new System.Drawing.Bitmap(@"..\..\..\DemoWinForm\Resources\flag.png"); defaultStyle.SymbolScale = 0.5f; //Create theming class and apply to layer SymbolFromFeatureDataRowTheming srt = new SymbolFromFeatureDataRowTheming("Symbol", defaultStyle); vl.Theme = new SharpMap.Rendering.Thematics.CustomTheme(srt.GetRotatedSymol); map.Layers.Add(vl); map.ZoomToExtents(); System.Drawing.Image mapImage = map.GetMap(); mapImage.Save("SymbolFromFDR.bmp"); }
public SharpMap.Styles.IStyle GetStyle(SharpMap.Data.FeatureDataRow fdr) { var retval = new SharpMap.Styles.VectorStyle(); if (fdr["Bearing"] == DBNull.Value) { var bmp = new System.Drawing.Bitmap(36, 36); using (var g = System.Drawing.Graphics.FromImage(bmp)) { g.Clear(System.Drawing.Color.Wheat); g.FillEllipse(System.Drawing.Brushes.Green, 0, 0, 36, 36); g.DrawEllipse(new System.Drawing.Pen(System.Drawing.Brushes.Yellow, 3), 4, 4, 28, 28); g.DrawString("H", new System.Drawing.Font("Arial", 18, System.Drawing.FontStyle.Bold), System.Drawing.Brushes.Yellow, new System.Drawing.RectangleF(2, 2, 34, 34), new System.Drawing.StringFormat { Alignment = System.Drawing.StringAlignment.Center, LineAlignment = System.Drawing.StringAlignment.Center }); } bmp.MakeTransparent(System.Drawing.Color.Wheat); retval.Symbol = bmp; } else { retval.Symbol = ColoredArrow(_brush); var rot = (Single)(Double)fdr["Bearing"]; retval.SymbolRotation = rot % 360f; } return retval; }
private void LoadParcels(List<PointD> pt, Color color, string labelname) { SharpMap.Map map = new SharpMap.Map(); List<GeoAPI.Geometries.Coordinate> vertices = new List<GeoAPI.Geometries.Coordinate>(); foreach (PointD i in pt) { GeoAPI.Geometries.Coordinate p = new GeoAPI.Geometries.Coordinate(); p.X = i.X; p.Y = i.Y; vertices.Add(p); } GeoAPI.Geometries.Coordinate l = new GeoAPI.Geometries.Coordinate(); l.X = pt[0].X; l.Y = pt[0].Y; vertices.Add(l); //Collection<GeoAPI.Geometries.IGeometry> geom = new Collection<GeoAPI.Geometries.IGeometry>(); GeometryFactory gf = new NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.ILinearRing shell = gf.CreateLinearRing(vertices.ToArray()); GeoAPI.Geometries.IPolygon polygon = gf.CreatePolygon(shell, null); SharpMap.Data.Providers.GeometryProvider geomProvider= new SharpMap.Data.Providers.GeometryProvider(polygon); SharpMap.Layers.VectorLayer layerParcels = new SharpMap.Layers.VectorLayer("Parcels"); SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); style.Fill = new SolidBrush(Color.FromArgb(200,color)); style.Outline = new Pen(new SolidBrush(color)); layerParcels.Style = style; layerParcels.Style.EnableOutline = true; layerParcels.DataSource = geomProvider; layerParcels.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan; var fdt = new SharpMap.Data.FeatureDataTable(); fdt.Columns.Add(new System.Data.DataColumn("id", typeof(uint))); fdt.Columns.Add(new System.Data.DataColumn("label", typeof(string))); var fdr = (SharpMap.Data.FeatureDataRow)fdt.NewRow(); fdr.ItemArray = new object[] { 1, labelname }; fdr.Geometry = polygon; fdt.AddRow(fdr); var dataprovider = new SharpMap.Data.Providers.GeometryFeatureProvider(fdt); var ll = new SharpMap.Layers.LabelLayer("llayer"); ll.DataSource = dataprovider; ll.LabelColumn = "label"; ll.Style.Font = new Font("Eurostile Extended", 16,FontStyle.Bold); mapBox1.Map.Layers.Add(layerParcels); mapBox1.Map.Layers.Add(ll); mapBox1.Map.ZoomToExtents(); mapBox1.Refresh(); }
public ClsTheme(SharpMap.Styles.VectorStyle style) { _style = style; }
private SharpMap.Styles.VectorStyle ReferenciasStyle(SharpMap.Data.FeatureDataRow row) { SharpMap.Styles.VectorStyle style; switch (row["TYPE"].ToString()) { case "Cargadero": style = LoadStyle(GetFileNameFromConfig("Simbolo_Cargadero")); break; case "Cruce": style = LoadStyle(GetFileNameFromConfig("Simbolo_Cruce")); break; case "Canchon": style = LoadStyle(GetFileNameFromConfig("Simbolo_Canchon")); break; case "Puente": style = LoadStyle(GetFileNameFromConfig("Simbolo_Puente")); break; case "Acceso": style = LoadStyle(GetFileNameFromConfig("Simbolo_Acceso")); break; case "Proveedor": style = LoadStyle(GetFileNameFromConfig("Simbolo_Proveedor")); break; default: { style = new SharpMap.Styles.VectorStyle(); style.Line.Color = System.Drawing.Color.Black; } break; } return style; }
private SharpMap.Styles.VectorStyle LoadStyle(string filename) { SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); if (System.IO.File.Exists(filename)) { string fileExtension = System.IO.Path.GetExtension(filename).ToLower(); switch (fileExtension) { case ".png": case ".jpg": case ".gif": case ".bmp": style.Symbol = new System.Drawing.Bitmap(filename, true); break; case ".ico": System.Drawing.Icon icon = new System.Drawing.Icon(filename); style.Symbol = icon.ToBitmap(); break; default: style.Line.Color = System.Drawing.Color.Black; break; } } else { style.Line.Color = System.Drawing.Color.Black; } return style; }
public static void InitializeBackgroundMap(ref SharpMap.Forms.MapBox mapBox1) { string GSHHGFileName = @"d:\Users\dwoodall\Documents\GSHHG\gshhg-shp-2.3.5-1\GSHHS_shp\f\GSHHS_f_L1.shp"; // this is the default area to be displayed. do not make it bigger unless you want to wait forever for it to render GeoAPI.Geometries.Envelope envelope = new GeoAPI.Geometries.Envelope(-75.0d, -80.0d, 23.0d, 28.0d); //ShapeFile GSHHGData = new ShapeFile(GSHHGFileName); SharpMap.Layers.VectorLayer GSHHGLayer = new SharpMap.Layers.VectorLayer("GSHHG"); GSHHGLayer.DataSource = new SharpMap.Data.Providers.ShapeFile(GSHHGFileName, true); if (!GSHHGLayer.DataSource.IsOpen) { GSHHGLayer.DataSource.Open(); } //Create the style for Land SharpMap.Styles.VectorStyle landStyle = new SharpMap.Styles.VectorStyle(); landStyle.Fill = new System.Drawing.SolidBrush(S52.colorMaptoRGBI(S52.ColorName.LANDF)); landStyle.Outline = new System.Drawing.Pen(System.Drawing.Color.Black); //Create the style for Water SharpMap.Styles.VectorStyle waterStyle = new SharpMap.Styles.VectorStyle(); waterStyle.Fill = new System.Drawing.SolidBrush(S52.colorMaptoRGBI(S52.ColorName.DEPMD)); //Create the default style SharpMap.Styles.VectorStyle defaultStyle = new SharpMap.Styles.VectorStyle(); defaultStyle.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Red); //Create the theme items Dictionary <string, SharpMap.Styles.IStyle> styles = new Dictionary <string, SharpMap.Styles.IStyle>(); styles.Add("land", landStyle); styles.Add("water", waterStyle); styles.Add("default", defaultStyle); GSHHGLayer.Style = landStyle; GSHHGLayer.Style.EnableOutline = true; mapBox1.BackColor = S52.colorMaptoRGB(S52.ColorName.UINFB); mapBox1.Map.Layers.Add(GSHHGLayer); mapBox1.Map.ZoomToExtents(); mapBox1.Refresh(); GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformationFactory ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); GSHHGLayer.CoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator); GSHHGLayer.ReverseCoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator, ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84); //mapBox1.Map.BackgroundLayer.Add(new SharpMap.Layers.TileAsyncLayer( // new BruTile.Web.OsmTileSource(), "OSM")); //mapBox1.Map.ZoomToBox(envelope); mapBox1.Map.ZoomToExtents(); mapBox1.Refresh(); mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan; }
/// <summary> /// Creates an instance of this class /// </summary> /// <param name="styleRotationColumn">Name of the column, which contains the symbol</param> /// <param name="defaultStyle">Default vector style from which parts are to be modified</param> public SymbolFromFeatureDataRowTheming(System.String styleRotationColumn, SharpMap.Styles.VectorStyle defaultStyle) { SymbolColumn = styleRotationColumn; DefaultStyle = defaultStyle; }
/// <summary> /// Creates an instance of this class /// </summary> /// <param name="styleRotationColumn">Name of the column, which contains the rotation angle in degrees [0°, 360°]</param> /// <param name="defaultStyle">Default vector style from which parts are to be modified</param> public SymbolRotationTheming(System.String styleRotationColumn, SharpMap.Styles.VectorStyle defaultStyle) { StyleRotationColumn = styleRotationColumn; DefaultStyle = defaultStyle; }
private SharpMap.Styles.VectorStyle CaminosStyle(SharpMap.Data.FeatureDataRow row) { SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); switch (row["TYPE"].ToString()) { case "Camino Principal": style.Line.Color = System.Drawing.Color.Brown; break; case "Camino Secundario": style.Line.Color = System.Drawing.Color.DarkGray; break; case "Ruta Provincial": style.Line.Color = System.Drawing.Color.Orange; break; case "Ruta Nacional": style.Line.Color = System.Drawing.Color.Yellow; style.Line.Width = 2; break; case "Sin Especificar": default: style.Line.Color = System.Drawing.Color.Black; break; } return style; }
/// <summary> /// Creates an instance of this class /// </summary> /// <param name="styleRotationColumn">Name of the column, which contains the rotation angle in degrees [0°, 360°]</param> /// <param name="defaultStyle">Default vector style from which parts are to be modified</param> public SymbolRotationTheming(System.String styleRotationColumn, SharpMap.Styles.VectorStyle defaultStyle) { StyleRotationColumn = styleRotationColumn; DefaultStyle = defaultStyle; }
private void RenderGeometry(System.Drawing.Graphics g, Map map, Geometry feature, SharpMap.Styles.VectorStyle style) { switch (feature.GetType().FullName) { case "SharpMap.Geometries.Polygon": if (style.EnableOutline) { SharpMap.Rendering.VectorRenderer.DrawPolygon(g, (Polygon)feature, style.Fill, style.Outline, _ClippingEnabled, map); } else { SharpMap.Rendering.VectorRenderer.DrawPolygon(g, (Polygon)feature, style.Fill, null, _ClippingEnabled, map); } break; case "SharpMap.Geometries.MultiPolygon": if (style.EnableOutline) { SharpMap.Rendering.VectorRenderer.DrawMultiPolygon(g, (MultiPolygon)feature, style.Fill, style.Outline, _ClippingEnabled, map); } else { SharpMap.Rendering.VectorRenderer.DrawMultiPolygon(g, (MultiPolygon)feature, style.Fill, null, _ClippingEnabled, map); } break; case "SharpMap.Geometries.LineString": SharpMap.Rendering.VectorRenderer.DrawLineString(g, (LineString)feature, style.Line, map); break; case "SharpMap.Geometries.MultiLineString": SharpMap.Rendering.VectorRenderer.DrawMultiLineString(g, (MultiLineString)feature, style.Line, map); break; case "SharpMap.Geometries.Point": SharpMap.Rendering.VectorRenderer.DrawPoint(g, (Point)feature, style.Symbol, style.SymbolScale, style.SymbolOffset, style.SymbolRotation, map); break; case "SharpMap.Geometries.MultiPoint": SharpMap.Rendering.VectorRenderer.DrawMultiPoint(g, (MultiPoint)feature, style.Symbol, style.SymbolScale, style.SymbolOffset, style.SymbolRotation, map); break; case "SharpMap.Geometries.GeometryCollection": foreach (Geometries.Geometry geom in (GeometryCollection)feature) { RenderGeometry(g, map, geom, style); } break; default: break; } }
/// <summary> /// Renders the layer to a graphics object /// </summary> /// <param name="g">Graphics object reference</param> /// <param name="map">Map which is rendered</param> public override void Render(System.Drawing.Graphics g, Map map) { if (map.Center == null) { throw (new ApplicationException("Cannot render map. View center not specified")); } g.SmoothingMode = this.SmoothingMode; SharpMap.Geometries.BoundingBox envelope = map.Envelope; //View to render if (this.CoordinateTransformation != null) { envelope = SharpMap.CoordinateSystems.Transformations.GeometryTransform.TransformBox(envelope, this.CoordinateTransformation.MathTransform.Inverse()); } //List<SharpMap.Geometries.Geometry> features = this.DataSource.GetGeometriesInView(map.Envelope); if (this.DataSource == null) { throw (new ApplicationException("DataSource property not set on layer '" + this.LayerName + "'")); } //If thematics is enabled, we use a slighty different rendering approach if (this.Theme != null) { SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet(); this.DataSource.Open(); this.DataSource.ExecuteIntersectionQuery(envelope, ds); this.DataSource.Close(); SharpMap.Data.FeatureDataTable features = (SharpMap.Data.FeatureDataTable)ds.Tables[0]; if (this.CoordinateTransformation != null) { for (int i = 0; i < features.Count; i++) { features[i].Geometry = SharpMap.CoordinateSystems.Transformations.GeometryTransform.TransformGeometry(features[i].Geometry, this.CoordinateTransformation.MathTransform); } } //Linestring outlines is drawn by drawing the layer once with a thicker line //before drawing the "inline" on top. if (Style.EnableOutline) { //foreach (SharpMap.Geometries.Geometry feature in features) for (int i = 0; i < features.Count; i++) { SharpMap.Data.FeatureDataRow feature = features[i]; //Draw background of all line-outlines first if (feature.Geometry is SharpMap.Geometries.LineString) { SharpMap.Styles.VectorStyle outlinestyle1 = this.Theme.GetStyle(feature) as SharpMap.Styles.VectorStyle; if (outlinestyle1.Enabled && outlinestyle1.EnableOutline) { SharpMap.Rendering.VectorRenderer.DrawLineString(g, feature.Geometry as LineString, outlinestyle1.Outline, map); } } else if (feature.Geometry is SharpMap.Geometries.MultiLineString) { SharpMap.Styles.VectorStyle outlinestyle2 = this.Theme.GetStyle(feature) as SharpMap.Styles.VectorStyle; if (outlinestyle2.Enabled && outlinestyle2.EnableOutline) { SharpMap.Rendering.VectorRenderer.DrawMultiLineString(g, feature.Geometry as MultiLineString, outlinestyle2.Outline, map); } } } } for (int i = 0; i < features.Count; i++) { SharpMap.Data.FeatureDataRow feature = features[i]; SharpMap.Styles.VectorStyle style = this.Theme.GetStyle(feature) as SharpMap.Styles.VectorStyle; RenderGeometry(g, map, feature.Geometry, style); } } else { this.DataSource.Open(); Collection <SharpMap.Geometries.Geometry> geoms = this.DataSource.GetGeometriesInView(envelope); this.DataSource.Close(); if (this.CoordinateTransformation != null) { for (int i = 0; i < geoms.Count; i++) { geoms[i] = SharpMap.CoordinateSystems.Transformations.GeometryTransform.TransformGeometry(geoms[i], this.CoordinateTransformation.MathTransform); } } //Linestring outlines is drawn by drawing the layer once with a thicker line //before drawing the "inline" on top. if (this.Style.EnableOutline) { foreach (SharpMap.Geometries.Geometry geom in geoms) { if (geom != null) { //Draw background of all line-outlines first switch (geom.GetType().FullName) { case "SharpMap.Geometries.LineString": SharpMap.Rendering.VectorRenderer.DrawLineString(g, geom as LineString, this.Style.Outline, map); break; case "SharpMap.Geometries.MultiLineString": SharpMap.Rendering.VectorRenderer.DrawMultiLineString(g, geom as MultiLineString, this.Style.Outline, map); break; default: break; } } } } for (int i = 0; i < geoms.Count; i++) { if (geoms[i] != null) { RenderGeometry(g, map, geoms[i], this.Style); } } } base.Render(g, map); }
//特征着色 private SharpMap.Styles.VectorStyle FeatureColoured(SharpMap.Data.FeatureDataRow row) { SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); string NAME = row["NAME"].ToString().ToLower(); if (NAME == featureName) { style.Fill = new System.Drawing.SolidBrush(Color.Green); style.Outline = new System.Drawing.Pen(Color.Transparent, 2); style.Line.Color = Color.Yellow; style.EnableOutline = true; return style; } else { //style.Fill = new SolidBrush(Color.Transparent); //style.Outline = new Pen(Color.ForestGreen, 0.4f); //style.Line.Width = 1; //style.Line.Color = Color.Green; style.Fill = new System.Drawing.SolidBrush(Color.Transparent); style.Outline = new System.Drawing.Pen(Color.ForestGreen, 0.4f); style.Line.Color = Color.Green; style.EnableOutline = true; return style; } }
public void LoadAndDrawData() { this.MainMapImage.Map.BackColor = Color.LightBlue; this.MainMapImage.Map.Center = new SharpMap.Geometries.Point(-4, 40); //Set center of map this.MainMapImage.Map.Zoom = 12; //Set zoom level this.MainMapImage.Map.Size = new System.Drawing.Size(1000, 1000); //Set output size //Set up the countries layer SharpMap.Layers.VectorLayer layCountries = new SharpMap.Layers.VectorLayer("Countries"); //Set the datasource to a shapefile in the App_data folder layCountries.DataSource = new SharpMap.Data.Providers.ShapeFile(@"Data\coastlines.shp"); //Set fill-style to green layCountries.Style.Fill = new SolidBrush(Color.Black); //Set the polygons to have a black outline layCountries.Style.Outline = System.Drawing.Pens.Black; layCountries.Style.EnableOutline = true; layCountries.SRID = 4321; //Set up a political area layer SharpMap.Layers.VectorLayer layArea = new SharpMap.Layers.VectorLayer("Areas"); //Set the datasource to a shapefile in the App_data folder layArea.DataSource = new SharpMap.Data.Providers.ShapeFile(@"Data\areas.shp"); //Define a blue 1px wide pen layArea.Style.Line = new Pen(Color.Red, 10.4f); layArea.Style.Fill = new SolidBrush(Color.Beige); layArea.SRID = 4322; //Set up a road layer SharpMap.Layers.VectorLayer layRoads = new SharpMap.Layers.VectorLayer("Roads"); //Set the datasource to a shapefile in the App_data folder layRoads.DataSource = new SharpMap.Data.Providers.ShapeFile(@"Data\roads.shp"); //Define a blue 1px wide pen layRoads.Style.Line = new Pen(Color.Red, 2.0f); layRoads.MaxVisible = 15; layRoads.SRID = 4323; SharpMap.Rendering.Thematics.CustomTheme iTheme = new SharpMap.Rendering.Thematics.CustomTheme(GetRoadCustomStyle); SharpMap.Styles.VectorStyle defaultstyle = new SharpMap.Styles.VectorStyle(); //Create default renderstyle defaultstyle.Line = new Pen(Color.Red, 0.5f); iTheme.DefaultStyle = defaultstyle; layRoads.Theme = iTheme; SharpMap.Layers.VectorLayer layCities = new SharpMap.Layers.VectorLayer("Cities"); //Set the datasource to a shapefile in the App_data folder layCities.DataSource = new SharpMap.Data.Providers.ShapeFile(@"Data\cities.shp"); //Define a blue 1px wide pen layCities.Style.Symbol = new Bitmap(@"Data\city.png"); layCities.Style.SymbolScale = 1.8f; layCities.MaxVisible = 10; layCities.SRID = 4324; //Set up a river layer SharpMap.Layers.VectorLayer layRivers = new SharpMap.Layers.VectorLayer("Rivers"); //Set the datasource to a shapefile in the App_data folder layRivers.DataSource = new SharpMap.Data.Providers.ShapeFile(@"Data\rivers.shp"); //Define a blue 1px wide pen layRivers.Style.Line = new Pen(Color.Blue, 0.4f); layRivers.MaxVisible = 7; layRivers.SRID = 4325; //Add the layers to the map object. //The order we add them in are the order they are drawn, so we add the rivers last to put them on top MainMapImage.Map.Layers.Add(layCountries); MainMapImage.Map.Layers.Add(layArea); MainMapImage.Map.Layers.Add(layRivers); MainMapImage.Map.Layers.Add(layRoads); MainMapImage.Map.Layers.Add(layCities); MainMapImage.Map.Center = new SharpMap.Geometries.Point(-4, 40); //Set center of map MainMapImage.Map.Zoom = 12; //Set zoom level MainMapImage.Map.Size = new System.Drawing.Size(1000, 1000); //Set output size MainMapImage.ActiveTool = SharpMap.Forms.MapImage.Tools.Pan; MainMapImage.WheelZoomMagnitude = 1.5; MainMapImage.Refresh(); }
public ClsTheme(SharpMap.Styles.VectorStyle style) { _style = style; }
// demonstratas the use of dynamic styles (themes) for vector layers private SharpMap.Styles.VectorStyle GetCountryStyle(SharpMap.Data.FeatureDataRow row) { // set a linear gradient brush for each country according to the bounding pixel rectangle SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); Color c = SharpMap.Rendering.Thematics.ColorBlend.Rainbow7.GetColor((float)((System.Convert.ToDouble(row["KK_KAT"]) - 1.0) / 6.0)); c = Color.FromArgb(180, c.R, c.G, c.B); style.Fill = new SolidBrush(c); // set the border width depending on the map scale Pen pen = new Pen(Brushes.Black, (int)(50.0 / map.PixelSize)); pen.LineJoin = LineJoin.Round; style.Outline = pen; style.EnableOutline = true; return style; }
//修改shp图层的外观,包括颜色和线宽 public void setShpLayer(string layername, Color color, int width) { ILayer layer = this.mapBox.Map.GetLayerByName(layername); if (layer != null) { SharpMap.Styles.VectorStyle vs = new SharpMap.Styles.VectorStyle(); //Line vs.Line.Color = color; vs.Line.Width = width; //Point vs.PointColor = new SolidBrush(color); vs.PointSize = width; //Polygon vs.Outline = new Pen(color, width); vs.Fill = new SolidBrush(Color.Transparent); vs.EnableOutline = true; (layer as VectorLayer).Style = vs; this.mapBox.Refresh(); } }
/// <summary> /// Creates an instance of this class /// </summary> /// <param name="styleRotationColumn">Name of the column, which contains the symbol</param> /// <param name="defaultStyle">Default vector style from which parts are to be modified</param> public SymbolFromFeatureDataRowTheming(System.String styleRotationColumn, SharpMap.Styles.VectorStyle defaultStyle) { SymbolColumn = styleRotationColumn; DefaultStyle = defaultStyle; }
private SharpMap.Styles.VectorStyle GetRoadCustomStyle(SharpMap.Data.FeatureDataRow row) { double zoom = MainMapImage.Map.Zoom; bool isPrimary = row["ROUTE_INTE"].ToString().Equals("14 (Primary Route)"); if (zoom > 10) { if (isPrimary) { SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); style.Line = new Pen(Color.DarkRed, 2.0f); return style; } else { SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); style.Line = new Pen(Color.Transparent, 0.1f); return style; } } else if (isPrimary) { SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); style.Line = new Pen(Color.DarkRed, 3.0f); return style; } else return null; //Return null which will render the default style }