Re: GPS Class that maps Lat/Long to UTM Coordinates (WGS84 and others)
Very nice! I downloaded this for two reasons. The first was to learn how to convert UTM to Lat/Long (and vice versa). The second was as an example of a Class. Being a relative newcomer to the whole OOP thing (though I've had many years of programming experience), I wanted to learn more about it.
Quick question. Would this class be a good place to put conversion routines for doing the various lat/long formats (DMS.dd, DM.dd, D.dd)?
Thanks for the code!
Larry
Re: GPS Class that maps Lat/Long to UTM Coordinates (WGS84 and others)
Absolutely! Classes are as flexible as you need them to be. :D
Re: GPS Class that maps Lat/Long to UTM Coordinates (WGS84 and others)
We are looking to use this in a research project. Is there a license agreement for this code?
Re: GPS Class that maps Lat/Long to UTM Coordinates (WGS84 and others)
Nope, freeware as far as I'm concerned. That's why it's posted on here.
Re: GPS Class that maps Lat/Long to UTM Coordinates (WGS84 and others)
I'm afraid your class is extremely accurate and useful.
Also for peeps who be tryin to convert to C#. This is what I did:
1) Create a VB Library Project.
2) Add the GPS.vb class
3) Compile
4) Start a new C# project
5) Reference the first VB Library Project directly or through the compiled DLL
6) There you can use the class as if it were c#
Anw. Thanks again. You have saved so many lives by posting this code.
Re: GPS Class that maps Lat/Long to UTM Coordinates (WGS84 and others)
It seems like a simple question, but i just cant seem to work it out.
I have Eastings, Northings, Hemisphere and the Zone, I can get the class to work and it outputs Latitudes and Logditudes for me, but they are in DMS, but I really need to get the output in Decimal Long/Lat.
I know im missing something simple.
this is the code i use to output the Long/Lat, is there a conversion function?
Quote:
Dim utm As New GPS.UTM(Northing, Easting, Zone)
utm.UTMLatitudeHemisphere = GPS.UTMLat.South
MyLatitude = utm.Latitude.ToString
MyLongitude = utm.Longitude.ToString
i feel like it should be
Quote:
MyLatitude = utm.Decimal.Latitude.ToString
MyLongitude = utm.Decimal.Longitude.ToString
Or something similar.
Thanks, Mike
Re: GPS Class that maps Lat/Long to UTM Coordinates (WGS84 and others)
To get decimal degrees, it's
degrees + (minutes/60) + (seconds/3600)
Re: GPS Class that maps Lat/Long to UTM Coordinates (WGS84 and others)
To get decimal degrees, it's
degrees + (minutes/60) + (seconds/3600)
Re: GPS Class that maps Lat/Long to UTM Coordinates (WGS84 and others)
Quote:
Originally Posted by
lar3ry
To get decimal degrees, it's
degrees + (minutes/60) + (seconds/3600)
I understand the Maths involved, im just unsure of how to implement this. Would i do it in the GPS.vb class or would i do this in my function?
This is a snippet of my code:
Quote:
If reader.HasRows Then
While reader.Read()
Northing = reader("Northing")
Easting = reader("Easting")
CarNumber = reader("CarNbr")
Zone = reader("Zone")
Dim utm As New GPS.UTM(Northing, Easting, Zone)
utm.UTMLatitudeHemisphere = GPS.UTMLat.South
MyLatitude = utm.Latitude.ToString
MyLongitude = utm.Longitude.ToString
Lats = Left(MyLatitude, Len(MyLatitude) - 6)
Longs = Left(MyLongitude, Len(MyLongitude) - 5)
'LongsDblQotPos = InStr(Longs, """)
'LongsSnglQotPos = InStr(Longs, "'")
'LongsMin = Mid(Longs, 6, Len(Longs) - 7 - LongsSnglQotPos)
'LongsSec = Mid(Longs, LongsSnglQotPos + 2, Len(Longs) - (LongsSnglQotPos + 2))
'LongsDecimal = (((LongsSec / 60) + LongsMin) / 60) + 27
'LatsDblQotPos = InStr(Lats, """)
'LatsSnglQotPos = InStr(Lats, "'")
'LatsMin = Mid(Lats, 5, Len(Lats) - 6 - LatsSnglQotPos)
'LatsSec = Mid(Lats, LatsSnglQotPos + 2, Len(Lats) - (LatsSnglQotPos + 2))
'LatsDecimal = CDbl(Val((((LatsSec / 60) + LatsMin) / 60) + 153))
My.Computer.FileSystem.WriteAllText("C:\TestCopy.txt", "['Car:" & CarNumber & "'," & " -" & Lats & "," & " " & Longs & ", " & index & "]" & Chr(10), True)
index = index + 1
End While
End If
It reads the values from a DB then converts them from UTM to Lat Long, but my application needs lat longs in decimal format. Im just unsure of how to do that.
Re: GPS Class that maps Lat/Long to UTM Coordinates (WGS84 and others)
Dismiss my last question... it seems with a little more obvious thinking i worked it out!
Quote:
If reader.HasRows Then
While reader.Read()
Northing = reader("Northing")
Easting = reader("Easting")
CarNumber = reader("CarNbr")
Zone = reader("Zone")
Dim utm As New GPS.UTM(Northing, Easting, Zone)
utm.UTMLatitudeHemisphere = GPS.UTMLat.South
MyLatitude = utm.Latitude.ToString
MyLongitude = utm.Longitude.ToString
LatsDecimal = utm.Latitude.Degrees + (utm.Latitude.Minutes / 60) + (utm.Latitude.Seconds / 3600)
LongsDecimal = utm.Longitude.Degrees + (utm.Longitude.Minutes / 60) + (utm.Longitude.Seconds / 3600)
My.Computer.FileSystem.WriteAllText("C:\TestCopy.txt", "['Car:" & CarNumber & "'," & " -" & LatsDecimal & "," & " " & LongsDecimal & ", " & index & "]," & Chr(10), True)
index = index + 1
End While
End If
Re: GPS Class that maps Lat/Long to UTM Coordinates (WGS84 and others)
Hi Jenner - I have implemented your code to geolocate aerial images - and the locations are only somewhat close. I have a centroid located at 35.44752324, -119.0344939 and the UTM comes out as 11N 3925110.67478774, 314745.859021866 - this is about 373 and 741 meters off. The Lat/Lon are in WGS84, and I am loading the resulting UTM Arcmap using NAD83_UTM_Zone11 as my projection. . Thanks for your help
Re: GPS Class that maps Lat/Long to UTM Coordinates (WGS84 and others)
I see a lot of posts here requesting decimal Lat/Long output instead of ddd mm' ss.ss".
So, I added two read only properties to the class. Here is the code with the new parts highlighted:
Added two local private double variables...
Code:
Public Class UTM
Private Const k0 As Double = 0.9996
Private cooLat As New Coordinate(0, CoordinateType.Latitude)
Private cooLong As New Coordinate(0, CoordinateType.Longitude)
Private utmDat As UTMDatum = UTMDatum.WGS84
Private dblNorthing As Double = 0
Private dblEasting As Double = 0
Private DecLat As Double = 0.0
Private DecLong As Double = 0.0
Private utmL As UTMLat = UTMLat.North
Private intZone As Int32
Added two read only properties...
Code:
#Region "Properties"
.
.
.
Public ReadOnly Property DecLatitude() As Double
Get
Return DecLat
End Get
End Property
Public ReadOnly Property DecLongitude() As Double
Get
Return DecLong
End Get
End Property
.
.
.
#End Region
Filled in the private class variables with the values in the UTM to LL conversion ....
Code:
Public Sub GetLatLong()
.
.
.
cooLat = New Coordinate(Convert.ToDecimal(lat), CoordinateType.Latitude)
DecLat = lat
Dim lon As Double = GetZoneCM() - ((lof1 - lof2 + lof3) / Math.Cos(phi1)) * 180 / Math.PI
DecLong = lon
cooLong = New Coordinate(Convert.ToDecimal(lon), CoordinateType.Longitude)
End Sub
My question to the forum here is, has anyone seen a class like this, but for U.S. State-Planes <-> LatLong ?
Korg sends
Re: GPS Class that maps Lat/Long to UTM Coordinates (WGS84 and others)
I have been testing the class and it works well ... thank you.
When I try to convert a UTM coordinate to a Lat/Long coordinate, the latitude is off slightly but the longitude is the same. I am comparing my results to the National Resources Canada website at:
http://webapp.geod.nrcan.gc.ca/geod/...outils/trx.php.
The values I am using are:
N: 5453095.17
E: 704731.39
Zone: 13
The results I get from the class are:
Lat: 49.196384246396228 (49° 11' 46.9833")
Long: -102.18969397760389 (-102° 11' 22.8983")
but the results from the Geodetic site are:
Lat: 49° 11' 47.17321"
Long: -102° 11' 22.89833"
From other samples I tested, it appears that the longitude is always the same but the latitude is always off a bit.
Here is the code I am using:
Dim utm As New clsGPS.UTM(myNorthing, myEasting, Zone)
utm.UTMLatitudeHemisphere = clsGPS.UTMLat.North
lat = utm.Latitude.GetDecimalCoordinate
lon = utm.Longitude.GetDecimalCoordinate
Am I missing something?
Blair
Re: GPS Class that maps Lat/Long to UTM Coordinates (WGS84 and others)
I made some changes in the function GetLatLong() that solve the problem in the south hemisphere, added local variable dNorth and dEast :
Dim dNorth As Double = 0
Dim dEast As Double = 0
' dblNorthing = If(utmL = UTMLat.North, dblNorthing, 10000000 - dblNorthing)
dNorth = If(utmL = UTMLat.North, dblNorthing, 10000000 - dblNorthing)
dEast = dblEasting
Dim arc As Double = dNorth / k0