source: development/cairns_2006/conversion.py @ 3400

Last change on this file since 3400 was 2286, checked in by jakeman, 19 years ago

THis version contains the create_mesh.py file that creates multiple regions
that have different mesh densities. Unlkie previous submissions this file
now works

File size: 2.0 KB
Line 
1"""
2Author: John Jakeman
3Created: 12/12/2005
4Program used to convert a commer seperated .xya file consiting of
5X and Y corrdinates in degrees and an elevation in meters into an .xya file
6in which all quantities are measured in meters
7"""
8
9def convert_latlon_to_xycoords(lat,longt,origin):
10
11    from math import cos, pi
12    r_earth = 6.378135E+06
13   
14    lat_origin,long_origin = origin
15    # Evalulates distance in X-direction from origin for points in
16    # Western Hemispehere
17    if lat < 0:
18        X = (360.0+lat-lat_origin)/360.0*abs(cos(longt*pi/180.0))*r_earth*2.0*pi
19       
20    elif lat < lat_origin: # Only needed when lat_origin > 0
21        X = (360.0-lat-lat_origin)/360.0*abs(cos(longt*pi/180.0))*r_earth*2.0*pi
22       
23    # Evaluates distance from origin in X-direction for points in
24    # Eastern Hemisphere
25    else:
26        X = (lat-lat_origin)/360.0*abs(cos(longt*pi/180.0))*r_earth*2.0*pi
27    # Calulates distance in Y-direction from a point to origin
28    Y = abs((longt-long_origin)/360.0*2*pi*r_earth)
29    if Y < 0 :
30        Y = 2*pi*r_earth + Y
31
32    return [X,Y]
33
34"""
35from Numeric import array, zeros, Float, asarray
36
37# Open .xya file to be converted
38filename  = 'cairns_degrees.xya'
39fid = open(filename)
40
41# Skip first line
42line = fid.readline()
43
44# Read remaining lines
45lines = fid.readlines()
46fid.close()
47
48# Origin of cartesian system is the point (lat_origin, long_origin)
49lat_origin = 145.0
50long_origin = -24.0
51
52origin = lat_origin, long_origin
53
54# fields[0]: latitude
55# fields[1]: longitude
56# fields[2]: elevation
57
58# Open .xya file to be used to store new coordinates in meters
59filename = 'cairns_test.xya'
60fid = open(filename, "w")
61fid.write('elevation\n')
62
63
64for i, line in enumerate(lines):
65    fields = line.split(',')
66   
67    X,Y =  convert_latlon_to_xycoords(float(fields[0]),float(fields[1]),origin)
68
69    # Write X and Y corrdinates and corresponding elevation to .xya file
70    fid.write(repr(X) + ', ')
71    fid.write(repr(Y) + ', ')
72    fid.write(fields[2])
73
74fid.close()
75"""
Note: See TracBrowser for help on using the repository browser.