|
''' <summary>
''' Represents the Equidistant Cylindrical map projection.
''' </summary>
''' <remarks>Map projections are used to flatten 3D coordinates into a 2D form which can be displayed
''' easily on a computer screen. This class provides two methods, Project and Deproject, which convert
''' convert geographic coordinates to projected coordinates, and vice versa.</remarks>
Public Class MapProjection
' Many map projections work with coordinates in the form of radians instead of degrees.
' These constants will help us convert back and forth.
Private Const DEGREEStoRADIANS As Double = Math.PI / 180
Private Const RADIANStoDEGREES As Double = 180 / Math.PI
' These values represent the equatorial radius of the WGS84 ellipsoid in meters.
' resulting in projected coordinates which are also in meters
Private Const WGS84SEMIMAJOR As Double = 6378137
Private Const ONEOVERWGS84SEMIMAJOR As Double = 1 / WGS84SEMIMAJOR
Public Sub New()
End Sub
''' <summary>
''' Converts a geographic coordinate into a projected coordinate.
''' </summary>
''' <param name="geographicCoordinate">A <strong>PointF</strong> object, representing a geographic coordinate.</param>
''' <returns>A projected coordinate in the form of a <strong>PointF</strong> object.</returns>
Public Function Project(ByVal geographicCoordinate As PointF) As PointF
' First, convert the geographic coordinate to radians
Dim radianX As Double = geographicCoordinate.X * DEGREEStoRADIANS
Dim radianY As Double = geographicCoordinate.Y * DEGREEStoRADIANS
' Make a new Point object
Dim result As New PointF()
' Calculate the projected X coordinate
result.X = Convert.ToSingle(radianX * Math.Cos(0) * WGS84SEMIMAJOR)
' Calculate the projected Y coordinate
result.Y = Convert.ToSingle(radianY * WGS84SEMIMAJOR)
' Return the result
Return result
End Function
''' <summary>
''' Converts a projected coordinate to a geographic coordinate.
''' </summary>
''' <param name="projectedCoordinate">A <strong>PointF</strong> object, representing a projected coordinate.</param>
''' <returns>A geographic coordinate in the form of a <strong>PointF</strong> object.</returns>
Public Function Deproject(ByVal projectedCoordinate As PointF) As PointF
' Make a new point to store the result
Dim result As New PointF()
' Calculate the geographic X coordinate (longitude)
result.X = Convert.ToSingle(projectedCoordinate.X / Math.Cos(0) * RADIANStoDEGREES * ONEOVERWGS84SEMIMAJOR)
' Calculate the geographic Y coordinate (latitude)
result.Y = Convert.ToSingle(projectedCoordinate.Y * RADIANStoDEGREES * ONEOVERWGS84SEMIMAJOR)
Return result
End Function
End Class
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Hi there! From 2004 to 2009 I ran a company called "GeoFrameworks," publishing two components called GPS.NET and GIS.NET which helped developers quickly write location-based services. Now, I've released the source code for GPS.NET to CodePlex for you to use as you see fit.
GPS.NET 2.0 on CodePlex
GPS.NET 3.0 on CodePlex
... I've also released the source code of a library called the "GeoFramework," a collection of commonly used classes such as
Latitude,
Longitude,
Distance,
Speed, and
Position:
GeoFramework 1.0 on CodePlex
GeoFramework 2.0 on CodePlex
I'm now taking a break from programming, but I really appreciate the positive feedback from readers!
Phil has a highly technical mind as well as having adepts in both art and music. His twenty-five years of computer experience brings knowledge to the table for any enterprise endeavor. But his skills in problem solving provide practical solutions to a myriad of problems, both technical and administrative. He also has a propensity for math and science that suit him well for tasks associated with geospacial information systems.
As a .Net architect and developer, Phil has six years under his belt in C# development, on top of twelve years of Visual Basic, starting with version four. He has an extensive background in business enterprise development, which includes SQL server database design and development. Now Phil prefers to exercise his talents in fields of science and mathematics.