public void TestBasicLineSymbolizer() { ShapeFile p = new ShapeFile(@"d:\\daten\GeoFabrik\\roads.shp", false); VectorLayer l = new VectorLayer("roads", p); //l.Style.Outline = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 5); l.Style.Line = new Pen(Color.Gold, 1); l.Style.EnableOutline = false; Map m = new Map(new Size(1440, 1080)) { BackColor = Color.Cornsilk }; m.Layers.Add(l); m.ZoomToExtents(); Stopwatch sw = new Stopwatch(); sw.Start(); m.GetMap(); sw.Stop(); Console.WriteLine(string.Format("Rendering old method: {0}ms", sw.ElapsedMilliseconds)); sw.Reset(); sw.Start(); Image bmp = m.GetMap(); sw.Stop(); Console.WriteLine(string.Format("Rendering old method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("NDSRoads1.bmp"); CachedLineSymbolizer cls = new CachedLineSymbolizer(); //cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.PlainLineSymbolizeHandler { Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 5) }); cls.LineSymbolizeHandlers.Add(new PlainLineSymbolizeHandler { Line = new Pen(Color.Gold, 1) }); l.Style.LineSymbolizer = cls; sw.Reset(); sw.Start(); bmp = m.GetMap(); sw.Stop(); Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("NDSRoads2.bmp"); }
private static Map InitializeMapWithSymbolizerLayers(float angle) { //Initialize a new map of size 'imagesize' Map map = new Map(); //Set up the countries layer var layCountries = new SharpMap.Layers.Symbolizer.PolygonalVectorLayer( "Countries", new ShapeFileEx("GeoData/World/countries.shp", true), new BasicPolygonSymbolizer {Fill = new SolidBrush(Color.Green), Outline = Pens.Black,} ) {SRID = 4326}; //Set up a river layer var symbolizer = new CachedLineSymbolizer(); symbolizer.LineSymbolizeHandlers.AddRange( new [] { new PlainLineSymbolizeHandler { Line = new Pen(Color.Blue, 3) { LineJoin = LineJoin.Round } }, new PlainLineSymbolizeHandler{ Line = new Pen(Color.Aqua, 1)}, }); var layRivers = new SharpMap.Layers.Symbolizer.LinealVectorLayer("Rivers") { //Set the datasource to a shapefile in the App_data folder DataSource = new ShapeFileEx("GeoData/World/rivers.shp", true), //Define a blue 2px wide pen Symbolizer = symbolizer, SRID = 4326 }; //Set up a cities layer var layCities = new SharpMap.Layers.Symbolizer.PuntalVectorLayer("Cities") { //Set the datasource to a shapefile in the App_data folder DataSource = new ShapeFileEx("GeoData/World/cities.shp", true), Symbolizer = new RasterPointSymbolizer() { Scale = 0.8f }, MaxVisible = 40 } ; //Set up a country label layer var layLabel = new LabelLayer("Country labels") { DataSource = layCountries.DataSource, Enabled = true, LabelColumn = "Name", Style = new LabelStyle { ForeColor = Color.White, Font = new Font(FontFamily.GenericSerif, 12), BackColor = new SolidBrush(Color.FromArgb(128, 255, 0, 0)), HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center }, MaxVisible = 90, MinVisible = 30, SRID = 4326, MultipartGeometryBehaviour = LabelLayer.MultipartGeometryBehaviourEnum.Largest, }; //Set up a city label layer var layCityLabel = new LabelLayer("City labels") { DataSource = layCities.DataSource, Enabled = true, LabelColumn = "Name", TextRenderingHint = TextRenderingHint.AntiAlias, SmoothingMode = SmoothingMode.AntiAlias, SRID = 4326, LabelFilter = LabelCollisionDetection.ThoroughCollisionDetection, Style = new LabelStyle { ForeColor = Color.Black, Font = new Font(FontFamily.GenericSerif, 11), HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left, VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Bottom, Offset = new PointF(3, 3), CollisionDetection = true, Halo = new Pen(Color.Yellow, 2) }, MaxVisible = layLabel.MinVisible, }; //Setup River label var layRiverLabel = new LabelLayer("River labels") { DataSource = layRivers.DataSource, Enabled = true, LabelColumn = "Name", TextRenderingHint = TextRenderingHint.AntiAlias, SmoothingMode = SmoothingMode.AntiAlias, SRID = 4326, LabelFilter = LabelCollisionDetection.ThoroughCollisionDetection, MultipartGeometryBehaviour = LabelLayer.MultipartGeometryBehaviourEnum.All, Style = new LabelStyle { ForeColor = Color.DarkBlue, Font = new Font("Arial", 11), HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center, VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Middle, //CollisionDetection = true, Halo = new Pen(Color.Azure, 2), IgnoreLength = true }, }; //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 map.Layers.Add(layCountries); map.Layers.Add(layRivers); map.Layers.Add(layCities); map.Layers.Add(layRiverLabel); map.Layers.Add(layLabel); map.Layers.Add(layCityLabel); //limit the zoom to 360 degrees width map.MaximumZoom = 360; map.BackColor = Color.LightBlue; map.Zoom = 360; map.Center = new Point(0, 0); Matrix mat = new Matrix(); mat.RotateAt(angle, map.WorldToImage(map.Center)); map.MapTransform = mat; return map; }
public void TestWarpedLineSymbolizer() { ShapeFile p = new ShapeFile(@"d:\\daten\GeoFabrik\\Aurich\\roads.shp", false); VectorLayer l = new VectorLayer("roads", p); CachedLineSymbolizer cls = new CachedLineSymbolizer(); cls.LineSymbolizeHandlers.Add(new PlainLineSymbolizeHandler { Line = new Pen(Color.Gold, 2) }); WarpedLineSymbolizeHander wls = new WarpedLineSymbolizeHander { Pattern = WarpedLineSymbolizer. GetGreaterSeries(3, 3), Line = new Pen(Color.Firebrick, 1) , Interval = 20 }; cls.LineSymbolizeHandlers.Add(wls); l.Style.LineSymbolizer = cls; Map m = new Map(new Size(720, 540)) { BackColor = Color.Cornsilk }; m.Layers.Add(l); m.ZoomToExtents(); Stopwatch sw = new Stopwatch(); sw.Start(); Image bmp = m.GetMap(); sw.Stop(); Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("AurichRoads1.bmp"); cls.LineSymbolizeHandlers[1] = new WarpedLineSymbolizeHander { Pattern = WarpedLineSymbolizer. GetTriangle(4, 0), Line = new Pen(Color.Firebrick, 1), Fill = new SolidBrush(Color.Firebrick) , Interval = 10 }; sw.Reset(); sw.Start(); bmp = m.GetMap(); sw.Stop(); Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("AurichRoads2-0.bmp"); cls.LineSymbolizeHandlers[1] = new WarpedLineSymbolizeHander { Pattern = WarpedLineSymbolizer. GetTriangle(4, 1), Line = new Pen(Color.Firebrick, 1), Fill = new SolidBrush(Color.Firebrick) , Interval = 10 }; sw.Reset(); sw.Start(); bmp = m.GetMap(); sw.Stop(); Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("AurichRoads2-1.bmp"); cls.LineSymbolizeHandlers[1] = new WarpedLineSymbolizeHander { Pattern = WarpedLineSymbolizer. GetTriangle(4, 2), Line = new Pen(Color.Firebrick, 1), Fill = new SolidBrush(Color.Firebrick) , Interval = 10 }; sw.Reset(); sw.Start(); bmp = m.GetMap(); sw.Stop(); Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("AurichRoads2-2.bmp"); cls.LineSymbolizeHandlers[1] = new WarpedLineSymbolizeHander { Pattern = WarpedLineSymbolizer. GetTriangle(4, 3), Line = new Pen(Color.Firebrick, 1), Fill = new SolidBrush(Color.Firebrick) , Interval = 10 }; sw.Reset(); sw.Start(); bmp = m.GetMap(); sw.Stop(); Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("AurichRoads2-3.bmp"); //cls.LineSymbolizeHandlers[0] = cls.LineSymbolizeHandlers[1]; cls.LineSymbolizeHandlers[1] = new WarpedLineSymbolizeHander { Pattern = WarpedLineSymbolizer.GetZigZag(4, 4), Line = new Pen(Color.Firebrick, 1), //Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Firebrick) }; sw.Reset(); sw.Start(); bmp = m.GetMap(); sw.Stop(); Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("AurichRoads3.bmp"); }
/// <summary> /// Returns the style based on a feature /// </summary> /// <param name="attribute">Set of attribute values to calculate the <see cref="SharpMap.Styles.IStyle"/> from</param> /// <returns>The style</returns> public IStyle GetStyle(IFeature attribute) { VectorStyle res = _style; CachedLineSymbolizer cls = new CachedLineSymbolizer(); cls.LineSymbolizeHandlers.Add(new PlainLineSymbolizeHandler { Line = new Pen(Color.Gold, 2) }); WarpedLineSymbolizeHander wls = new WarpedLineSymbolizeHander { Pattern = WarpedLineSymbolizer. GetGreaterSeries(3, 3), Line = new Pen(Color.Firebrick, 1) , Interval = 20 }; cls.LineSymbolizeHandlers.Add(wls); cls.ImmediateMode = true; res.LineSymbolizer = cls; return res; }