forked from SharpMap/SharpMap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapTest.cs
More file actions
130 lines (107 loc) · 4.88 KB
/
MapTest.cs
File metadata and controls
130 lines (107 loc) · 4.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#if !LINUX
using System;
using System.Drawing;
using System.IO;
using BruTile.Predefined;
using BruTile.Web;
using GeoAPI.CoordinateSystems.Transformations;
using GeoAPI.Geometries;
using NUnit.Framework;
using NetTopologySuite.Geometries;
using SharpMap;
using SharpMap.Data.Providers;
using SharpMap.Layers;
using SharpMap.Styles;
namespace UnitTests.Serialization
{
public class MapTest : BaseSerializationTest
{
private readonly Size _mapSize = new Size(1200, 800);
[Test, Description("Just a line")]
public void TestMap1()
{
var m = new Map(_mapSize);
m.Layers.Add(new VectorLayer("tmp", new GeometryProvider(
new LineString(new [] {new Coordinate(0, 0), new Coordinate(10, 10), }))));
m.ZoomToExtents();
Map mD = null;
Assert.DoesNotThrow(()=>mD=SandD(m, GetFormatter()));
TestMaps("Test1", m, mD);
}
private static void TestMaps(string name, Map m, Map mD)
{
Assert.NotNull(mD);
Assert.AreEqual(m.Size, mD.Size);
Assert.AreEqual(m.Layers.Count, mD.Layers.Count);
var c = new LayerTest.VectorLayerEqualityComparer();
for (var i = 0; i < m.Layers.Count; i++)
{
Assert.IsTrue(c.Equals((VectorLayer)m.Layers[i],
(VectorLayer)mD.Layers[i]),
"Layer {0}, '{1}' Differs at {2}",
i, m.Layers[i].LayerName, string.Join(", ", c.DifferAt));
}
Assert.AreEqual(m.PixelAspectRatio, mD.PixelAspectRatio);
Assert.AreEqual(m.PixelHeight, mD.PixelHeight);
Assert.AreEqual(m.PixelWidth, mD.PixelWidth);
Assert.AreEqual(m.PixelSize, mD.PixelSize);
Assert.AreEqual(m.BackColor, mD.BackColor);
Assert.IsTrue(m.Center.Equals(mD.Center));
Assert.IsTrue(m.GetExtents().Equals(mD.GetExtents()));
Assert.IsTrue(m.Envelope.Equals(mD.Envelope));
Assert.AreEqual(m.Decorations.Count, mD.Decorations.Count);
Assert.AreEqual(m.SRID, mD.SRID);
Assert.AreEqual(m.Zoom, mD.Zoom);
Assert.DoesNotThrow(() => m.GetMap().Save(System.IO.Path.Combine(UnitTestsFixture.GetImageDirectory(new MapTest()), name + "-S.bmp")));
Assert.DoesNotThrow(() => mD.GetMap().Save(System.IO.Path.Combine(UnitTestsFixture.GetImageDirectory(new MapTest()), name + "-D.bmp")));
}
[Test, Description("BingHybridStaging base map, OSM of Aurich, randomly styled"), Ignore("Need to fix BruTile serialization")]
public void TestMap2()
{
var m = new Map(_mapSize);
m.BackgroundLayer.Add(new TileLayer(KnownTileSources.Create(KnownTileSource.BingHybridStaging), "BingHybridStaging"));
string cn = $"Data Source={TestUtility.GetPathToTestFile("osm_aurich.sqlite")};";
var ct = Wgs84ToWebMercator;
//Env[7,45731445821406 : 7,53454260528903, 53,4342695512313 : 53,478793942147]
var box = new Envelope(7.45731445821406, 7.53454260528903, 53.4342695512313, 53.478793942147);
var box3857 = GeometryTransform.TransformBox(box, ct.MathTransform);
m.ZoomToBox(box3857);
foreach (var msp in ManagedSpatiaLite.GetSpatialTables(cn))
{
var l = new VectorLayer(msp.Table, msp);
switch (msp.Table.Substring(0, 2).ToLower())
{
case "pt":
l.Style = VectorStyle.CreateRandomPuntalStyle();
break;
case "ln":
l.Style = VectorStyle.CreateRandomLinealStyle();
break;
case "pg":
l.Style = VectorStyle.CreateRandomPolygonalStyle();
break;
default:
l.Style = VectorStyle.CreateRandomStyle();
break;
}
l.CoordinateTransformation = ct;
m.Layers.Add(l);
}
var f = GetFormatter();
//BruTile.Utility.AddBruTileSurrogates(GetFormatter());
Map mD = null;
Assert.DoesNotThrow(() => mD = SandD(m, f));
TestMaps("Test2", m, mD);
}
private static ICoordinateTransformation Wgs84ToWebMercator
{
get
{
return new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory()
.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84,
ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator);
}
}
}
}
#endif