2

I need to convert a bunch of coordinates that were stored in Feet to Decimal Degrees. I found a Function in VB.Net, though it's results are not coming back correctly. When I input 3106972, 1417936 into this function I get: -80.7964701731349, 32.8465039721407 where they should be: -105.115621, 40.480104. Where am I going wrong here?

Here is the function:

Private Function ConvertFeetToDecimalDegrees(lat As Integer, lng As Integer) As String
' This function converts coordinates from Florida State Plane North Zone NAD83 feet  
' to Geographic coordinates in decimal degrees  
' Set up the coordinate system parameters.  
Dim A = 20925604.47                         ' major radius of GRS 1980 ellipsoid, feet  
Dim Ec = 0.0818191910435                    ' eccentricity of GRD 1980 ellipsoid  
Dim Ec2 = Ec * Ec                           ' eccentricity squared  
Dim AngRad = 0.0174532925199433             ' number of radians in a degree  
Dim Pi4 = 3.141592653582 / 4                ' Pi / 4  
Dim P1 = 29.583333333333329 * AngRad        ' latitude of first standard parallel  
Dim P2 = 30.75 * AngRad                     ' latitude of second standard parallel  
Dim P0 = 29.0 * AngRad                      ' latitude of origin  
Dim M0 = -84.5 * AngRad                     ' central meridian  
Dim X0 = 1968500.0                          ' False easting of central meridian, map units  

' Calculate the coordinate system constants.  
Dim m1 = Math.Cos(P1) / Math.Sqrt(1 - (Ec2 * Math.Pow((Math.Sin(P1)), 2)))
Dim m2 = Math.Cos(P2) / Math.Sqrt(1 - (Ec2 * Math.Pow((Math.Sin(P2)), 2)))
Dim t1 = Math.Tan(Pi4 - (P1 / 2)) / Math.Pow((1 - Ec * Math.Sin(P1)) / (1 + Ec * Math.Sin(P1)), (Ec / 2))
Dim t2 = Math.Tan(Pi4 - (P2 / 2)) / Math.Pow((1 - Ec * Math.Sin(P2)) / (1 + Ec * Math.Sin(P2)), (Ec / 2))
Dim t0 = Math.Tan(Pi4 - (P0 / 2)) / Math.Pow((1 - Ec * Math.Sin(P0)) / (1 + Ec * Math.Sin(P0)), (Ec / 2))
Dim n = Math.Log(m1 / m2) / Math.Log(t1 / t2)
Dim F = m1 / (n * Math.Pow(t1, n))
Dim rho0 = A * F * Math.Pow(t0, n)
' Convert the coordinate to Latitude/Longitude.  

' Calculate the Longitude.  
lat = lat - X0
Dim Pi2 = Pi4 * 2
Dim rho = Math.Sqrt(Math.Pow(lat, 2) + (Math.Pow(rho0 - lng, 2)))
Dim theta = Math.Atan(lat / (rho0 - lng))
Dim t = Math.Pow(rho / (A * F), (1 / n))
Dim LonR = theta / n + M0
lat = lat + X0

' Estimate the Latitude  
Dim Lat0 = Pi2 - (2 * Math.Atan(t))

' Substitute the estimate into the iterative calculation that  
' converges on the correct Latitude value.  
Dim part1 = (1 - (Ec * Math.Sin(Lat0))) / (1 + (Ec * Math.Sin(Lat0)))
Dim LatR = Pi2 - (2 * Math.Atan(t * Math.Pow(part1, (Ec / 2))))

Lat0 = LatR
part1 = (1 - (Ec * Math.Sin(Lat0))) / (1 + (Ec * Math.Sin(Lat0)))
LatR = Pi2 - (2 * Math.Atan(t * Math.Pow(part1, (Ec / 2))))
Debug.WriteLine(LatR & "|" & LonR)

If (Math.Abs(LatR - Lat0) > 0.000000002) Then
  ' Convert from radians to degrees.  
  Dim _Lat = LatR / AngRad
  Dim _Lng = LonR / AngRad
  Return _Lng.ToString + "|" + _Lat.ToString
End If
Return ""
End Function
DonA
  • 321
  • 1
  • 5
  • 15
  • 2
    You are in Florida aren't you? ...This function converts coordinates from Florida State Plane North Zone NAD83 feet to Geographic coordinates in decimal degrees ... –  Aug 24 '14 at 01:17
  • No, but I no idea how to change that part to colorado. Ideas? – DonA Aug 24 '14 at 01:18
  • 1
    I would suggest that you project your data to the desired coordinates using your GIS package of choice. –  Aug 24 '14 at 01:19
  • I don't have a package, I have to do this with the code provided - bar any changes that fix this current issue. – DonA Aug 24 '14 at 01:20
  • 1
    Do you know more detail about the projection (other than "in feet") -- if not, then this will be an extremely complex problem. Even if you do, you're essentially asking for a custom projection transformation script, which is a pretty big request. (The shortcut -- changing the origin and parallel to be somewhere in Colorado -- will get you closer to your area of interest, but is likely to have significant inaccuracy.) – Erica Aug 24 '14 at 01:29
  • Welcome to GIS SE! You say that you have no GIS package but you have an [tag:arcgis-10.0] tag which is most often used to indicate that you are using ArcGIS Desktop (possibly Server) 10.0 - can you edit your question to remove that, please? Also, revising your question to provide clarifications sought via comments is usually better than creating a comment trail that potential answerers may or may not read. – PolyGeo Aug 24 '14 at 01:30
  • Sorry I don't know what all the tags mean here. – DonA Aug 24 '14 at 01:37
  • I been searching for an answer for this for weeks, why is this so hard to come by? How do the conversion sites convert it so easily? – DonA Aug 24 '14 at 01:39
  • No problem - thanks for updating - tags are generally more important to the potential answerers who use them to find questions that they can help with - your two remaining tags look right for this question – PolyGeo Aug 24 '14 at 01:39
  • What conversion sites? Can you provide a link to at least one - and why not use one of them? I suspect the ease comes from a Projected Coordinate System (e.g. Florida State Plane North Zone NAD83) being supplied along with the units of feet (which can be used with a potentially infinite number of Projected Coordinate Systems). – PolyGeo Aug 24 '14 at 01:43
  • Please excuse the title placed on this Q&A but it has previously proven useful to programmers new to coordinate systems: http://gis.stackexchange.com/questions/22996/spatial-reference-for-dummies – PolyGeo Aug 24 '14 at 01:46
  • I have thousands of database records to fix, I can't use a site for that - it would take ages. Where this function could save us valuable time. – DonA Aug 24 '14 at 01:50
  • 2
    Is downloading QGIS (which is free) and using one of its coordinate transformation algorithms an option -- assuming you can determine the projection of the original data? – Erica Aug 24 '14 at 02:07
  • Not sure how it works and if it would. Would I have to convert them one-by-one? I have an Application that accesses our database - inside here I can code a function to fix these not-very-helpful lat/longs. – DonA Aug 24 '14 at 02:13

2 Answers2

3

There is a similar formula described in this Esri forum post (for Washington State rather than Florida), so it is certainly a problem that's been addressed for a range of locations. The post refers to Map Projections, A Working Manual for the mathematical basics to modify the script for a different location.

However, that would require some familiarity with projections, a fair amount of reading, and knowing the specific projection of the original data. If you don't know it, the question becomes much trickier and there is a chance of significant errors being introduced. The error will be less than "somewhere in Florida when it's supposed to be in Colorado" of course, but whether that's acceptable depends on the application (are you locating cities or utility poles?)...

Another option would be to explore scripting through a GIS program (e.g., QGIS which is free) and using their pre-existing transformation functions. Again, this depends on knowing the original projection of your data. If you choose to go that route, then scripting the function would need to be a new Question (because it's pretty different, and because I don't know how to answer it.)

Erica
  • 8,974
  • 4
  • 34
  • 79
  • Unfortunately, I don't have much training in this, but will check out the link. So if I understand what your saying, there is some kind of projection they use to get the coordinates and I would need that? Thanks so far! – DonA Aug 24 '14 at 02:36
  • 1
    Basically, a map projection is how the spherical earth gets translated to a flat rectangle to make maps. If your data coordinates are in feet, then they're probably one of the State Plane projections (Colorado has two or three within the state) but you'd need to know how old the data are and which datum (NAD27 or NAD83, named after the years they were derived). Projections are often not easy to deal with. – Erica Aug 24 '14 at 02:43
  • That post has the exact same function I use except for the change in a few variables. It would appear I need to know which of those to change. I am ok with a guess right now to start trying some. I will see if I can contact the vender for the projections. – DonA Aug 24 '14 at 02:47
  • 1
    You may also have some success contacting somebody in state/local agency (or local USGS office) who might have dealt with conversion between projections for that region -- simpler than trying to derive the math from scratch! – Erica Aug 24 '14 at 02:53
  • I'll try that too. – DonA Aug 24 '14 at 03:02
  • I found the SPCS83 parameters for our area, the only thing they were missing was the central meridian - man I am close! Any ideas? – DonA Aug 24 '14 at 04:10
  • Those degree values are in deg.minutesseconds, you have to convert that to decimal degrees. – AndreJ Aug 24 '14 at 07:59
1

The feet and degree coordinates fit to each other if you use EPSG:2231 NAD83 / Colorado North (ftUS) with the following parameters:

+proj=lcc +lat_1=40.78333333333333 +lat_2=39.71666666666667 +lat_0=39.33333333333334 +lon_0=-105.5 +x_0=914401.8288036576 +y_0=304800.6096012192 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs

enter image description here

Using QGIS measurement tool, the offset is about 21m. I added the point for a NAD27 CRS as well, that is 85m West of NAD83/WGS84.

AndreJ
  • 76,698
  • 5
  • 86
  • 162
  • With those values in place I get: -103.468797385415|47.818404171443 where the expected is: -105.115643|40.480202 thanks for your help. – DonA Aug 24 '14 at 16:03
  • 2
    I have to say this is the first time I've ever seen coordinates posted on here so close to where I live and at a place I somewhat regularly visit! – Chris W Aug 24 '14 at 20:17
  • 1
    @ChrisW, I work here in the Fort! – DonA Aug 25 '14 at 23:35