Changeset 6404
- Timestamp:
- Feb 24, 2009, 6:13:06 PM (16 years ago)
- Location:
- anuga_core/source/anuga/coordinate_transforms
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/coordinate_transforms/redfearn.py
r6149 r6404 37 37 return sign*dd, mm, ss 38 38 39 def redfearn(lat, lon, false_easting=None, false_northing=None, zone=None): 39 def redfearn(lat, lon, false_easting=None, false_northing=None, 40 zone=None, central_meridian=None): 40 41 """Compute UTM projection using Redfearn's formula 41 42 … … 47 48 If zone is specified reproject lat and long to specified zone instead of 48 49 standard zone 50 51 If meridian is specified, reproject lat and lon to that instead of zone. In this case 52 zone will be set to -1 to indicate non-UTM projection 53 54 Note that zone and meridian cannot both be specifed 49 55 """ 50 56 … … 54 60 55 61 56 # GDA Specifications62 # GDA Specifications 57 63 a = 6378137.0 #Semi major axis 58 64 inverse_flattening = 298.257222101 #1/f … … 73 79 74 80 75 # Derived constants81 # Derived constants 76 82 f = 1.0/inverse_flattening 77 83 b = a*(1-f) #Semi minor axis … … 84 90 e6 = e2*e4 85 91 86 # Foot point latitude92 # Foot point latitude 87 93 n = (a-b)/(a+b) #Same as e2 - why ? 88 94 n2 = n*n … … 114 120 t6 = t2*t4 115 121 116 # Radius of Curvature122 # Radius of Curvature 117 123 rho = a*(1-e2)/(1-e2*sinphi*sinphi)**1.5 118 124 nu = a/(1-e2*sinphi*sinphi)**0.5 … … 122 128 psi4 = psi2*psi2 123 129 124 125 126 #Meridian distance 127 130 # Meridian distance 128 131 A0 = 1 - e2/4 - 3*e4/64 - 5*e6/256 129 132 A2 = 3.0/8*(e2+e4/4+15*e6/128) … … 138 141 m = term1 + term2 + term3 + term4 #OK 139 142 140 #Zone 143 if zone is not None and central_meridian is not None: 144 msg = 'You specified both zone and central_meridian. Provide only one of them' 145 raise Exception, msg 146 147 # Zone 141 148 if zone is None: 142 149 zone = int((lon - longitude_of_western_edge_zone0)/zone_width) 143 150 144 central_meridian = zone*zone_width+longitude_of_central_meridian_zone0 151 # Central meridian 152 if central_meridian is None: 153 central_meridian = zone*zone_width+longitude_of_central_meridian_zone0 154 else: 155 zone = -1 145 156 146 157 omega = (lon-central_meridian)*pi/180 #Relative longitude (radians) … … 153 164 omega8 = omega4*omega4 154 165 155 # Northing166 # Northing 156 167 term1 = nu*sinphi*cosphi*omega2/2 157 168 term2 = nu*sinphi*cosphi3*(4*psi2+psi-t2)*omega4/24 … … 162 173 northing = false_northing + K0*(m + term1 + term2 + term3 + term4) 163 174 164 # Easting175 # Easting 165 176 term1 = nu*omega*cosphi 166 177 term2 = nu*cosphi3*(psi-t2)*omega3/6 -
anuga_core/source/anuga/coordinate_transforms/test_redfearn.py
r6400 r6404 10 10 from redfearn import * 11 11 from anuga.utilities.anuga_exceptions import ANUGAError 12 12 from anuga.utilities.system_tools import get_pathname_from_package 13 from os.path import join 13 14 import Numeric as num 14 15 … … 273 274 274 275 275 def test_nonstandard_meridian(self):276 def Xtest_nonstandard_meridian(self): 276 277 """test_nonstandard_meridian 277 278 … … 279 280 points using an arbitrary central meridian. 280 281 """ 281 282 283 # FIXME: To do using csv file284 pass285 286 282 287 283 # The file projection_test_points.csv contains 10 points … … 291 287 # in the middle of zones 53 and 54). 292 288 293 294 295 289 path = get_pathname_from_package('anuga.coordinate_transforms') 290 datafile = join(path, 'projection_test_points.csv') 291 fid = open(datafile) 292 293 for line in fid.readlines()[1:]: 294 fields = line.strip().split(',') 295 296 lon = float(fields[1]) 297 lat = float(fields[2]) 298 x = float(fields[3]) 299 y = float(fields[4]) 300 301 zone, easting, northing = redfearn(lat, lon, 302 central_meridian=137.5) 303 304 print 305 print 'Lat', lat 306 print 'Lon', lon 307 print 'Zone', zone 308 print 'Ref x', x, 'Computed x', easting, 'Close enough:', num.allclose(x, easting) 309 print 'Ref y', y, 'Computed y', northing, 'Close enough:', num.allclose(y, northing) 310 311 # Check calculation 312 assert zone == -1 # Indicates non UTM projection 313 print 314 #assert num.allclose(x, easting) 315 #assert num.allclose(y, northing) 316 317 # Test that zone and meridian can't both be specified 318 try: 319 zone, easting, northing = redfearn(lat, lon, 320 zone=50, central_meridian=137.5) 321 except: 322 pass 323 else: 324 msg = 'Should have raised exception' 325 raise Exception, msg 296 326 297 327 def test_convert_lats_longs(self):
Note: See TracChangeset
for help on using the changeset viewer.