/
ProjectedCoordinateSystem.cs
211 lines (191 loc) · 8.57 KB
/
ProjectedCoordinateSystem.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
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
// Copyright 2005 - 2009 - Morten Nielsen (www.sharpgis.net)
//
// This file is part of ProjNet.
// ProjNet is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// ProjNet is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public License
// along with ProjNet; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using GeoAPI.CoordinateSystems;
namespace ProjNet.CoordinateSystems
{
/// <summary>
/// A 2D cartographic coordinate system.
/// </summary>
public class ProjectedCoordinateSystem : HorizontalCoordinateSystem, IProjectedCoordinateSystem
{
/// <summary>
/// Initializes a new instance of a projected coordinate system
/// </summary>
/// <param name="datum">Horizontal datum</param>
/// <param name="geographicCoordinateSystem">Geographic coordinate system</param>
/// <param name="linearUnit">Linear unit</param>
/// <param name="projection">Projection</param>
/// <param name="axisInfo">Axis info</param>
/// <param name="name">Name</param>
/// <param name="authority">Authority name</param>
/// <param name="code">Authority-specific identification code.</param>
/// <param name="alias">Alias</param>
/// <param name="abbreviation">Abbreviation</param>
/// <param name="remarks">Provider-supplied remarks</param>
internal ProjectedCoordinateSystem(IHorizontalDatum datum, IGeographicCoordinateSystem geographicCoordinateSystem,
ILinearUnit linearUnit, IProjection projection, List<AxisInfo> axisInfo,
string name, string authority, long code, string alias,
string remarks, string abbreviation)
: base(datum, axisInfo, name, authority, code, alias, abbreviation, remarks)
{
_GeographicCoordinateSystem = geographicCoordinateSystem;
_LinearUnit = linearUnit;
_Projection = projection;
}
#region Predefined projected coordinate systems
/// <summary>
/// Universal Transverse Mercator - WGS84
/// </summary>
/// <param name="Zone">UTM zone</param>
/// <param name="ZoneIsNorth">true of Northern hemisphere, false if southern</param>
/// <returns>UTM/WGS84 coordsys</returns>
public static ProjectedCoordinateSystem WGS84_UTM(int Zone, bool ZoneIsNorth)
{
List<ProjectionParameter> pInfo = new List<ProjectionParameter>();
pInfo.Add(new ProjectionParameter("latitude_of_origin", 0));
pInfo.Add(new ProjectionParameter("central_meridian", Zone * 6 - 183));
pInfo.Add(new ProjectionParameter("scale_factor", 0.9996));
pInfo.Add(new ProjectionParameter("false_easting", 500000));
pInfo.Add(new ProjectionParameter("false_northing", ZoneIsNorth ? 0 : 10000000));
//IProjection projection = cFac.CreateProjection("UTM" + Zone.ToString() + (ZoneIsNorth ? "N" : "S"), "Transverse_Mercator", parameters);
Projection proj = new Projection("Transverse_Mercator", pInfo, "UTM" + Zone.ToString(System.Globalization.CultureInfo.InvariantCulture) + (ZoneIsNorth ? "N" : "S"),
"EPSG", 32600 + Zone + (ZoneIsNorth ? 0 : 100), String.Empty, String.Empty, String.Empty);
System.Collections.Generic.List<AxisInfo> axes = new List<AxisInfo>();
axes.Add(new AxisInfo("East", AxisOrientationEnum.East));
axes.Add(new AxisInfo("North", AxisOrientationEnum.North));
return new ProjectedCoordinateSystem(ProjNet.CoordinateSystems.HorizontalDatum.WGS84,
ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, ProjNet.CoordinateSystems.LinearUnit.Metre, proj, axes,
"WGS 84 / UTM zone " + Zone.ToString(System.Globalization.CultureInfo.InvariantCulture) + (ZoneIsNorth ? "N" : "S"), "EPSG", 32600 + Zone + (ZoneIsNorth ? 0 : 100),
String.Empty, "Large and medium scale topographic mapping and engineering survey.", string.Empty);
}
#endregion
#region IProjectedCoordinateSystem Members
private IGeographicCoordinateSystem _GeographicCoordinateSystem;
/// <summary>
/// Gets or sets the GeographicCoordinateSystem.
/// </summary>
public IGeographicCoordinateSystem GeographicCoordinateSystem
{
get { return _GeographicCoordinateSystem; }
set { _GeographicCoordinateSystem = value; }
}
private ILinearUnit _LinearUnit;
/// <summary>
/// Gets or sets the <see cref="LinearUnit">LinearUnits</see>. The linear unit must be the same as the <see cref="CoordinateSystem"/> units.
/// </summary>
public ILinearUnit LinearUnit
{
get { return _LinearUnit; }
set { _LinearUnit = value; }
}
/// <summary>
/// Gets units for dimension within coordinate system. Each dimension in
/// the coordinate system has corresponding units.
/// </summary>
/// <param name="dimension">Dimension</param>
/// <returns>Unit</returns>
public override IUnit GetUnits(int dimension)
{
return _LinearUnit;
}
private IProjection _Projection;
/// <summary>
/// Gets or sets the projection
/// </summary>
public IProjection Projection
{
get { return _Projection; }
set { _Projection = value; }
}
/// <summary>
/// Returns the Well-known text for this object
/// as defined in the simple features specification.
/// </summary>
public override string WKT
{
get
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("PROJCS[\"{0}\", {1}, {2}, {3}", Name, GeographicCoordinateSystem.WKT, LinearUnit.WKT, Projection.WKT);
for(int i=0;i<Projection.NumParameters;i++)
sb.AppendFormat(CultureInfo.InvariantCulture.NumberFormat, ", {0}", Projection.GetParameter(i).WKT);
//sb.AppendFormat(", {0}", LinearUnit.WKT);
//Skip authority and code if not defined
if (!String.IsNullOrEmpty(Authority) && AuthorityCode > 0)
sb.AppendFormat(", AUTHORITY[\"{0}\", \"{1}\"]", Authority, AuthorityCode);
//Skip axis info if they contain default values
if (AxisInfo.Count != 2 ||
AxisInfo[0].Name != "X" || AxisInfo[0].Orientation != AxisOrientationEnum.East ||
AxisInfo[1].Name != "Y" || AxisInfo[1].Orientation != AxisOrientationEnum.North)
for (int i = 0; i < AxisInfo.Count; i++)
sb.AppendFormat(", {0}", GetAxis(i).WKT);
//if (!String.IsNullOrEmpty(Authority) && AuthorityCode > 0)
// sb.AppendFormat(", AUTHORITY[\"{0}\", \"{1}\"]", Authority, AuthorityCode);
sb.Append("]");
return sb.ToString();
}
}
/// <summary>
/// Gets an XML representation of this object.
/// </summary>
public override string XML
{
get
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat(CultureInfo.InvariantCulture.NumberFormat,
"<CS_CoordinateSystem Dimension=\"{0}\"><CS_ProjectedCoordinateSystem>{1}",
this.Dimension, InfoXml);
foreach (AxisInfo ai in this.AxisInfo)
sb.Append(ai.XML);
sb.AppendFormat("{0}{1}{2}</CS_ProjectedCoordinateSystem></CS_CoordinateSystem>",
GeographicCoordinateSystem.XML, LinearUnit.XML, Projection.XML);
return sb.ToString();
}
}
/// <summary>
/// Checks whether the values of this instance is equal to the values of another instance.
/// Only parameters used for coordinate system are used for comparison.
/// Name, abbreviation, authority, alias and remarks are ignored in the comparison.
/// </summary>
/// <param name="obj"></param>
/// <returns>True if equal</returns>
public override bool EqualParams(object obj)
{
if (!(obj is ProjectedCoordinateSystem))
return false;
ProjectedCoordinateSystem pcs = obj as ProjectedCoordinateSystem;
if(pcs.Dimension != this.Dimension)
return false;
for (int i = 0; i < pcs.Dimension; i++)
{
if(pcs.GetAxis(i).Orientation != this.GetAxis(i).Orientation)
return false;
if (!pcs.GetUnits(i).EqualParams(this.GetUnits(i)))
return false;
}
return pcs.GeographicCoordinateSystem.EqualParams(this.GeographicCoordinateSystem) &&
pcs.HorizontalDatum.EqualParams(this.HorizontalDatum) &&
pcs.LinearUnit.EqualParams(this.LinearUnit) &&
pcs.Projection.EqualParams(this.Projection);
}
#endregion
}
}