forked from SharpMap/SharpMap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLayerGroupTest.cs
More file actions
167 lines (138 loc) · 7.95 KB
/
LayerGroupTest.cs
File metadata and controls
167 lines (138 loc) · 7.95 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using System;
using GeoAPI.Geometries;
using NUnit.Framework;
using SharpMap.Layers;
using SharpMap.Styles;
namespace UnitTests.Layers
{
[TestFixture]
public class LayerGroupTest //: UnitTestsFixture
{
#region DummyLayer class
private class DummyLayer : Layer
{
public override Envelope Envelope
{
get { return null; }
}
}
#endregion
#region FooLayer class
private class FooLayer : Layer
{
public override Envelope Envelope
{
get { return new Envelope(5, 10, 5, 10); }
}
}
#endregion
private GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation CreateTransformation()
{
var ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
return ctf.CreateFromCoordinateSystems(
ProjNet.CoordinateSystems.GeocentricCoordinateSystem.WGS84,
ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84);
}
private GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation CreateReverseTransformation()
{
var ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
return ctf.CreateFromCoordinateSystems(
ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84,
ProjNet.CoordinateSystems.GeocentricCoordinateSystem.WGS84);
}
[Test(Description = "Setting a CoordinateTransformation to LayerGroup propagates to inner layers")]
public void CoordinateTransformation_SettingValue_PropagatesTransformation()
{
var group = new LayerGroup("group");
group.Layers.Add(new DummyLayer());
var transf = CreateTransformation();
group.CoordinateTransformation = transf;
Assert.That(((Layer)group.Layers[0]).CoordinateTransformation, Is.EqualTo(transf),
"LayerGroup.CoordinateTransformation should propagate to inner layers");
}
[Test(Description = "Setting a CoordinateTransformation to LayerGroup when SkipTransformationPropagation is true does NOT propagate to inner layers")]
public void CoordinateTransformation_SettingValueWhenSkipIsOn_DoesNotPropagateTransformation()
{
var group = new LayerGroup("group");
group.Layers.Add(new DummyLayer());
var transf = CreateTransformation();
group.SkipTransformationPropagation = true;
group.CoordinateTransformation = transf;
Assert.That(((Layer)group.Layers[0]).CoordinateTransformation, Is.Not.EqualTo(transf),
"LayerGroup.CoordinateTransformation should NOT propagate to inner layers because SkipTransformationPropagation was true");
}
[Test(Description = "Setting a ReverseCoordinateTransformation to LayerGroup propagates to inner layers")]
public void ReverseCoordinateTransformation_SettingValue_PropagatesTransformation()
{
var group = new LayerGroup("group");
group.Layers.Add(new DummyLayer());
var transf = CreateTransformation();
group.ReverseCoordinateTransformation = transf;
Assert.That(((Layer)group.Layers[0]).ReverseCoordinateTransformation, Is.EqualTo(transf),
"LayerGroup.ReverseCoordinateTransformation should propagate to inner layers");
}
[Test(Description = "Setting a ReverseCoordinateTransformation to LayerGroup when SkipTransformationPropagation is true does NOT propagate to inner layers")]
public void ReverseCoordinateTransformation_SettingValueWhenSkipIsOn_DoesNotPropagateTransformation()
{
var group = new LayerGroup("group");
group.Layers.Add(new DummyLayer());
var transf = CreateTransformation();
group.SkipTransformationPropagation = true;
group.ReverseCoordinateTransformation = transf;
Assert.That(((Layer)group.Layers[0]).ReverseCoordinateTransformation, Is.Not.EqualTo(transf),
"LayerGroup.ReverseCoordinateTransformation should NOT propagate to inner layers because SkipTransformationPropagation was true");
}
[Test(Description = "Envelope returns null when the inner layer Envelope is null")]
public void Envelope_WhenInnerLayerEnvelopeIsNull_ReturnsNull()
{
var group = new LayerGroup("group");
group.Layers.Add(new DummyLayer());
Assert.That(group.Envelope, Is.Null,
"LayerGroup envelope should be null since we added a layer with a null envelope");
}
[Test(Description = "Envelope returns null when there are no layers")]
public void Envelope_NoInnerLayers_ReturnsNull()
{
var group = new LayerGroup("group");
Assert.IsNull(group.Envelope);
}
[Test(Description = "Envelope skips inner layers which return null envelope")]
public void Envelope_SomeInnerLayerWithNullEnvelope_SkipNulls()
{
var group = new LayerGroup("group");
group.Layers.Add(new DummyLayer());
group.Layers.Add(new FooLayer());
Assert.That(group.Envelope, Is.EqualTo(new Envelope(5, 10, 5, 10)));
}
[Test(Description = "Clone clones all the properties")]
public void LayerGroup_CloneProp()
{
var group = new LayerGroup("group");
// This is a transformation that cannot be "inverted" in ProjNet
// Directly setting CoordinateTransformation will update SRID and TargetSRID
group.CoordinateTransformation = CreateTransformation();
group.ReverseCoordinateTransformation = CreateReverseTransformation();
group.Enabled = true;
group.IsQueryEnabled = true;
group.MinVisible = 10;
group.MaxVisible = 100;
//group.SRID = 4326; // different to CoordinateTransformation above!!!
//group.TargetSRID = 4318; // different to CoordinateTransformation above!!!
group.Proj4Projection = "dummy";
group.Style = new LabelStyle();
var clonedGroup = (LayerGroup)group.Clone();
Assert.That(clonedGroup.CoordinateTransformation.SourceCS.WKT, Is.EqualTo(group.CoordinateTransformation.SourceCS.WKT), "CoordinateTransformation mismatch");
Assert.That(clonedGroup.CoordinateTransformation.TargetCS.WKT, Is.EqualTo(group.CoordinateTransformation.TargetCS.WKT), "CoordinateTransformation mismatch");
Assert.That(clonedGroup.ReverseCoordinateTransformation.SourceCS.WKT, Is.EqualTo(group.ReverseCoordinateTransformation.SourceCS.WKT), "CoordinateTransformation mismatch");
Assert.That(clonedGroup.ReverseCoordinateTransformation.TargetCS.WKT, Is.EqualTo(group.ReverseCoordinateTransformation.TargetCS.WKT), "CoordinateTransformation mismatch");
Assert.That(clonedGroup.Enabled, Is.EqualTo(group.Enabled), "Enabled mismatch");
Assert.That(clonedGroup.IsQueryEnabled, Is.EqualTo(group.IsQueryEnabled), "IsQueryEnabled mismatch");
Assert.That(clonedGroup.MinVisible, Is.EqualTo(group.MinVisible), "MinVisible mismatch");
Assert.That(clonedGroup.MaxVisible, Is.EqualTo(group.MaxVisible), "MaxVisible mismatch");
Assert.That(clonedGroup.SRID, Is.EqualTo(group.SRID), "SRID mismatch");
Assert.That(clonedGroup.Proj4Projection, Is.EqualTo(group.Proj4Projection), "Proj4Projection mismatch");
Assert.That(clonedGroup.TargetSRID, Is.EqualTo(group.TargetSRID), "TargetSRID mismatch");
Assert.That(clonedGroup.Style, Is.EqualTo(group.Style), "Style mismatch");
}
}
}