History

GSF.Geo: Added the GSF.Geo project to the solution.

StephenCWills committed 10 years ago

Commit 67d77d31 parent 242adea11 files · +861 −1Browse files

Showing the changes to Source/Libraries/GSF.Geo/CoordinateReferenceSystem.cs (1 of 11 files). Show all

Unified · Split

Source/Libraries/GSF.Geo/CoordinateReferenceSystem.cs+134−0
@@ -0,0 +1,134 @@
1+//******************************************************************************************************
2+// CoordinateReferenceSystem.cs - Gbtc
3+//
4+// Copyright © 2016, Grid Protection Alliance. All Rights Reserved.
5+//
6+// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
7+// the NOTICE file distributed with this work for additional information regarding copyright ownership.
8+// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may
9+// not use this file except in compliance with the License. You may obtain a copy of the License at:
10+//
11+// http://opensource.org/licenses/MIT
12+//
13+// Unless agreed to in writing, the subject software distributed under the License is distributed on an
14+// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
15+// License for the specific language governing permissions and limitations.
16+//
17+// Code Modification History:
18+// ----------------------------------------------------------------------------------------------------
19+// 08/20/2016 - Stephen C. Wills
20+// Generated original version of source code.
21+//
22+//******************************************************************************************************
23+
24+#region [ Contributor License Agreements ]
25+
26+/*
27+ Copyright (c) 2010-2016, Vladimir Agafonkin
28+ Copyright (c) 2010-2011, CloudMade
29+ All rights reserved.
30+
31+ Redistribution and use in source and binary forms, with or without modification, are
32+ permitted provided that the following conditions are met:
33+
34+ 1. Redistributions of source code must retain the above copyright notice, this list of
35+ conditions and the following disclaimer.
36+
37+ 2. Redistributions in binary form must reproduce the above copyright notice, this list
38+ of conditions and the following disclaimer in the documentation and/or other materials
39+ provided with the distribution.
40+
41+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
42+ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
43+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
44+ COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
46+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
48+ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
49+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50+*/
51+
52+#endregion
53+
54+using System;
55+using GSF.Drawing;
56+
57+namespace GSF.Geo
58+{
59+ /// <summary>
60+ /// Abstract class that defines coordinate reference systems for projecting
61+ /// geographical points into pixel (screen) coordinates and back.
62+ /// </summary>
63+ /// <remarks>http://en.wikipedia.org/wiki/Coordinate_reference_system</remarks>
64+ public abstract class CoordinateReferenceSystem
65+ {
66+ /// <summary>
67+ /// Gets the projection used by the CRS.
68+ /// </summary>
69+ public abstract IProjection Projection { get; }
70+
71+ /// <summary>
72+ /// Gets the transformation used by the CRS.
73+ /// </summary>
74+ public abstract Transformation Transformation { get; }
75+
76+ /// <summary>
77+ /// Translates the given geographical coordinate
78+ /// to a cartesian point at the given zoom level.
79+ /// </summary>
80+ /// <param name="coordinate">The coordinate to be translated.</param>
81+ /// <param name="zoom">The zoom level.</param>
82+ /// <returns>The cartesian point corresponding to the given coordinate.</returns>
83+ public virtual Point Translate(GeoCoordinate coordinate, double zoom)
84+ {
85+ Point projectedPoint = Projection.Project(coordinate);
86+ double scale = Scale(zoom);
87+ return Transformation.Transform(projectedPoint, scale);
88+ }
89+
90+ /// <summary>
91+ /// Translates the given cartesian point to a
92+ /// geographical coordinate at the given zoom level.
93+ /// </summary>
94+ /// <param name="point">The point to be translated.</param>
95+ /// <param name="zoom">The zoom level.</param>
96+ /// <returns>The geographical location of the point.</returns>
97+ public virtual GeoCoordinate Translate(Point point, double zoom)
98+ {
99+ double scale = Scale(zoom);
100+ Point untransformedPoint = Transformation.Untransform(point, scale);
101+ return Projection.Unproject(untransformedPoint);
102+ }
103+
104+ /// <summary>
105+ /// Returns the scale used when transforming projected coordinates into
106+ /// pixel coordinates for a particular zoom. For example, it returns
107+ /// <c>256 * 2^zoom</c> for Mercator-based CRS.
108+ /// </summary>
109+ /// <param name="zoom">The zoom level.</param>
110+ /// <returns>The scale at the given zoom level.</returns>
111+ public virtual double Scale(double zoom)
112+ {
113+ return 256 * Math.Pow(2, zoom);
114+ }
115+
116+ /// <summary>
117+ /// Returns the zoom level corresponding to the given scale factor.
118+ /// </summary>
119+ /// <param name="scale">The scale factor.</param>
120+ /// <returns>The zoom level corresponding to the given scale factor.</returns>
121+ public virtual double Zoom(double scale)
122+ {
123+ return Math.Log(scale / 256) / Math.Log(2);
124+ }
125+
126+ /// <summary>
127+ /// Returns the distance between two geographical coordinates.
128+ /// </summary>
129+ /// <param name="coordinate1">The first geographical coordinate.</param>
130+ /// <param name="coordinate2">The second geographical coordinate.</param>
131+ /// <returns>The distance between two geographical coordinates.</returns>
132+ public abstract double Distance(GeoCoordinate coordinate1, GeoCoordinate coordinate2);
133+ }
134+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t