def LLtoUTM( Lat, Long, ReferenceEllipsoid=23):
    """
    converts lat/long to UTM coords.  Equations from USGS Bulletin 1532
    East Longitudes are positive, West longitudes are negative.
    North latitudes are positive, South latitudes are negative
    Lat and Long are in decimal degrees
    Written by Chuck Gantz- chuck.gantz@globalstar.com
    """
    a = _ellipsoid[ReferenceEllipsoid][_EquatorialRadius]
    eccSquared = _ellipsoid[ReferenceEllipsoid][_eccentricitySquared]
    k0 = 0.9996

#Make sure the longitude is between -180.00 .. 179.9
    LongTemp = (Long+180)-int((Long+180)/360)*360-180 # -180.00 .. 179.9

    LatRad = Lat*_deg2rad
    LongRad = LongTemp*_deg2rad

    ZoneNumber = int((LongTemp + 180)/6) + 1

    if Lat >= 56.0 and Lat < 64.0 and LongTemp >= 3.0 and LongTemp < 12.0:
        ZoneNumber = 32

    # Special zones for Svalbard
    if Lat >= 72.0 and Lat < 84.0:
        if  LongTemp >= 0.0  and LongTemp <  9.0:ZoneNumber = 31
        elif LongTemp >= 9.0  and LongTemp < 21.0: ZoneNumber = 33
        elif LongTemp >= 21.0 and LongTemp < 33.0: ZoneNumber = 35
        elif LongTemp >= 33.0 and LongTemp < 42.0: ZoneNumber = 37

    LongOrigin = (ZoneNumber - 1)*6 - 180 + 3 #+3 puts origin in middle of zone
    LongOriginRad = LongOrigin * _deg2rad

    #compute the UTM Zone from the latitude and longitude
    UTMZone = "%d%c" % (ZoneNumber, _UTMLetterDesignator(Lat))

    eccPrimeSquared = (eccSquared)/(1-eccSquared)
    N = a/sqrt(1-eccSquared*sin(LatRad)*sin(LatRad))
    T = tan(LatRad)*tan(LatRad)
    C = eccPrimeSquared*cos(LatRad)*cos(LatRad)
    A = cos(LatRad)*(LongRad-LongOriginRad)

    M = a*((1
            - eccSquared/4
            - 3*eccSquared*eccSquared/64
            - 5*eccSquared*eccSquared*eccSquared/256)*LatRad
           - (3*eccSquared/8
              + 3*eccSquared*eccSquared/32
              + 45*eccSquared*eccSquared*eccSquared/1024)*sin(2*LatRad)
           + (15*eccSquared*eccSquared/256 + 45*eccSquared*eccSquared*eccSquared/1024)*sin(4*LatRad)
           - (35*eccSquared*eccSquared*eccSquared/3072)*sin(6*LatRad))

    UTMEasting = (k0*N*(A+(1-T+C)*A*A*A/6
                        + (5-18*T+T*T+72*C-58*eccPrimeSquared)*A*A*A*A*A/120)
                  + 500000.0)

    UTMNorthing = (k0*(M+N*tan(LatRad)*(A*A/2+(5-T+9*C+4*C*C)*A*A*A*A/24
                                        + (61
                                           -58*T
                                           +T*T
                                           +600*C
                                           -330*eccPrimeSquared)*A*A*A*A*A*A/720)))

    if Lat < 0:
        UTMNorthing = UTMNorthing + 10000000.0; #10000000 meter offset for southern hemisphere
    #UTMZone was originally returned here.  I don't know what the
    #letter at the end was for.
    #print("UTMZone", UTMZone)
    return (ZoneNumber, UTMEasting, UTMNorthing)
def LLtoUTM ( Lat , Long , ReferenceEllipsoid = 23 ) : a = _ellipsoid [ ReferenceEllipsoid ] [ _EquatorialRadius ] eccSquared = _ellipsoid [ ReferenceEllipsoid ] [ _eccentricitySquared ] k0 = 0.9996 LongTemp = ( Long + 180 ) - int ( ( Long + 180 ) / 360 ) * 360 - 180 LatRad = Lat * _deg2rad LongRad = LongTemp * _deg2rad ZoneNumber = int ( ( LongTemp + 180 ) / 6 ) + 1 if Lat >= 56.0 and Lat < 64.0 and LongTemp >= 3.0 and LongTemp < 12.0 : ZoneNumber = 32 if Lat >= 72.0 and Lat < 84.0 : if LongTemp >= 0.0 and LongTemp < 9.0 : ZoneNumber = 31 elif LongTemp >= 9.0 and LongTemp < 21.0 : ZoneNumber = 33 elif LongTemp >= 21.0 and LongTemp < 33.0 : ZoneNumber = 35 elif LongTemp >= 33.0 and LongTemp < 42.0 : ZoneNumber = 37 LongOrigin = ( ZoneNumber - 1 ) * 6 - 180 + 3 LongOriginRad = LongOrigin * _deg2rad UTMZone = "%d%c" % ( ZoneNumber , _UTMLetterDesignator ( Lat ) ) eccPrimeSquared = ( eccSquared ) / ( 1 - eccSquared ) N = a / sqrt ( 1 - eccSquared * sin ( LatRad ) * sin ( LatRad ) ) T = tan ( LatRad ) * tan ( LatRad ) C = eccPrimeSquared * cos ( LatRad ) * cos ( LatRad ) A = cos ( LatRad ) * ( LongRad - LongOriginRad ) M = a * ( ( 1 - eccSquared / 4 - 3 * eccSquared * eccSquared / 64 - 5 * eccSquared * eccSquared * eccSquared / 256 ) * LatRad - ( 3 * eccSquared / 8 + 3 * eccSquared * eccSquared / 32 + 45 * eccSquared * eccSquared * eccSquared / 1024 ) * sin ( 2 * LatRad ) + ( 15 * eccSquared * eccSquared / 256 + 45 * eccSquared * eccSquared * eccSquared / 1024 ) * sin ( 4 * LatRad ) - ( 35 * eccSquared * eccSquared * eccSquared / 3072 ) * sin ( 6 * LatRad ) ) UTMEasting = ( k0 * N * ( A + ( 1 - T + C ) * A * A * A / 6 + ( 5 - 18 * T + T * T + 72 * C - 58 * eccPrimeSquared ) * A * A * A * A * A / 120 ) + 500000.0 ) UTMNorthing = ( k0 * ( M + N * tan ( LatRad ) * ( A * A / 2 + ( 5 - T + 9 * C + 4 * C * C ) * A * A * A * A / 24 + ( 61 - 58 * T + T * T + 600 * C - 330 * eccPrimeSquared ) * A * A * A * A * A * A / 720 ) ) ) if Lat < 0 : UTMNorthing = UTMNorthing + 10000000.0 ; return ( ZoneNumber , UTMEasting , UTMNorthing )
converts lat/long to UTM coords.  Equations from USGS Bulletin 1532
    East Longitudes are positive, West longitudes are negative.
    North latitudes are positive, South latitudes are negative
    Lat and Long are in decimal degrees
    Written by Chuck Gantz- chuck.gantz@globalstar.com