Ver Mensaje Individual
  #8 (permalink)  
Antiguo 21/01/2009, 12:30
venkman
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: problemas objetos y clases

¿Por qué metes eso en el __init__? Déjalo como estaba. Tan sólo cambia esto (lo he marcado con # AQUÍ):

Código python:
Ver original
  1. from math import pi, sin, cos, tan, sqrt
  2.  
  3. class UTM2LatLon:
  4.  
  5.     #LatLong- UTM conversion..h
  6.     #definitions for lat/long to UTM and UTM to lat/lng conversions
  7.     #include <string.h>
  8.    
  9.     _deg2rad = pi / 180.0
  10.     _rad2deg = 180.0 / pi
  11.    
  12.     _EquatorialRadius = 2
  13.     _eccentricitySquared = 3
  14.     _ellipsoid = [
  15.     #  id, Ellipsoid name, Equatorial Radius, square of eccentricity    
  16.     # first once is a placeholder only, To allow array indices to match id numbers
  17.     [ -1, "Placeholder", 0, 0],
  18.     [ 1, "Airy", 6377563, 0.00667054],
  19.     [ 2, "Australian National", 6378160, 0.006694542],
  20.     [ 3, "Bessel 1841", 6377397, 0.006674372],
  21.     [ 4, "Bessel 1841 (Nambia] ", 6377484, 0.006674372],
  22.     [ 5, "Clarke 1866", 6378206, 0.006768658],
  23.     [ 6, "Clarke 1880", 6378249, 0.006803511],
  24.     [ 7, "Everest", 6377276, 0.006637847],
  25.     [ 8, "Fischer 1960 (Mercury] ", 6378166, 0.006693422],
  26.     [ 9, "Fischer 1968", 6378150, 0.006693422],
  27.     [ 10, "GRS 1967", 6378160, 0.006694605],
  28.     [ 11, "GRS 1980", 6378137, 0.00669438],
  29.     [ 12, "Helmert 1906", 6378200, 0.006693422],
  30.     [ 13, "Hough", 6378270, 0.00672267],
  31.     [ 14, "International", 6378388, 0.00672267],
  32.     [ 15, "Krassovsky", 6378245, 0.006693422],
  33.     [ 16, "Modified Airy", 6377340, 0.00667054],
  34.     [ 17, "Modified Everest", 6377304, 0.006637847],
  35.     [ 18, "Modified Fischer 1960", 6378155, 0.006693422],
  36.     [ 19, "South American 1969", 6378160, 0.006694542],
  37.     [ 20, "WGS 60", 6378165, 0.006693422],
  38.     [ 21, "WGS 66", 6378145, 0.006694542],
  39.     [ 22, "WGS-72", 6378135, 0.006694318],
  40.     [ 23, "WGS-84", 6378137, 0.00669438]
  41. ]
  42.     def _UTMLetterDesignator(Lat):
  43.     #This routine determines the correct UTM letter designator for the given latitude
  44.     #returns 'Z' if latitude is outside the UTM limits of 84N to 80S
  45.     #Written by Chuck Gantz- [email][email protected][/email]"""
  46.    
  47.         if 84 >= Lat >= 72: return 'X'
  48.         elif 72 > Lat >= 64: return 'W'
  49.         elif 64 > Lat >= 56: return 'V'
  50.         elif 56 > Lat >= 48: return 'U'
  51.         elif 48 > Lat >= 40: return 'T'
  52.         elif 40 > Lat >= 32: return 'S'
  53.         elif 32 > Lat >= 24: return 'R'
  54.         elif 24 > Lat >= 16: return 'Q'
  55.         elif 16 > Lat >= 8: return 'P'
  56.         elif  8 > Lat >= 0: return 'N'
  57.         elif  0 > Lat >= -8: return 'M'
  58.         elif -8> Lat >= -16: return 'L'
  59.         elif -16 > Lat >= -24: return 'K'
  60.         elif -24 > Lat >= -32: return 'J'
  61.         elif -32 > Lat >= -40: return 'H'
  62.         elif -40 > Lat >= -48: return 'G'
  63.         elif -48 > Lat >= -56: return 'F'
  64.         elif -56 > Lat >= -64: return 'E'
  65.         elif -64 > Lat >= -72: return 'D'
  66.         elif -72 > Lat >= -80: return 'C'
  67.         else: return 'Z'    # if the Latitude is outside the UTM limits
  68.    
  69.     # AQUÍ
  70.     def UTMtoLL(self, ReferenceEllipsoid, northing, easting, zone):
  71.         #converts UTM coords to lat/long.  Equations from USGS Bulletin 1532
  72.         #East Longitudes are positive, West longitudes are negative.
  73.         #North latitudes are positive, South latitudes are negative
  74.         #Lat and Long are in decimal degrees.
  75.         #Written by Chuck Gantz- [email][email protected][/email]
  76.         #Converted to Python by Russ Nelson <[email protected]>"""
  77.    
  78.         k0 = 0.9996
  79.         # AQUÍ
  80.         a = self._ellipsoid[ReferenceEllipsoid][self._EquatorialRadius]
  81.         eccSquared = self._ellipsoid[ReferenceEllipsoid][self._eccentricitySquared]
  82.         e1 = (1-sqrt(1-eccSquared))/(1+sqrt(1-eccSquared))
  83.         #NorthernHemisphere; //1 for northern hemispher, 0 for southern
  84.    
  85.         x = easting - 500000.0 #remove 500,000 meter offset for longitude
  86.         y = northing
  87.    
  88.         ZoneLetter = zone[-1]
  89.         ZoneNumber = int(zone[:-1])
  90.         if ZoneLetter >= 'N':
  91.             NorthernHemisphere = 1  # point is in northern hemisphere
  92.         else:
  93.             NorthernHemisphere = 0  # point is in southern hemisphere
  94.             y -= 10000000.0         # remove 10,000,000 meter offset used for southern hemisphere
  95.    
  96.         LongOrigin = (ZoneNumber - 1)*6 - 180 + 3  # +3 puts origin in middle of zone
  97.    
  98.         eccPrimeSquared = (eccSquared)/(1-eccSquared)
  99.    
  100.         M = y / k0
  101.         mu = M/(a*(1-eccSquared/4-3*eccSquared*eccSquared/64-5*eccSquared*eccSquared*eccSquared/256))
  102.    
  103.         phi1Rad = (mu + (3*e1/2-27*e1*e1*e1/32)*sin(2*mu)
  104.                    + (21*e1*e1/16-55*e1*e1*e1*e1/32)*sin(4*mu)
  105.                    +(151*e1*e1*e1/96)*sin(6*mu))
  106.         phi1 = phi1Rad*_rad2deg;
  107.    
  108.         N1 = a/sqrt(1-eccSquared*sin(phi1Rad)*sin(phi1Rad))
  109.         T1 = tan(phi1Rad)*tan(phi1Rad)
  110.         C1 = eccPrimeSquared*cos(phi1Rad)*cos(phi1Rad)
  111.         R1 = a*(1-eccSquared)/pow(1-eccSquared*sin(phi1Rad)*sin(phi1Rad), 1.5)
  112.         D = x/(N1*k0)
  113.    
  114.         Lat = phi1Rad - (N1*tan(phi1Rad)/R1)*(D*D/2-(5+3*T1+10*C1-4*C1*C1-9*eccPrimeSquared)*D*D*D*D/24
  115.                                               +(61+90*T1+298*C1+45*T1*T1-252*eccPrimeSquared-3*C1*C1)*D*D*D*D*D*D/720)
  116.         # AQUÍ
  117.         Lat = Lat * self._rad2deg
  118.    
  119.         Long = (D-(1+2*T1+C1)*D*D*D/6+(5-2*C1+28*T1-3*C1*C1+8*eccPrimeSquared+24*T1*T1)
  120.                 *D*D*D*D*D/120)/cos(phi1Rad)
  121.         # AQUÍ
  122.         Long = LongOrigin + Long * self._rad2deg
  123.         return (Lat, Long)

No hace falta meter eso en el __init__. Este código ahora te dará otro error distinto cuando hagas la llamada de antes:

Cuando en la línea 88 intentas hacer ZoneLetter = zone[-1] esto no va a funcionar para el valor 30 que le estás pasando en la llamada en el último parámetro. Pero ahí ya no te puedo ayudar porque no sé lo que significa ese parámetro y lo que estás queriendo hacer. Intuyo que ese método espera que le pases algo como "30N" y no 30, pero no puedo decirte más.