|
17 | 17 | # lonlat, lonlon are lat/lon of London.
|
18 | 18 | lonlat = 51.53
|
19 | 19 | lonlon = 0.08
|
| 20 | + |
20 | 21 | # find 1000 points along the great circle.
|
21 | 22 | #x,y = m.gcpoints(nylon,nylat,lonlon,lonlat,1000)
|
22 | 23 | # draw the great circle.
|
23 | 24 | #m.plot(x,y,linewidth=2)
|
24 | 25 | # drawgreatcircle performs the previous 2 steps in one call.
|
25 | 26 | m.drawgreatcircle(nylon,nylat,lonlon,lonlat,linewidth=2,color='b')
|
| 27 | + |
26 | 28 | m.drawcoastlines()
|
27 | 29 | m.fillcontinents()
|
28 | 30 | # draw parallels
|
|
46 | 48 | # lonlat, lonlon are lat/lon of London.
|
47 | 49 | lonlat = 51.53
|
48 | 50 | lonlon = 0.08
|
| 51 | + |
49 | 52 | # find 1000 points along the great circle.
|
50 | 53 | #x,y = m.gcpoints(nylon,nylat,lonlon,lonlat,1000)
|
51 | 54 | # draw the great circle.
|
|
63 | 66 | plt.title('Great Circle from New York to London (Gnomonic)')
|
64 | 67 | sys.stdout.write('plotting Great Circle from New York to London (Gnomonic)\n')
|
65 | 68 | plt.show()
|
| 69 | + |
| 70 | + |
| 71 | +# Example of Great Circles which exit and reenter the map |
| 72 | +m = Basemap(projection='robin', lat_0=0, lon_0=0,resolution='c') |
| 73 | + |
| 74 | +m.drawmapboundary(fill_color='#ffffff',color='#ffffff') |
| 75 | +m.fillcontinents(color='#f2f2f2',lake_color='#ffffff') |
| 76 | +m.drawcoastlines(color='#e0e0e0') |
| 77 | +m.drawcountries(color='#e0e0e0') |
| 78 | + |
| 79 | +parallels = np.arange(-90,90,10.) |
| 80 | +meridians = np.arange(10.,351.,20.) |
| 81 | +m.drawparallels(parallels,labels=[False,False,False,False], color='#d3d3d3',dashes=[1,3]) |
| 82 | +m.drawmeridians(meridians,labels=[False,False,False,False], color='#d3d3d3',dashes=[1,3]) |
| 83 | + |
| 84 | +# Choose the lat and longtitude of two points |
| 85 | + |
| 86 | +p1 = (45.27,-75.42) # roughly Ottawa |
| 87 | +p2 = (44.05,-4.28) # roughly Paris |
| 88 | +p3 = (-38.58,145.05) # roughly Victoria |
| 89 | + |
| 90 | +la1, lo1 = p1 |
| 91 | +la2, lo2 = p2 |
| 92 | +la3, lo3 = p3 |
| 93 | + |
| 94 | +# Drawing points; you need to convert from lon-lat to xy-cartesian |
| 95 | +x1,y1 = m(lo1,la1) |
| 96 | +x2,y2 = m(lo2,la2) |
| 97 | +x3,y3 = m(lo3,la3) |
| 98 | + |
| 99 | +# Convert back by setting inverse=True |
| 100 | +lon,lat = m(x1,y1,inverse=True) |
| 101 | + |
| 102 | +# Plot pionts using markers |
| 103 | +m.plot(x1,y1, marker='.', markersize=8, color='#000000') |
| 104 | +m.plot(x2,y2, marker='.', markersize=8, color='#000000') |
| 105 | +m.plot(x3,y3, marker='.', markersize=8, color='#000000') |
| 106 | + |
| 107 | +# Of note, the map uses metres as it's smallest distance, so 1000*x is x km |
| 108 | +# The offset is in projection cooordinates |
| 109 | +plt.text(x1+100000,y1+100000,'Ottawa') |
| 110 | +plt.text(x2+100000,y2+100000,'Paris') |
| 111 | +plt.text(x3+100000,y3+100000,'Victoria') |
| 112 | + |
| 113 | +# Draw a great circle line joining them |
| 114 | +m.drawgreatcircle(lo1,la1,lo2,la2,linewidth=1,color='#000000',alpha=1,del_s=100) |
| 115 | +m.drawgreatcircle(lo2,la2,lo3,la3,linewidth=1,color='#000000',alpha=1,del_s=100) |
| 116 | + |
| 117 | +# Drawing a great circle which exits and reenters the map works on certain projections |
| 118 | +m.drawgreatcircle(lo1,la1,lo3,la3,linewidth=1,color='#FF0000',alpha=1,del_s=100) |
| 119 | + |
| 120 | +plt.show() |
0 commit comments