MapWinGIS:SampleCode-VB Net:ObtainGeodesic

This is a back-up of the WIKI.
Not all links might work
We're working on a new wiki.

Main Page | Recent changes | View source | Page history | Log in / create account |

Printable version | Disclaimers | Privacy policy

Obtain Geodesic

This function is for Visual Studios 2005 version of visual basic net. Polylines can be constructed from a sequence of points. This function illustrates how to obtain some representative points in order to model a geodesic curve.

[Illustration]


      <summary>
      Returns an array of MapWinGIS.Points contianing numPoints individual points that define
      a curved geodesic pathway between the two points.  All point values are assumed to be
      in terms of latitude and longitude
      </summary>
      <param name="ptStart">A MapWinGIS Point in Lat/Lon where the curve starts</param>
      <param name="ptEnd">A MapWinGIS Point in Lat/Lon where the curve ends</param>
      <param name="numPoints">An Integer indicating the number of points</param>
      <returns>an array of MapWinGIS Points with numPoints values</returns>
      <remarks></remarks>
     Public Function GeoDesic(ByVal ptStart As MapWinGIS.Point, _
                              ByVal ptEnd As MapWinGIS.Point, _
                              ByVal numPoints As Integer) As MapWinGIS.Point()
 
         Dim PointList(numPoints) As MapWinGIS.Point
         Dim I As Integer ' Loop index.  I is the value of the intermediate point.
         Dim ptStartC As New MapWinGIS.Point ' Start in 3D Cartesian coordinates 
         Dim ptEndC As New MapWinGIS.Point   ' End in 3D Cartesian coordinates
         Dim C As Double ' The ratio of the real radius of earth to the cord at point I
         Dim pt As MapWinGIS.Point ' the intermediary point to work with 
         ' In ptStart and ptEnd, X = Longitude, Y = Latitude and Radius earth = 6378 km
         ptStart.x = ptStart.x * 3.14159 / 180
         ptStart.y = ptStart.y * 3.14159 / 180
         ptEnd.x = ptEnd.x * 3.14159 / 180
         ptEnd.y = ptEnd.y * 3.14159 / 180
         ptStartC.x = 6378 * Math.Cos(ptStart.x) * Math.Cos(ptStart.y) ' X = R cos(LON) cos(LAT) 
         ptStartC.y = 6378 * Math.Sin(ptStart.x) * Math.Cos(ptStart.y) ' Y = R sin(LON)cos(LAT) 
         ptStartC.Z = 6378 * Math.Sin(ptStart.y)                       ' Z = R sin(LAT) 
         ptEndC.x = 6378 * Math.Cos(ptEnd.x) * Math.Cos(ptEnd.y) ' X = R cos(LON) cos(LAT) 
         ptEndC.y = 6378 * Math.Sin(ptEnd.x) * Math.Cos(ptEnd.y) ' Y = R sin(LON)cos(LAT) 
         ptEndC.Z = 6378 * Math.Sin(ptEnd.y)                     ' Z = R sin(LAT) 
         For I = 0 To numPoints ' the output should also include the start and end points
             pt = New MapWinGIS.Point ' Each time we are creating a new intermediary point
             pt.x = ptStartC.x + I * (ptEndC.x - ptStartC.x) / numPoints
             pt.y = ptStartC.y + I * (ptEndC.y - ptStartC.y) / numPoints
             pt.Z = ptStartC.Z + I * (ptEndC.Z - ptStartC.Z) / numPoints
             'C = R / SQRT(X^2 + Y^2 + Z^2) where X, Y, Z are on the chord that actually goes through the earth
             C = 6378 / Math.Sqrt(Math.Pow(pt.x, 2) + Math.Pow(pt.y, 2) + Math.Pow(pt.Z, 2))
             pt.x = pt.x * C
             pt.y = pt.y * C
             pt.Z = pt.Z * C
             PointList(I) = New MapWinGIS.Point
             'Longitude
             PointList(I).x = Math.Atan(pt.y / pt.x) * 180 / 3.14159
             'Latitude
             PointList(I).y = Math.Asin(pt.Z / 6378) * 180 / 3.14159
         Next I
         Return PointList
     End Function

Code posted by Shade1974 on Sept 11, 2006 Last Modified on Sept. 13, 2006

Retrieved from "http://mapwindow.org/wiki/index.php/MapWinGIS:SampleCode-VB_Net:ObtainGeodesic"

This page has been accessed 2,183 times. This page was last modified on 13 September 2006, at 23:58.