public void TestPlainPolygonSymbolizer(string filePath) { filePath = filePath.Replace("\\", new string(System.IO.Path.DirectorySeparatorChar, 1)); if (!System.IO.File.Exists(filePath)) { throw new NUnit.Framework.IgnoreException($"'{filePath}' not found"); } var provider = new SharpMap.Data.Providers.ShapeFile(filePath, true); var l = new SharpMap.Layers.Symbolizer.PolygonalVectorLayer("Countries", provider); l.Symbolizer = new ModifiedBasicPolygonSymbolizer { Fill = new System.Drawing.Drawing2D.HatchBrush( System.Drawing.Drawing2D.HatchStyle.WideDownwardDiagonal, System.Drawing.Color.Red /*, * System.Drawing.Color.LightPink*/), UseClipping = false, //Outline = System.Drawing.Pens.AliceBlue }; var m = new SharpMap.Map(new System.Drawing.Size(1440, 1080)) { BackColor = System.Drawing.Color.Cornsilk }; m.Layers.Add(l); m.ZoomToExtents(); var sw = new System.Diagnostics.Stopwatch(); var img = m.GetMap(); sw.Start(); img = m.GetMap(); img.Save(System.IO.Path.Combine(UnitTestsFixture.GetImageDirectory(this), "PolygonSymbolizer-1.bmp"), System.Drawing.Imaging.ImageFormat.Bmp); sw.Stop(); System.Diagnostics.Trace.WriteLine(string.Format("Rendering new method:{0}ms", sw.ElapsedMilliseconds)); l.Symbolizer = new SharpMap.Rendering.Symbolizer.BasicPolygonSymbolizer() { Fill = new System.Drawing.Drawing2D.HatchBrush( System.Drawing.Drawing2D.HatchStyle.WideDownwardDiagonal, System.Drawing.Color.Red /*, * System.Drawing.Color.LightPink*/), UseClipping = false, //Outline = System.Drawing.Pens.AliceBlue }; sw.Reset(); sw.Start(); img = m.GetMap(); img.Save(System.IO.Path.Combine(UnitTestsFixture.GetImageDirectory(this), "PolygonSymbolizer-2.bmp"), System.Drawing.Imaging.ImageFormat.Bmp); sw.Stop(); System.Diagnostics.Trace.WriteLine(string.Format("Rendering new method:{0}ms", sw.ElapsedMilliseconds)); }
public void TestPlainPolygonSymbolizer() { var provider = new SharpMap.Data.Providers.ShapeFile( "..\\..\\..\\WinFormSamples\\GeoData\\World\\countries.shp", true); var l = new SharpMap.Layers.Symbolizer.PolygonalVectorLayer("Countries", provider); l.Symbolizer = new ModifiedBasicPolygonSymbolizer { Fill = new System.Drawing.Drawing2D.HatchBrush( System.Drawing.Drawing2D.HatchStyle.WideDownwardDiagonal, System.Drawing.Color.Red /*, * System.Drawing.Color.LightPink*/), UseClipping = false, //Outline = System.Drawing.Pens.AliceBlue }; var m = new SharpMap.Map(new System.Drawing.Size(1440, 1080)) { BackColor = System.Drawing.Color.Cornsilk }; m.Layers.Add(l); m.ZoomToExtents(); var sw = new System.Diagnostics.Stopwatch(); var img = m.GetMap(); sw.Start(); img = m.GetMap(); img.Save("PolygonSymbolizer-1.bmp", System.Drawing.Imaging.ImageFormat.Bmp); sw.Stop(); System.Console.WriteLine(string.Format("Rendering new method:{0}ms", sw.ElapsedMilliseconds)); l.Symbolizer = new SharpMap.Rendering.Symbolizer.BasicPolygonSymbolizer() { Fill = new System.Drawing.Drawing2D.HatchBrush( System.Drawing.Drawing2D.HatchStyle.WideDownwardDiagonal, System.Drawing.Color.Red /*, * System.Drawing.Color.LightPink*/), UseClipping = false, //Outline = System.Drawing.Pens.AliceBlue }; sw.Restart(); img = m.GetMap(); img.Save("PolygonSymbolizer-2.bmp", System.Drawing.Imaging.ImageFormat.Bmp); sw.Stop(); System.Console.WriteLine(string.Format("Rendering new method:{0}ms", sw.ElapsedMilliseconds)); }
public void TestPlainPolygonSymbolizer() { var provider = new SharpMap.Data.Providers.ShapeFile( "..\\..\\..\\WinFormSamples\\GeoData\\World\\countries.shp", true); var l = new SharpMap.Layers.Symbolizer.PolygonalVectorLayer("Countries", provider); l.Symbolizer = new ModifiedBasicPolygonSymbolizer { Fill = new System.Drawing.Drawing2D.HatchBrush( System.Drawing.Drawing2D.HatchStyle.WideDownwardDiagonal, System.Drawing.Color.Red /*, System.Drawing.Color.LightPink*/), UseClipping = false, //Outline = System.Drawing.Pens.AliceBlue }; var m = new SharpMap.Map(new System.Drawing.Size(1440, 1080)) { BackColor = System.Drawing.Color.Cornsilk }; m.Layers.Add(l); m.ZoomToExtents(); var sw = new System.Diagnostics.Stopwatch(); var img = m.GetMap(); sw.Start(); img = m.GetMap(); img.Save("PolygonSymbolizer-1.bmp", System.Drawing.Imaging.ImageFormat.Bmp); sw.Stop(); System.Console.WriteLine(string.Format("Rendering new method:{0}ms", sw.ElapsedMilliseconds)); l.Symbolizer = new SharpMap.Rendering.Symbolizer.BasicPolygonSymbolizer() { Fill = new System.Drawing.Drawing2D.HatchBrush( System.Drawing.Drawing2D.HatchStyle.WideDownwardDiagonal, System.Drawing.Color.Red/*, System.Drawing.Color.LightPink*/), UseClipping = false, //Outline = System.Drawing.Pens.AliceBlue }; sw.Reset(); sw.Start(); img = m.GetMap(); img.Save("PolygonSymbolizer-2.bmp", System.Drawing.Imaging.ImageFormat.Bmp); sw.Stop(); System.Console.WriteLine(string.Format("Rendering new method:{0}ms", sw.ElapsedMilliseconds)); }
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; }
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 ShapeFile("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 ShapeFile("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 ShapeFile("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); }