{"id":81,"date":"2008-11-15T12:19:57","date_gmt":"2008-11-15T05:19:57","guid":{"rendered":"http:\/\/arif.unpad.ac.id\/?p=81"},"modified":"2008-11-15T12:19:57","modified_gmt":"2008-11-15T05:19:57","slug":"convert-degrees-coordinates-longitude-latitude-to-utm-coordinates","status":"publish","type":"post","link":"https:\/\/blogs.unpad.ac.id\/arif\/2008\/11\/15\/convert-degrees-coordinates-longitude-latitude-to-utm-coordinates\/","title":{"rendered":"Convert Degrees Coordinates (Longitude Latitude ) to UTM coordinates"},"content":{"rendered":"<p>Imagine, digital earth maps now just like real earth. Just look at Google Earth or Microsoft Virtual Earth, satellite photo result can show free for us. It will be nice if we have mobile gadget with GPS, we will always know where are we. Technicaly Map in software world has to be trend begin when GIS needs increase. Some developer confuse with coordinates what is UTM or what is Degree. Same with me, i have problem to build GIS system and I use SVG or XAML to make a map, generated from ArcView or mapinfo. The booth software support any coordinates type, but our client use degrees format to put the location. SVG or XAML are not support using degress, they both just support using coordinates X,Y. So I make the function to convert Degrees to UTM or UTM to Degrees.<\/p>\n<p><!--more--><\/p>\n<p>\u00a0<\/p>\n<pre>Public Class Ellipsoid\n    Public id As Integer\n    Public ellipsoidName As String\n    Public EquatorialRadius As Double\n    Public eccentricitySquared As Double\n    Const PI As Double = 3.14159265\n    Const FOURTHPI As Double = PI \/ 4\n    Const deg2rad As Double = PI \/ 180\n    Const rad2deg As Double = 180.0 \/ PI\n    Const oneMiles = 1609.344\n    Const oneFoot = 0.3048\n    Const oneDegreeLat = 111044.736\n    Const oneMinuteLat = 1850.7456\n    Const oneSecondLat = 30.84576\n    Const oneDegreeLong = 67592.448\n    Const oneMinuteLong = 1126.5408\n    Const oneSecondLong = 18.77568\n\n    Public Sub New(ByVal iid As Integer, ByVal sname As String, ByVal radius As Double, ByVal ecc As Double)\n        id = iid\n        ellipsoidName = sname\n        EquatorialRadius = radius\n        eccentricitySquared = ecc\n    End Sub\n    Public Sub New(ByVal iid As Integer)\n        SetID(iid)\n    End Sub\n\n    Sub GPS2XY(ByVal gpspos As String, ByRef x As Double, ByRef y As Double)\n        If gpspos &lt;&gt; \"\" Then\n            Dim latdeg As String = \"\"\n            Dim longdeg As String = \"\"\n            Dim UTMZone As String = \"\"\n            GPS2LATLONGDeg(gpspos, latdeg, longdeg)\n\n            Dim lat As Double = DegMinSec2Deg(latdeg)\n            Dim longi As Double = DegMinSec2Deg(longdeg)\n\n            LLtoUTM(lat, longi, x, y, UTMZone)\n            If InStr(gpspos, \"S\") &gt; 0 Then y = -1 * Math.Abs(y)\n            'If InStr(gpspos, \"E\") &gt; 0 Then x = -1 * Math.Abs(x)\n\n        Else\n            x = 0\n            y = 0\n        End If\n    End Sub\n    Sub GPS2LATLONGDeg(ByVal gpspos As String, ByRef latdeg As String, ByRef longdeg As String)\n        gpspos = gpspos.Replace(\";\", \"\")\n        gpspos = gpspos.Replace(\":\", \"\")\n        Dim charx As String = IIf(InStr(gpspos, \"N\") &gt; 0, \"N\", \"S\")\n        Dim chary As String = IIf(InStr(gpspos, \"E\") &gt; 0, \"E\", \"W\")\n        latdeg = Trim(Mid(gpspos, InStr(gpspos, charx) + 1, InStr(gpspos, chary) - 2))\n        longdeg = Trim(Mid(gpspos, InStr(gpspos, chary) + 1))\n        If InStr(gpspos, \"S\") &gt; 0 Then latdeg = \"-\" &amp; latdeg\n        If InStr(gpspos, \"W\") &gt; 0 Then longdeg = \"-\" &amp; longdeg\n\n    End Sub\n    Function DegMinSec2Deg(ByVal degree As String) As Double\n        Dim ddegree As Double = 0\n        Dim dminute As Double = 0\n        Dim dsecond As Double = 0\n        Dim ismin As Boolean = (InStr(degree, \"-\") &gt; 0)\n        Dim lat As Double = 0\n        If InStr(UCase(degree), \"D\") &gt; 0 Then\n            ddegree = CDbl(Trim(Mid(degree, 1, InStr(UCase(degree), \"D\") - 1)))\n            degree = Trim(Mid(degree, InStr(UCase(degree), \"D\") + 1))\n        ElseIf InStr(degree, Chr(176)) &gt; 0 Then\n            ddegree = CDbl(Trim(Mid(degree, 1, InStr(UCase(degree), Chr(176)) - 1)))\n            degree = Trim(Mid(degree, InStr(UCase(degree), Chr(176)) + 1))\n        ElseIf InStr(degree, Chr(186)) &gt; 0 Then\n            ddegree = CDbl(Trim(Mid(degree, 1, InStr(UCase(degree), Chr(186)) - 1)))\n            degree = Trim(Mid(degree, InStr(UCase(degree), Chr(186)) + 1))\n        Else\n            ddegree = 0\n        End If\n        If InStr(UCase(degree), \"'\") &gt; 0 Then\n            dminute = CDbl(Trim(Mid(degree, 1, InStr(UCase(degree), \"'\") - 1)))\n        Else\n            dminute = 0\n        End If\n        degree = Trim(Mid(degree, InStr(UCase(degree), \"'\") + 1))\n        If InStr(UCase(degree), \"\"\"\") &gt; 0 Then\n            dsecond = CDbl(Trim(Mid(degree, 1, InStr(UCase(degree), \"\"\"\") - 1)))\n        ElseIf InStr(UCase(degree), \"''\") &gt; 0 Then\n            dsecond = CDbl(Trim(Mid(degree, 1, InStr(UCase(degree), \"''\") - 1)))\n        Else\n            dsecond = 0\n        End If\n\n        lat = Math.Abs(ddegree) + (Math.Abs(dminute) \/ 60) + (Math.Abs(dsecond) \/ 3600)\n        If ismin Then\n            lat = lat * -1\n        End If\n\n        Return lat\n    End Function\n\n    Public Sub SetValue(ByVal iid As Integer, ByVal sname As String, ByVal radius As Double, ByVal ecc As Double)\n        id = iid\n        ellipsoidName = sname\n        EquatorialRadius = radius\n        eccentricitySquared = ecc\n    End Sub\n\n    Public Sub SetID(ByVal id)\n        If id = -1 Then\n            SetValue(-1, \"Placeholder\", 0, 0)\n        ElseIf id = 1 Then\n            SetValue(1, \"Airy\", 6377563, 0.00667054)\n        ElseIf id = 2 Then\n            SetValue(2, \"Australian National\", 6378160, 0.006694542)\n        ElseIf id = 3 Then\n            SetValue(3, \"Bessel 1841\", 6377397, 0.006674372)\n        ElseIf id = 4 Then\n            SetValue(4, \"Bessel 1841 (Nambia) \", 6377484, 0.006674372)\n        ElseIf id = 5 Then\n            SetValue(5, \"Clarke 1866\", 6378206, 0.006768658)\n        ElseIf id = 6 Then\n            SetValue(6, \"Clarke 1880\", 6378249, 0.006803511)\n        ElseIf id = 7 Then\n            SetValue(7, \"Everest\", 6377276, 0.006637847)\n        ElseIf id = 8 Then\n            SetValue(8, \"Fischer 1960 (Mercury) \", 6378166, 0.006693422)\n        ElseIf id = 9 Then\n            SetValue(9, \"Fischer 1968\", 6378150, 0.006693422)\n        ElseIf id = 10 Then\n            SetValue(10, \"GRS 1967\", 6378160, 0.006694605)\n        ElseIf id = 11 Then\n            SetValue(11, \"GRS 1980\", 6378137, 0.00669438)\n        ElseIf id = 12 Then\n            SetValue(12, \"Helmert 1906\", 6378200, 0.006693422)\n        ElseIf id = 13 Then\n            SetValue(13, \"Hough\", 6378270, 0.00672267)\n        ElseIf id = 14 Then\n            SetValue(14, \"International\", 6378388, 0.00672267)\n        ElseIf id = 15 Then\n            SetValue(15, \"Krassovsky\", 6378245, 0.006693422)\n        ElseIf id = 16 Then\n            SetValue(16, \"Modified Airy\", 6377340, 0.00667054)\n        ElseIf id = 17 Then\n            SetValue(17, \"Modified Everest\", 6377304, 0.006637847)\n        ElseIf id = 18 Then\n            SetValue(18, \"Modified Fischer 1960\", 6378155, 0.006693422)\n        ElseIf id = 19 Then\n            SetValue(19, \"South American 1969\", 6378160, 0.006694542)\n        ElseIf id = 20 Then\n            SetValue(20, \"WGS 60\", 6378165, 0.006693422)\n        ElseIf id = 21 Then\n            SetValue(21, \"WGS 66\", 6378145, 0.006694542)\n        ElseIf id = 22 Then\n            SetValue(22, \"WGS-72\", 6378135, 0.006694318)\n        ElseIf id = 23 Then\n            SetValue(23, \"WGS-84\", 6378137, 0.00669438)\n        End If\n    End Sub\n    Function UTMLetterDesignator(ByVal Lat As Double) As Char\n        Dim LetterDesignator As Char\n        If ((84 &gt;= Lat) And (Lat &gt;= 72)) Then\n            LetterDesignator = \"X\"\n        ElseIf ((72 &gt; Lat) And (Lat &gt;= 64)) Then\n            LetterDesignator = \"W\"\n        ElseIf ((64 &gt; Lat) And (Lat &gt;= 56)) Then\n            LetterDesignator = \"V\"\n        ElseIf ((56 &gt; Lat) And (Lat &gt;= 48)) Then\n            LetterDesignator = \"U\"\n        ElseIf ((48 &gt; Lat) And (Lat &gt;= 40)) Then\n            LetterDesignator = \"T\"\n        ElseIf ((40 &gt; Lat) And (Lat &gt;= 32)) Then\n            LetterDesignator = \"S\"\n        ElseIf ((32 &gt; Lat) And (Lat &gt;= 24)) Then\n            LetterDesignator = \"R\"\n        ElseIf ((24 &gt; Lat) And (Lat &gt;= 16)) Then\n            LetterDesignator = \"Q\"\n        ElseIf ((16 &gt; Lat) And (Lat &gt;= 8)) Then\n            LetterDesignator = \"P\"\n        ElseIf ((8 &gt; Lat) And (Lat &gt;= 0)) Then\n            LetterDesignator = \"N\"\n        ElseIf ((0 &gt; Lat) And (Lat &gt;= -8)) Then\n            LetterDesignator = \"M\"\n        ElseIf ((-8 &gt; Lat) And (Lat &gt;= -16)) Then\n            LetterDesignator = \"L\"\n        ElseIf ((-16 &gt; Lat) And (Lat &gt;= -24)) Then\n            LetterDesignator = \"K\"\n        ElseIf ((-24 &gt; Lat) And (Lat &gt;= -32)) Then\n            LetterDesignator = \"J\"\n        ElseIf ((-32 &gt; Lat) And (Lat &gt;= -40)) Then\n            LetterDesignator = \"H\"\n        ElseIf ((-40 &gt; Lat) And (Lat &gt;= -48)) Then\n            LetterDesignator = \"G\"\n        ElseIf ((-48 &gt; Lat) And (Lat &gt;= -56)) Then\n            LetterDesignator = \"F\"\n        ElseIf ((-56 &gt; Lat) And (Lat &gt;= -64)) Then\n            LetterDesignator = \"E\"\n        ElseIf ((-64 &gt; Lat) And (Lat &gt;= -72)) Then\n            LetterDesignator = \"D\"\n        ElseIf ((-72 &gt; Lat) And (Lat &gt;= -80)) Then\n            LetterDesignator = \"C\"\n        Else\n            LetterDesignator = \"Z\"\n        End If\n        Return LetterDesignator\n    End Function\n\n    Sub LLtoUTM(ByVal Lat As Double, ByVal Longi As Double, ByRef UTMeast As Double, ByRef UTMnorth As Double, ByVal UTMzone As String)\n        Dim eccSquared = eccentricitySquared\n\n        Dim k0 As Double = 0.9996\n        Dim longorigin As Double = 0\n        Dim eccPrimeSquared As Double = 0\n        Dim n, t, c, a, m\n        Dim longtemp As Double = (Longi + 180) - Int((Longi + 180) \/ 360) * 360 - 180\n        Dim LatRad As Double = Lat * deg2rad\n        Dim LongRad As Double = longtemp * deg2rad\n        Dim LongOriginRad As Double = 0\n        Dim ZoneNumber As Integer\n\n        ZoneNumber = Int((longtemp + 180) \/ 6) + 1\n\n        If (Lat &gt;= 56.0 And Lat &lt; 64.0 And longtemp &gt;= 3.0 And longtemp &lt; 12.0) Then ZoneNumber = 32\n        If (Lat &gt;= 72.0 And Lat &lt; 84.0) Then\n            If (longtemp &gt;= 0.0 And longtemp &lt; 9.0) Then\n                ZoneNumber = 31\n            ElseIf (longtemp &gt;= 9.0 And longtemp &lt; 21.0) Then\n                ZoneNumber = 33\n            ElseIf (longtemp &gt;= 21.0 And longtemp &lt; 33.0) Then\n                ZoneNumber = 35\n            ElseIf (longtemp &gt;= 33.0 And longtemp &lt; 42.0) Then\n                ZoneNumber = 37\n            End If\n        End If\n        longorigin = (ZoneNumber - 1) * 6 - 180 + 3   '+3 puts origin in middle of zone\n        LongOriginRad = longorigin * deg2rad\n\n        'sprintf(UTMZone, \"%d%c\", ZoneNumber, UTMLetterDesignator(Lat));\n        UTMzone = Str(ZoneNumber) &amp; UTMLetterDesignator(Lat)\n\n        eccPrimeSquared = (eccentricitySquared) \/ (1 - eccentricitySquared)\n\n        n = EquatorialRadius \/ Math.Sqrt(1 - eccentricitySquared * Math.Sin(LatRad) * Math.Sin(LatRad))\n        t = Math.Tan(LatRad) * Math.Tan(LatRad)\n        c = eccPrimeSquared * Math.Cos(LatRad) * Math.Cos(LatRad)\n        a = Math.Cos(LatRad) * (LongRad - LongOriginRad)\n\n        m = EquatorialRadius * ((1 - eccentricitySquared \/ 4 - 3 * eccentricitySquared * eccentricitySquared \/ 64 - 5 * eccentricitySquared * eccentricitySquared * eccentricitySquared \/ 256) * LatRad _\n           - (3 * eccentricitySquared \/ 8 + 3 * eccentricitySquared * eccentricitySquared \/ 32 + 45 * eccentricitySquared * eccentricitySquared * eccentricitySquared \/ 1024) * Math.Sin(2 * LatRad) _\n           + (15 * eccentricitySquared * eccentricitySquared \/ 256 + 45 * eccentricitySquared * eccentricitySquared * eccentricitySquared \/ 1024) * Math.Sin(4 * LatRad) _\n           - (35 * eccentricitySquared * eccentricitySquared * eccentricitySquared \/ 3072) * Math.Sin(6 * LatRad))\n\n        UTMeast = (k0 * n * (a + (1 - t + c) * a * a * a \/ 6 _\n                     + (5 - 18 * t + t * t + 72 * c - 58 * eccPrimeSquared) * a * a * a * a * a \/ 120) _\n                     + 500000.0)\n\n        UTMnorth = (k0 * (m + n * Math.Tan(LatRad) * (a * a \/ 2 + (5 - t + 9 * c + 4 * c * c) * a * a * a * a \/ 24 _\n                    + (61 - 58 * t + t * t + 600 * c - 330 * eccPrimeSquared) * a * a * a * a * a * a \/ 720)))\n        If (Lat &lt; 0) Then\n            UTMnorth += 10000000.0 '10000000 meter offset for southern hemisphere\n        End If\n\n    End Sub\n\n    Sub UTMtoLL(ByVal ReferenceEllipsoid As Integer, ByVal UTMNorth As Double, ByVal UTMEast As Double, ByVal UTMZone As Char, _\n     ByRef Lat As Double, ByRef Longi As Double)\n        'converts UTM coords to lat\/long.  Equations from USGS Bulletin 1532\n        'East Longitudes are positive, West longitudes are negative.\n        'North latitudes are positive, South latitudes are negative\n        'Lat and Long are in decimal degrees.\n        'Written by Chuck Gantz- chuck.gantz@globalstar.com\n\n        Dim k0 As Double = 0.9996\n        Dim a As Double = EquatorialRadius\n        Dim eccSquared As Double = eccentricitySquared\n        Dim eccPrimeSquared As Decimal\n        Dim e1 As Double = (1 - Math.Sqrt(1 - eccSquared)) \/ (1 + Math.Sqrt(1 - eccSquared))\n        Dim N1, T1, C1, R1, D, M\n\n        Dim LongOrigin As Double = 0\n\n        Dim mu, phi1, phi1Rad\n\n        Dim x As Double\n        Dim y As Double\n        Dim ZoneNumber As Integer\n        Dim ZoneLetter As String\n        Dim NorthernHemisphere As Integer '1 for northern hemispher, 0 for southern\n\n        x = UTMEast - 500000.0 'remove 500,000 meter offset for longitude\n        y = UTMNorth\n\n        ZoneNumber = Mid(UTMZone, 1, Len(UTMZone) - 1)\n        ZoneLetter = Mid(UTMZone, Len(UTMZone) - 1)\n        ' strtoul(UTMZone, &amp;ZoneLetter, 10)\n\n        If ((Asc(ZoneLetter) - Asc(\"N\")) &gt;= 0) Then\n            NorthernHemisphere = 1 'point is in northern hemisphere\n        Else\n            NorthernHemisphere = 0 'point is in southern hemisphere\n            y -= 10000000.0 'remove 10,000,000 meter offset used for southern hemisphere\n        End If\n\n        LongOrigin = (ZoneNumber - 1) * 6 - 180 + 3 '+3 puts origin in middle of zone\n\n        eccPrimeSquared = (eccSquared) \/ (1 - eccSquared)\n\n        M = y \/ k0\n        mu = M \/ (a * (1 - eccSquared \/ 4 - 3 * eccSquared * eccSquared \/ 64 - 5 * eccSquared * eccSquared * eccSquared \/ 256))\n\n        phi1Rad = mu + (3 * e1 \/ 2 - 27 * e1 * e1 * e1 \/ 32) * Math.Sin(2 * mu) _\n                    + (21 * e1 * e1 \/ 16 - 55 * e1 * e1 * e1 * e1 \/ 32) * Math.Sin(4 * mu) _\n                    + (151 * e1 * e1 * e1 \/ 96) * Math.Sin(6 * mu)\n        phi1 = phi1Rad * rad2deg\n\n        N1 = a \/ Math.Sqrt(1 - eccSquared * Math.Sin(phi1Rad) * Math.Sin(phi1Rad))\n        T1 = Math.Tan(phi1Rad) * Math.Tan(phi1Rad)\n        C1 = eccPrimeSquared * Math.Cos(phi1Rad) * Math.Cos(phi1Rad)\n        R1 = a * (1 - eccSquared) \/ Math.Pow(1 - eccSquared * Math.Sin(phi1Rad) * Math.Sin(phi1Rad), 1.5)\n        D = x \/ (N1 * k0)\n\n        Lat = phi1Rad - (N1 * Math.Tan(phi1Rad) \/ R1) * (D * D \/ 2 - (5 + 3 * T1 + 10 * C1 - 4 * C1 * C1 - 9 * eccPrimeSquared) * D * D * D * D \/ 24 _\n            + (61 + 90 * T1 + 298 * C1 + 45 * T1 * T1 - 252 * eccPrimeSquared - 3 * C1 * C1) * D * D * D * D * D * D \/ 720)\n        Lat = Lat * rad2deg\n\n        Longi = (D - (1 + 2 * T1 + C1) * D * D * D \/ 6 + (5 - 2 * C1 + 28 * T1 - 3 * C1 * C1 + 8 * eccPrimeSquared + 24 * T1 * T1) _\n            * D * D * D * D * D \/ 120) \/ Math.Cos(phi1Rad)\n        Longi = LongOrigin + Longi * rad2deg\n\n    End Sub\n\nEnd Class<\/pre>\n<p>This is VB code and run using .NET Fremework 2.0 and tested in google earth and the result is same.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Imagine, digital earth maps now just like real earth. Just look at Google Earth or Microsoft Virtual Earth, satellite photo result can show free for us. It will be nice if we have mobile gadget with GPS, we will always know where are we. Technicaly Map in software world has to be trend begin when [&hellip;]<\/p>\n","protected":false},"author":53,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,47],"tags":[137,179,254,269,512],"class_list":["post-81","post","type-post","status-publish","format-standard","hentry","category-english","category-svg","tag-degree","tag-gis","tag-latitude","tag-longitude","tag-utm"],"_links":{"self":[{"href":"https:\/\/blogs.unpad.ac.id\/arif\/wp-json\/wp\/v2\/posts\/81","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.unpad.ac.id\/arif\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.unpad.ac.id\/arif\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.unpad.ac.id\/arif\/wp-json\/wp\/v2\/users\/53"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.unpad.ac.id\/arif\/wp-json\/wp\/v2\/comments?post=81"}],"version-history":[{"count":0,"href":"https:\/\/blogs.unpad.ac.id\/arif\/wp-json\/wp\/v2\/posts\/81\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.unpad.ac.id\/arif\/wp-json\/wp\/v2\/media?parent=81"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.unpad.ac.id\/arif\/wp-json\/wp\/v2\/categories?post=81"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.unpad.ac.id\/arif\/wp-json\/wp\/v2\/tags?post=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}