-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
107 lines (93 loc) · 4.22 KB
/
Form1.cs
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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraMap;
namespace BuildInCoordinateConverters {
public partial class Form1 : Form {
ShapefileDataAdapter adapter = new ShapefileDataAdapter();
List<MapData> mapData = new List<MapData> {
#region #Albers
new MapData() {
Filepath = "../../Shapefiles/Albers/switzerland.shp",
CoordinateSystem = new CartesianSourceCoordinateSystem() {
CoordinateConverter = new AlbersEqualAreaConticCartesianToGeoConverter() {
StandardParallelN = 60, StandardParallelS = 20,
Ellipsoid = Ellipsoid.GRS80, ProjectionCenter = new GeoPoint(40, -96)
}
}
},
#endregion #Albers
#region #Lambert
new MapData() {
Filepath = "../../Shapefiles/Lambert/Belize.shp",
CoordinateSystem = new CartesianSourceCoordinateSystem() {
CoordinateConverter = new LambertConformalConicCartesianToGeoConverter() {
StandardParallelN = 60, StandardParallelS = 20,
Ellipsoid = Ellipsoid.GRS80, ProjectionCenter = new GeoPoint(40, -96)
}
}
},
#endregion #Lambert
#region #TransverseMercator
new MapData() {
Filepath = "../../Shapefiles/TransverseMercator/israel.shp",
CoordinateSystem = new CartesianSourceCoordinateSystem() {
CoordinateConverter = new TransverseMercatorCartesianToGeoConverter() {
Ellipsoid = Ellipsoid.WGS84, ProjectionCenter = new GeoPoint(0, 33),
ScaleFactor = 0.9996, FalseNorthing = 0, FalseEasting = 500000
}
}
},
#endregion #TransverseMercator
#region #UTM
new MapData() {
Filepath = "../../Shapefiles/TransverseMercator/israel.shp",
CoordinateSystem = new CartesianSourceCoordinateSystem() {
CoordinateConverter = new UTMCartesianToGeoConverter() {
UtmZone = 36, Hemisphere = Hemisphere.Northern
}
}
},
#endregion #UTM
#region #MercatorAuxiliary
new MapData() {
Filepath = "../../Shapefiles/MercatorAux/montenegro.shp",
CoordinateSystem = new CartesianSourceCoordinateSystem() {
CoordinateConverter = new MercatorAuxiliarySphereCartesianToGeoConverter() {
SphereType = 0, ProjectionCenter = new GeoPoint(0,0)
}
}
},
#endregion #MercatorAuxiliary
};
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
cbData.DataSource = mapData;
VectorItemsLayer layer = new VectorItemsLayer() {Data = adapter};
layer.ItemStyle.Fill = Color.FromArgb(40, 255, 128, 0);
layer.DataLoaded +=layer_DataLoaded;
mapControl1.Layers.Add(layer);
}
void layer_DataLoaded(object sender, DataLoadedEventArgs e) {
mapControl1.ZoomToFitLayerItems(0.4);
}
private void cbData_SelectedIndexChanged(object sender, EventArgs e) {
MapData data = cbData.SelectedValue as MapData;
if (data == null) return;
Uri baseUri = new Uri(System.Reflection.Assembly.GetEntryAssembly().Location);
Uri fileUri = new Uri(baseUri, data.Filepath);
adapter.FileUri = fileUri;
adapter.SourceCoordinateSystem = data.CoordinateSystem;
}
}
class MapData {
public string Filepath { get; set; }
public SourceCoordinateSystem CoordinateSystem { get; set; }
public override string ToString() {
return String.Format("{0}; with {1}", Filepath, CoordinateSystem.CoordinateConverter);
}
}
}