kopia lustrzana https://github.com/ctjacobs/pyqso
Migrating grey line functionality over to a Cartopy-based implementation to address issue #62. This currently only plots QTH points. Support for the grey line itself is currently missing.
rodzic
f283df065b
commit
f3ee36a10b
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
from gi.repository import GObject
|
from gi.repository import GObject
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
|
||||||
from os.path import expanduser
|
from os.path import expanduser
|
||||||
try:
|
try:
|
||||||
import configparser
|
import configparser
|
||||||
|
@ -30,8 +29,8 @@ try:
|
||||||
logging.info("Using version %s of numpy." % (numpy.__version__))
|
logging.info("Using version %s of numpy." % (numpy.__version__))
|
||||||
import matplotlib
|
import matplotlib
|
||||||
logging.info("Using version %s of matplotlib." % (matplotlib.__version__))
|
logging.info("Using version %s of matplotlib." % (matplotlib.__version__))
|
||||||
import mpl_toolkits.basemap
|
import cartopy
|
||||||
logging.info("Using version %s of mpl_toolkits.basemap." % (mpl_toolkits.basemap.__version__))
|
logging.info("Using version %s of cartopy." % (cartopy.__version__))
|
||||||
from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo as FigureCanvas
|
from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo as FigureCanvas
|
||||||
have_necessary_modules = True
|
have_necessary_modules = True
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
|
@ -156,29 +155,24 @@ class GreyLine:
|
||||||
# Don't re-draw if the grey line is not visible.
|
# Don't re-draw if the grey line is not visible.
|
||||||
return True # We need to return True in case this is method was called by a timer event.
|
return True # We need to return True in case this is method was called by a timer event.
|
||||||
else:
|
else:
|
||||||
logging.debug("Drawing the grey line...")
|
# Set up the world map.
|
||||||
# Re-draw the grey line
|
|
||||||
self.fig.clf()
|
self.fig.clf()
|
||||||
sub = self.fig.add_subplot(111)
|
ax = self.fig.add_subplot(111, projection=cartopy.crs.PlateCarree())
|
||||||
|
ax.set_extent([-180, 180, -90, 90])
|
||||||
|
ax.gridlines()
|
||||||
|
ax.add_feature(cartopy.feature.LAND)
|
||||||
|
ax.add_feature(cartopy.feature.OCEAN)
|
||||||
|
ax.add_feature(cartopy.feature.COASTLINE)
|
||||||
|
ax.add_feature(cartopy.feature.BORDERS, alpha=0.25)
|
||||||
|
|
||||||
# Draw the map of the world. This is based on the example from:
|
# TODO: Re-draw the grey line.
|
||||||
# http://matplotlib.org/basemap/users/examples.html
|
|
||||||
m = mpl_toolkits.basemap.Basemap(projection="mill", lon_0=0, ax=sub, resolution="c", fix_aspect=False)
|
|
||||||
m.drawcountries(linewidth=0.4)
|
|
||||||
m.drawcoastlines(linewidth=0.4)
|
|
||||||
m.drawparallels(numpy.arange(-90, 90, 30), labels=[1, 0, 0, 0])
|
|
||||||
m.drawmeridians(numpy.arange(m.lonmin, m.lonmax+30, 60), labels=[0, 0, 0, 1])
|
|
||||||
m.drawmapboundary(fill_color="skyblue")
|
|
||||||
m.fillcontinents(color="green", lake_color="skyblue")
|
|
||||||
m.nightshade(datetime.utcnow()) # Add in the grey line using UTC time. Note that this requires NetCDF.
|
|
||||||
logging.debug("Grey line drawn.")
|
|
||||||
|
|
||||||
# Plot points on the map.
|
# Plot points on the map.
|
||||||
if(self.points):
|
if(self.points):
|
||||||
|
logging.debug("Plotting QTHs on the map...")
|
||||||
for p in self.points:
|
for p in self.points:
|
||||||
x, y = m(p.longitude, p.latitude)
|
ax.plot(p.longitude, p.latitude, p.style, transform=cartopy.crs.PlateCarree())
|
||||||
m.plot(x, y, p.style)
|
ax.text(p.longitude+0.01*p.longitude, p.latitude+0.01*p.latitude, p.name, color="black", size="small", weight="bold")
|
||||||
sub.text(x+0.01*x, y+0.01*y, p.name, color="white", size="small", weight="bold")
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
|
Ładowanie…
Reference in New Issue