public void TestPuntalLayer() { var lS = new SharpMap.Layers.Symbolizer.PuntalVectorLayer("PuntalTest", ProviderTest.CreateProvider()); var rsS = (RasterPointSymbolizer)lS.Symbolizer; rsS.Transparency = 0.2f; SharpMap.Layers.Symbolizer.PuntalVectorLayer lD = null; Assert.DoesNotThrow(() => lD = SandD(lS, GetFormatter())); Assert.IsNotNull(lD); Assert.IsInstanceOf(lS.Symbolizer.GetType(), lD.Symbolizer); var rsD = (RasterPointSymbolizer)lD.Symbolizer; Assert.AreEqual(rsS.Transparency, rsD.Transparency); }
public void TestTransformation() { var m = new SharpMap.Map(new System.Drawing.Size(640, 320)); var l = new SharpMap.Layers.Symbolizer.PuntalVectorLayer("l", new SharpMap.Data.Providers.GeometryProvider(m.Factory.CreatePoint(new GeoAPI.Geometries.Coordinate(0, 51.478885))), SharpMap.Rendering.Symbolizer.PathPointSymbolizer.CreateCircle(System.Drawing.Pens.Aquamarine, System.Drawing.Brushes.BurlyWood, 24)); var ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); l.CoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator); l.ReverseCoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator, ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84); m.Layers.Add(new SharpMap.Layers.TileLayer(BruTile.Predefined.KnownTileSources.Create(), "b")); m.Layers.Add(l); var e = new GeoAPI.Geometries.Envelope(-0.02, 0.02, 51.478885 - 0.01, 51.478885 + 0.01); e = GeoAPI.CoordinateSystems.Transformations.GeometryTransform.TransformBox(e, l.CoordinateTransformation.MathTransform); m.ZoomToBox(e); m.GetMap().Save("Greenwich.png", System.Drawing.Imaging.ImageFormat.Png); }
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); }
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 TestTransformation() { var m = new SharpMap.Map(new System.Drawing.Size(640, 320)); var l = new SharpMap.Layers.Symbolizer.PuntalVectorLayer("l", new SharpMap.Data.Providers.GeometryProvider(m.Factory.CreatePoint(new GeoAPI.Geometries.Coordinate(0, 51.478885))), SharpMap.Rendering.Symbolizer.PathPointSymbolizer.CreateCircle(System.Drawing.Pens.Aquamarine, System.Drawing.Brushes.BurlyWood, 24)); var ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); l.CoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator); l.ReverseCoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator, ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84); m.Layers.Add(new SharpMap.Layers.TileLayer(new BruTile.Web.OsmTileSource(),"b")); m.Layers.Add(l); var e = new GeoAPI.Geometries.Envelope(-0.02, 0.02, 51.478885 - 0.01, 51.478885 + 0.01); e = GeoAPI.CoordinateSystems.Transformations.GeometryTransform.TransformBox(e, l.CoordinateTransformation.MathTransform); m.ZoomToBox(e); m.GetMap().Save("Greenwich.png", System.Drawing.Imaging.ImageFormat.Png); }