-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathProjection.cs
More file actions
174 lines (157 loc) · 5.28 KB
/
Projection.cs
File metadata and controls
174 lines (157 loc) · 5.28 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
// 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;
namespace ProjNet.CoordinateSystems
{
/// <summary>
/// The Projection class defines the standard information stored with a projection
/// objects. A projection object implements a coordinate transformation from a geographic
/// coordinate system to a projected coordinate system, given the ellipsoid for the
/// geographic coordinate system. It is expected that each coordinate transformation of
/// interest, e.g., Transverse Mercator, Lambert, will be implemented as a class of
/// type Projection, supporting the IProjection interface.
/// </summary>
[Serializable]
public class Projection : Info, IProjection
{
internal Projection(string className, List<ProjectionParameter> parameters,
string name, string authority, long code, string alias,
string remarks, string abbreviation)
: base(name, authority, code, alias, abbreviation, remarks)
{
_parameters = parameters;
_ClassName = className;
}
#region Predefined projections
#endregion
#region IProjection Members
/// <summary>
/// Gets the number of parameters of the projection.
/// </summary>
public int NumParameters
{
get { return _parameters.Count; }
}
private List<ProjectionParameter> _parameters;
/// <summary>
/// Gets or sets the parameters of the projection
/// </summary>
internal List<ProjectionParameter> Parameters
{
get { return _parameters; }
set { _parameters = value; }
}
/// <summary>
/// Gets an indexed parameter of the projection.
/// </summary>
/// <param name="index">Index of parameter</param>
/// <returns>n'th parameter</returns>
public ProjectionParameter GetParameter(int index)
{
return _parameters[index];
}
/// <summary>
/// Adds a parameter to the parameter list
/// </summary>
/// <param name="name">The projection parameter name</param>
/// <param name="value">The value</param>
internal void AddParameter(string name, double value)
{
var param = new ProjectionParameter(name, value);
_parameters.Add(param);
}
/// <summary>
/// Gets an named parameter of the projection.
/// </summary>
/// <remarks>The parameter name is case insensitive</remarks>
/// <param name="name">Name of parameter</param>
/// <returns>parameter or null if not found</returns>
public ProjectionParameter GetParameter(string name)
{
foreach (ProjectionParameter par in _parameters)
if (par.Name.Equals(name, StringComparison.OrdinalIgnoreCase))
return par;
return null;
}
private string _ClassName;
/// <summary>
/// Gets the projection classification name (e.g. "Transverse_Mercator").
/// </summary>
public string ClassName
{
get { return _ClassName; }
}
/// <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("PROJECTION[\"{0}\"", ClassName);
if (!string.IsNullOrWhiteSpace(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_Projection Classname=\"{0}\">{1}", ClassName, InfoXml);
foreach (ProjectionParameter param in Parameters)
sb.Append(param.XML);
sb.Append("</CS_Projection>");
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 Projection))
return false;
Projection proj = obj as Projection;
if (proj.NumParameters != this.NumParameters)
return false;
for (int i = 0; i < _parameters.Count; i++)
{
ProjectionParameter param = GetParameter(proj.GetParameter(i).Name);
if (param == null)
return false;
if (param.Value != proj.GetParameter(i).Value)
return false;
}
return true;
}
#endregion
}
}