<% ' stategeo.asp Gerry Daumiller 2/8/99 (Perl version) - 4/16/2002 ' Program to convert from Montana State Plane Coordinates ' to Latitude/Longitude ' The formulae this program is based on are from "Map Projections, ' A Working Manual" by John P. Snyder, U.S. GeoLogical Survey ' Professional Paper 1395, 1987, pages 295-298 y = Request("y") x = Request("x") If y = "" or x = "" Then Response.Write "No value entered" Response.Write "

No value was entered for Northing or Easting

" Response.Write "" Response.End End If ' Set up the coordinate system parameters. 'a = 6378206.4 ' major radius of ellipsoid, map units (NAD 27) 'e = 0.08227185422 ' eccentricity of ellipsoid (NAD 27) a = 6378137 ' major radius of ellipsoid, map units (NAD 83) e = 0.08181922146 ' eccentricity of ellipsoid (NAD 83) angRad = 0.01745329252 ' number of radians in a degree pi4 = 3.141592653582 / 4 ' Pi / 4 p0 = 44.25 * angRad ' latitude of origin p1 = 45 * angRad ' latitude of first standard parallel p2 = 49 * angRad ' latitude of second standard parallel m0 = -109.5 * angRad ' central meridian x0 = 600000 ' False easting of central meridian, map units ' Calculate the coordinate system constants. m1 = Cos(p1) / Sqr(1 - ((e ^ 2) * Sin(p1) ^ 2)) m2 = Cos(p2) / Sqr(1 - ((e ^ 2) * Sin(p2) ^ 2)) t0 = Tan(pi4 - (p0 / 2)) t1 = Tan(pi4 - (p1 / 2)) t2 = Tan(pi4 - (p2 / 2)) t0 = t0 / (((1 - (e * (Sin(p0)))) / (1 + (e * (Sin(p0)))))^(e / 2)) t1 = t1 / (((1 - (e * (Sin(p1)))) / (1 + (e * (Sin(p1)))))^(e / 2)) t2 = t2 / (((1 - (e * (Sin(p2)))) / (1 + (e * (Sin(p2)))))^(e / 2)) n = Log(m1 / m2) / Log(t1 / t2) f = m1 / (n * (t1 ^ n)) rho0 = a * f * (t0 ^ n) ' Convert the coordinate to Latitude/Longitude. ' Calculate the Longitude. x = x - x0 pi2 = pi4 * 2 rho = Sqr((x ^ 2) + ((rho0 - y) ^ 2)) theta = Atn(x / (rho0 - y)) t = (rho / (a * f)) ^ (1 / n) lon = (theta / n) + m0 x = x + x0 ' Estimate the Latitude lat0 = pi2 - (2 * Atn(t)) ' Substitute the estimate into the iterative calculation that ' converges on the correct Latitude value. part1 = (1 - (e * Sin(lat0))) / (1 + (e * Sin(lat0))) lat1 = pi2 - (2 * Atn(t * (part1 ^ (e / 2)))) Do Until Abs(lat1 - lat0) < 0.000000002 lat0 = lat1 part1 = (1 - (e * Sin(lat0))) / (1 + (e * Sin(lat0))) lat1 = pi2 - (2 * Atn(t * (part1 ^ (e / 2)))) Loop ' Convert from radians to degrees. lat = lat1 / angRad lon = lon / angRad 'Round the latitude and longitude lat = (CLng(lat * 100000)) / 100000 lon = (CLng(lon * 100000)) / 100000 ' Calcuate degrees, minutes, and seconds. dLat = int(lat) mLat = 60 * (lat - dLat) sLat = 60 * (mLat - int(mLat)) mLat = int(mLat) lon = 0 - lon dLon = int(lon) mLon = 60 * (lon - dLon) sLon = 60 * (mLon - int(mLon)) mLon = int(mLon) lon = 0 - lon dLon = 0 - dLon 'Round the seconds sLat = (CLng(sLat * 100)) / 100 sLon = (CLng(sLon * 100)) / 100 %>

State Plane Converted to Latitude/Longitude

State Plane Coordinate
Northing Easting
Meters <%=y%> <%=x%>
Latitude: Longitude:
Decimal Degrees: <%=lat%> <%=lon%>
Degrees, Minutes, Seconds: <%=dLat%>   <%=mLat%>   <%=sLat%>   <%=dLon%>   <%=mLon%>   <%=sLon%>