forked from NetTopologySuite/ProjNet4GeoAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoordinateSystemFactory.cs
More file actions
345 lines (310 loc) · 17.2 KB
/
CoordinateSystemFactory.cs
File metadata and controls
345 lines (310 loc) · 17.2 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
// 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.Text;
using ProjNet.IO.CoordinateSystems;
namespace ProjNet.CoordinateSystems
{
/// <summary>
/// Builds up complex objects from simpler objects or values.
/// </summary>
/// <remarks>
/// <para>CoordinateSystemFactory allows applications to make coordinate systems that
/// cannot be created by a simpler implementation . This factory is very
/// flexible, whereas other implementations are easier to use.</para>
/// <para>For example, the EPSG authority has codes for USA state plane coordinate systems
/// using the NAD83 datum, but these coordinate systems always use meters. EPSG does not
/// have codes for NAD83 state plane coordinate systems that use feet units. This factory
/// lets an application create such a hybrid coordinate system.</para>
/// </remarks>
public class CoordinateSystemFactory
{
/// <summary>
/// Creates an instance of this class
/// </summary>
public CoordinateSystemFactory() { }
/// <summary>
/// Creates a coordinate system object from an XML string.
/// </summary>
/// <param name="xml">XML representation for the spatial reference</param>
/// <returns>The resulting spatial reference object</returns>
public CoordinateSystem CreateFromXml(string xml)
{
throw new NotImplementedException();
}
/// <summary>
/// Creates a spatial reference object given its Well-known text representation.
/// The output object may be either a <see cref="GeographicCoordinateSystem"/> or
/// a <see cref="ProjectedCoordinateSystem"/>.
/// </summary>
/// <param name="WKT">The Well-known text representation for the spatial reference</param>
/// <returns>The resulting spatial reference object</returns>
public CoordinateSystem CreateFromWkt(string WKT)
{
var info = CoordinateSystemWktReader.Parse(WKT);
return info as CoordinateSystem;
}
/// <summary>
/// Creates a <see cref="CompoundCoordinateSystem"/> [NOT IMPLEMENTED].
/// </summary>
/// <param name="name">Name of compound coordinate system.</param>
/// <param name="head">Head coordinate system</param>
/// <param name="tail">Tail coordinate system</param>
/// <returns>Compound coordinate system</returns>
public CompoundCoordinateSystem CreateCompoundCoordinateSystem(string name, CoordinateSystem head, CoordinateSystem tail)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException("Invalid name");
return new CompoundCoordinateSystem(head, tail, name, string.Empty, -1, string.Empty, string.Empty, string.Empty);
}
/// <summary>
/// Creates a <see cref="FittedCoordinateSystem"/>.
/// </summary>
/// <remarks>The units of the axes in the fitted coordinate system will be
/// inferred from the units of the base coordinate system. If the affine map
/// performs a rotation, then any mixed axes must have identical units. For
/// example, a (lat_deg,lon_deg,height_feet) system can be rotated in the
/// (lat,lon) plane, since both affected axes are in degrees. But you
/// should not rotate this coordinate system in any other plane.</remarks>
/// <param name="name">Name of coordinate system</param>
/// <param name="baseCoordinateSystem">Base coordinate system</param>
/// <param name="toBaseWkt">WKT of the math transform to the base coordinate system</param>
/// <param name="arAxes">Axiis of the fitted coordinate system</param>
/// <returns>Fitted coordinate system</returns>
public FittedCoordinateSystem CreateFittedCoordinateSystem(string name, CoordinateSystem baseCoordinateSystem, string toBaseWkt, List<AxisInfo> arAxes)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException("Invalid name");
var toBaseTransform = MathTransformWktReader.Parse(toBaseWkt);
return new FittedCoordinateSystem(baseCoordinateSystem, toBaseTransform, name, string.Empty, -1, string.Empty, string.Empty, string.Empty);
}
/// <inheritdoc cref="CreateFittedCoordinateSystem(string, CoordinateSystem, string, List{AxisInfo})"/>
/// <param name="name">Name of coordinate system</param>
/// <param name="baseCoordinateSystem">Base coordinate system</param>
/// <param name="toBase">the math transform to the base coordinate system</param>
/// <param name="arAxes">Axiis of the fitted coordinate system</param>
/// <returns></returns>
public FittedCoordinateSystem CreateFittedCoordinateSystem(string name, CoordinateSystem baseCoordinateSystem, Transformations.MathTransform toBase, List<AxisInfo> arAxes)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException("Invalid name");
return new FittedCoordinateSystem(baseCoordinateSystem, toBase, name, string.Empty, -1, string.Empty, string.Empty, string.Empty);
}
/*
/// <summary>
/// Creates a <see cref="ILocalCoordinateSystem">local coordinate system</see>.
/// </summary>
/// <remarks>
/// The dimension of the local coordinate system is determined by the size of
/// the axis array. All the axes will have the same units. If you want to make
/// a coordinate system with mixed units, then you can make a compound
/// coordinate system from different local coordinate systems.
/// </remarks>
/// <param name="name">Name of local coordinate system</param>
/// <param name="datum">Local datum</param>
/// <param name="unit">Units</param>
/// <param name="axes">Axis info</param>
/// <returns>Local coordinate system</returns>
public ILocalCoordinateSystem CreateLocalCoordinateSystem(string name, ILocalDatum datum, IUnit unit, List<AxisInfo> axes)
{
throw new NotImplementedException();
}
*/
/// <summary>
/// Creates an <see cref="Ellipsoid"/> from radius values.
/// </summary>
/// <seealso cref="CreateFlattenedSphere"/>
/// <param name="name">Name of ellipsoid</param>
/// <param name="semiMajorAxis"></param>
/// <param name="semiMinorAxis"></param>
/// <param name="linearUnit"></param>
/// <returns>Ellipsoid</returns>
public Ellipsoid CreateEllipsoid(string name, double semiMajorAxis, double semiMinorAxis, LinearUnit linearUnit)
{
double ivf = 0;
if (semiMajorAxis != semiMinorAxis)
ivf = semiMajorAxis / (semiMajorAxis - semiMinorAxis);
return new Ellipsoid(semiMajorAxis, semiMinorAxis, ivf, false, linearUnit, name, string.Empty, -1, string.Empty, string.Empty, string.Empty);
}
/// <summary>
/// Creates an <see cref="Ellipsoid"/> from an major radius, and inverse flattening.
/// </summary>
/// <seealso cref="CreateEllipsoid"/>
/// <param name="name">Name of ellipsoid</param>
/// <param name="semiMajorAxis">Semi major-axis</param>
/// <param name="inverseFlattening">Inverse flattening</param>
/// <param name="linearUnit">Linear unit</param>
/// <returns>Ellipsoid</returns>
public Ellipsoid CreateFlattenedSphere(string name, double semiMajorAxis, double inverseFlattening, LinearUnit linearUnit)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException("Invalid name");
return new Ellipsoid(semiMajorAxis, -1, inverseFlattening, true, linearUnit, name, string.Empty, -1, string.Empty, string.Empty, string.Empty);
}
/// <summary>
/// Creates a <see cref="ProjectedCoordinateSystem"/> using a projection object.
/// </summary>
/// <param name="name">Name of projected coordinate system</param>
/// <param name="gcs">Geographic coordinate system</param>
/// <param name="projection">Projection</param>
/// <param name="linearUnit">Linear unit</param>
/// <param name="axis0">Primary axis</param>
/// <param name="axis1">Secondary axis</param>
/// <returns>Projected coordinate system</returns>
public ProjectedCoordinateSystem CreateProjectedCoordinateSystem(string name, GeographicCoordinateSystem gcs, IProjection projection, LinearUnit linearUnit, AxisInfo axis0, AxisInfo axis1)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException("Invalid name", nameof(name));
if (gcs == null)
throw new ArgumentException("Geographic coordinate system was null", nameof(gcs));
if (projection == null)
throw new ArgumentException("Projection was null", nameof(projection));
if (linearUnit == null)
throw new ArgumentException("Linear unit was null");
var info = new List<AxisInfo>(2);
info.Add(axis0);
info.Add(axis1);
return new ProjectedCoordinateSystem(null, gcs, linearUnit, projection, info, name, string.Empty, -1, string.Empty, string.Empty, string.Empty);
}
/// <summary>
/// Creates a <see cref="Projection"/>.
/// </summary>
/// <param name="name">Name of projection</param>
/// <param name="wktProjectionClass">Projection class</param>
/// <param name="parameters">Projection parameters</param>
/// <returns>Projection</returns>
public IProjection CreateProjection(string name, string wktProjectionClass, List<ProjectionParameter> parameters)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException("Invalid name");
if (parameters == null || parameters.Count == 0)
throw new ArgumentException("Invalid projection parameters");
return new Projection(wktProjectionClass, parameters, name, string.Empty, -1, string.Empty, string.Empty, string.Empty);
}
/// <summary>
/// Creates <see cref="HorizontalDatum"/> from ellipsoid and Bursa-World parameters.
/// </summary>
/// <remarks>
/// Since this method contains a set of Bursa-Wolf parameters, the created
/// datum will always have a relationship to WGS84. If you wish to create a
/// horizontal datum that has no relationship with WGS84, then you can
/// either specify a <see cref="DatumType">horizontalDatumType</see> of <see cref="DatumType.HD_Other"/>, or create it via WKT.
/// </remarks>
/// <param name="name">Name of ellipsoid</param>
/// <param name="datumType">Type of datum</param>
/// <param name="ellipsoid">Ellipsoid</param>
/// <param name="toWgs84">Wgs84 conversion parameters</param>
/// <returns>Horizontal datum</returns>
public HorizontalDatum CreateHorizontalDatum(string name, DatumType datumType, Ellipsoid ellipsoid, Wgs84ConversionInfo toWgs84)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException("Invalid name");
if (ellipsoid == null)
throw new ArgumentException("Ellipsoid was null");
return new HorizontalDatum(ellipsoid, toWgs84, datumType, name, string.Empty, -1, string.Empty, string.Empty, string.Empty);
}
/// <summary>
/// Creates a <see cref="PrimeMeridian"/>, relative to Greenwich.
/// </summary>
/// <param name="name">Name of prime meridian</param>
/// <param name="angularUnit">Angular unit</param>
/// <param name="longitude">Longitude</param>
/// <returns>Prime meridian</returns>
public PrimeMeridian CreatePrimeMeridian(string name, AngularUnit angularUnit, double longitude)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException("Invalid name");
return new PrimeMeridian(longitude, angularUnit, name, string.Empty, -1, string.Empty, string.Empty, string.Empty);
}
/// <summary>
/// Creates a <see cref="GeographicCoordinateSystem"/>, which could be Lat/Lon or Lon/Lat.
/// </summary>
/// <param name="name">Name of geographical coordinate system</param>
/// <param name="angularUnit">Angular units</param>
/// <param name="datum">Horizontal datum</param>
/// <param name="primeMeridian">Prime meridian</param>
/// <param name="axis0">First axis</param>
/// <param name="axis1">Second axis</param>
/// <returns>Geographic coordinate system</returns>
public GeographicCoordinateSystem CreateGeographicCoordinateSystem(string name, AngularUnit angularUnit, HorizontalDatum datum, PrimeMeridian primeMeridian, AxisInfo axis0, AxisInfo axis1)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException("Invalid name");
var info = new List<AxisInfo>(2);
info.Add(axis0);
info.Add(axis1);
return new GeographicCoordinateSystem(angularUnit, datum, primeMeridian, info, name, string.Empty, -1, string.Empty, string.Empty, string.Empty);
}
/*
/// <summary>
/// Creates a <see cref="ILocalDatum"/>.
/// </summary>
/// <param name="name">Name of datum</param>
/// <param name="datumType">Datum type</param>
/// <returns></returns>
public ILocalDatum CreateLocalDatum(string name, DatumType datumType)
{
throw new NotImplementedException();
}
*/
/// <summary>
/// Creates a <see cref="VerticalDatum"/> from an enumerated type value.
/// </summary>
/// <param name="name">Name of datum</param>
/// <param name="datumType">Type of datum</param>
/// <returns>Vertical datum</returns>
public VerticalDatum CreateVerticalDatum(string name, DatumType datumType)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException("Invalid name");
return new VerticalDatum(datumType, name, string.Empty, -1, string.Empty, string.Empty, string.Empty);
}
/// <summary>
/// Creates a <see cref="VerticalCoordinateSystem"/> from a <see cref="VerticalDatum">datum</see> and <see cref="LinearUnit">linear units</see>.
/// </summary>
/// <param name="name">Name of vertical coordinate system</param>
/// <param name="datum">Vertical datum</param>
/// <param name="verticalUnit">Unit</param>
/// <param name="axis">Axis info</param>
/// <returns>Vertical coordinate system</returns>
public VerticalCoordinateSystem CreateVerticalCoordinateSystem(string name, VerticalDatum datum, LinearUnit verticalUnit, AxisInfo axis)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException("Invalid name");
return new VerticalCoordinateSystem(verticalUnit, datum, axis, name, string.Empty, -1, string.Empty, string.Empty, string.Empty);
}
/// <summary>
/// Creates a <see cref="CreateGeocentricCoordinateSystem"/> from a <see cref="HorizontalDatum">datum</see>,
/// <see cref="LinearUnit">linear unit</see> and <see cref="PrimeMeridian"/>.
/// </summary>
/// <param name="name">Name of geocentric coordinate system</param>
/// <param name="datum">Horizontal datum</param>
/// <param name="linearUnit">Linear unit</param>
/// <param name="primeMeridian">Prime meridian</param>
/// <returns>Geocentric Coordinate System</returns>
public GeocentricCoordinateSystem CreateGeocentricCoordinateSystem(string name, HorizontalDatum datum, LinearUnit linearUnit, PrimeMeridian primeMeridian)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException("Invalid name");
var info = new List<AxisInfo>(3);
info.Add(new AxisInfo("X", AxisOrientationEnum.Other));
info.Add(new AxisInfo("Y", AxisOrientationEnum.Other));
info.Add(new AxisInfo("Z", AxisOrientationEnum.Other));
return new GeocentricCoordinateSystem(datum, linearUnit, primeMeridian, info, name, string.Empty, -1, string.Empty, string.Empty, string.Empty);
}
}
}