forked from SharpMap/SharpMap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormSqlServerOpts.cs
More file actions
270 lines (219 loc) · 9.88 KB
/
FormSqlServerOpts.cs
File metadata and controls
270 lines (219 loc) · 9.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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SharpMap;
using SharpMap.Data.Providers;
using SharpMap.Layers;
namespace WinFormSamples.Samples
{
public partial class FormSqlServerOpts : Form
{
public SharpMap.Forms.MapBox MapBox { get; set; }
public string ConnectionString { get; set; }
public FormSqlServerOpts()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
// NO LONGER REQUIRED (performed internally by SharpMap.SqlServerSpatialObjects)
//SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
SqlServerSample.InitialiseTables(ConnectionString);
WireHandlers();
base.OnLoad(e);
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
}
private void WireHandlers()
{
this.optDataProviderWKB.Click += this.optDataProvider_Click;
this.optDataProviderNative.Click += this.optDataProvider_Click;
this.optSpatialGeog.Click += this.optSpatial_Click;
this.optSpatialGeom.Click += this.optSpatial_Click;
this.chkSpatialValidate.CheckedChanged += this.chkSpatialValidate_Click;
this.optExtentsIndividual.Click += this.optExtents_Click;
this.optExtentsAggregate.Click += this.optExtents_Click;
this.optExtentsSpatialIndex.Click += this.optExtents_Click;
this.cmdGetExtents.Click += this.cmdGetExtents_Click;
this.chkHintIndex.CheckedChanged += this.chkHints_Click;
this.chkHintNoLock.CheckedChanged += this.chkHints_Click;
this.chkHintsSeek.CheckedChanged += this.chkHints_Click;
this.optDefQueryNone.Click += this.optDefQuery_Click;
this.optDefQueryId.Click += this.optDefQuery_Click;
this.optDefQueryName.Click += this.optDefQuery_Click;
}
private void optDataProvider_Click(object sender, EventArgs e)
{
if (optDataProviderNative.Checked && !chkSpatialValidate.Checked)
// MUST be true for Native Types
chkSpatialValidate.Checked = true;
optSpatial_Click(null, null);
}
private void optSpatial_Click(object sender, EventArgs e)
{
// reset map layers
MapBox.Map.Layers.Clear();
SharpMap.Layers.VectorLayer spatialLyr;
string spatialTable;
string geomColumn;
SqlServerSpatialObjectType geomType;
Brush symBrush;
if (optSpatialGeog.Checked)
{
spatialTable = SqlServerSample.GeogTable;
geomColumn = "Geog4326";
geomType = SqlServerSpatialObjectType.Geography;
symBrush = new SolidBrush(optDataProviderWKB.Checked ? Color.Orange : Color.DeepSkyBlue);
labTable.Text = "Table: " + SqlServerSample.GeogTable;
}
else
{
// ensure checked
optSpatialGeom.Checked = true;
spatialTable = SqlServerSample.GeomTable;
geomColumn = "Geom4326";
geomType = SqlServerSpatialObjectType.Geometry;
symBrush = new SolidBrush(optDataProviderWKB.Checked ? Color.Red : Color.DodgerBlue);
labTable.Text = "Table: " + SqlServerSample.GeomTable;
chkSpatialValidate.Enabled = true;
}
spatialLyr = new SharpMap.Layers.VectorLayer("Spatial");
if (optDataProviderWKB.Checked)
spatialLyr.DataSource = new SqlServer2008(ConnectionString, spatialTable, geomColumn, "Id", geomType, 4326, SqlServer2008ExtentsMode.QueryIndividualFeatures);
else
spatialLyr.DataSource = new SqlServer2008Ex(ConnectionString, spatialTable, geomColumn, "Id", geomType, 4326, SqlServer2008ExtentsMode.QueryIndividualFeatures);
spatialLyr.SRID = spatialLyr.DataSource.SRID;
spatialLyr.TargetSRID = 3857;
spatialLyr.Style.PointColor = symBrush;
//Set up a label layer
var labelLyr = new SharpMap.Layers.LabelLayer("Labels")
{
DataSource = spatialLyr.DataSource,
//SRID=4326,
TargetSRID = 3857,
Enabled = true,
LabelColumn = "Name",
//MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest,
LabelFilter = SharpMap.Rendering.LabelCollisionDetection.QuickAccurateCollisionDetectionMethod,
Style = new SharpMap.Styles.LabelStyle()
{
ForeColor = System.Drawing.Color.DarkSlateGray,
Font = new System.Drawing.Font(System.Drawing.FontFamily.GenericSerif, 8),
//BackColor = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(128, 255, 0, 0)),
HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left,
CollisionDetection = true,
Offset = new PointF(10, 0)
//MaxVisible = 90,
//MinVisible = 30
}
};
MapBox.Map.Layers.Add(spatialLyr);
MapBox.Map.Layers.Add(labelLyr);
// configure data provider options
chkSpatialValidate_Click(null, null);
optExtents_Click(null, null);
chkHints_Click(null, null);
optDefQuery_Click(null, null);
MapBox.Refresh();
}
private SqlServer2008 GetSqlServerDataProvider()
{
if (MapBox.Map.Layers.Count == 0)
return null;
VectorLayer lyr = (VectorLayer)MapBox.Map.Layers[0];
return (SqlServer2008)lyr.DataSource;
}
private void chkSpatialValidate_Click(object sender, EventArgs e)
{
var sqlDP = GetSqlServerDataProvider();
if (sqlDP == null) return;
if (sqlDP is SqlServer2008Ex)
if (sender != null && !chkSpatialValidate.Checked)
{
chkSpatialValidate.Checked = true;
MessageBox.Show("Validate is cannot be disabled for Native Types",
"Validate Geometries", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
sqlDP.ValidateGeometries = chkSpatialValidate.Checked;
if (sender != null)
MapBox.Refresh();
}
private void optExtents_Click(object sender, EventArgs e)
{
var sqlDP = GetSqlServerDataProvider();
if (sqlDP == null) return;
try
{
if (optExtentsIndividual.Checked)
sqlDP.ExtentsMode = SqlServer2008ExtentsMode.QueryIndividualFeatures;
else if (optExtentsAggregate.Checked)
sqlDP.ExtentsMode = SqlServer2008ExtentsMode.EnvelopeAggregate;
else if (optExtentsSpatialIndex.Checked)
{
sqlDP.ExtentsMode = SqlServer2008ExtentsMode.SpatialIndex;
MessageBox.Show("Are you sure? \nThis mode uses the extent of the Spatial Index GRID, " +
"not the extents of the DATA, and does not take into account any Definition Query. " +
"\nTo see this in action, click Get Extents for each Extent mode and see the resulting envelope output to Console.",
"Extents Mode", MessageBoxButtons.OK, MessageBoxIcon.Question);
}
if (sender != null)
MapBox.Refresh();
}
catch (Exception ex)
{
this.optExtentsSpatialIndex.Checked = false;
MessageBox.Show(ex.Message, "Extents Mode", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
private void chkHints_Click(object sender, EventArgs e)
{
var sqlDP = GetSqlServerDataProvider();
if (sqlDP == null) return;
sqlDP.NoLockHint = chkHintNoLock.Checked;
sqlDP.ForceSeekHint = chkHintsSeek.Checked;
if (chkHintIndex.Checked)
{
if (optSpatialGeom.Checked)
sqlDP.ForceIndex = SqlServerSample.GeomSpatialIndex;
else
sqlDP.ForceIndex = SqlServerSample.GeogSpatialIndex;
}
else
sqlDP.ForceIndex = string.Empty;
if (sender != null)
MapBox.Refresh();
}
private void optDefQuery_Click(object sender, EventArgs e)
{
var sqlDP = GetSqlServerDataProvider();
if (sqlDP == null) return;
if (optDefQueryName.Checked)
sqlDP.DefinitionQuery = optDefQueryName.Text;
else if (optDefQueryId.Checked)
sqlDP.DefinitionQuery = optDefQueryId.Text;
else
sqlDP.DefinitionQuery = string.Empty;
if (sender != null)
MapBox.Refresh();
}
private void cmdGetExtents_Click(object sender, EventArgs e)
{
labExtentsTime.Text = "";
var sqlDP = GetSqlServerDataProvider();
if (sqlDP == null) return;
var stopWatch = System.Diagnostics.Stopwatch.StartNew();
var env = sqlDP.GetExtents();
stopWatch.Stop();
labExtentsTime.Text = stopWatch.ElapsedMilliseconds.ToString("0.000") + "ms";
Console.WriteLine("Spatial Extents " + env.ToString());
}
}
}