예제 #1
0
    def drawgreatcircle(self,ax,lon1,lat1,lon2,lat2,dtheta=0.02,color='k', \
                       linewidth=1.,linestyle='-',dashes=[None,None]):
        """
 draw a great circle on the map.

 ax - current axis instance.
 lon1,lat1 - longitude,latitude of one endpoint of the great circle.
 lon2,lat2 - longitude,latitude of the other endpoint of the great circle.
 dtheta - interval between points on arc in radians (default=0.02).
 color - color to draw great circle (default black).
 linewidth - line width for great circle (default 1.)
 linestyle - line style for great circle (default '-', i.e. solid).
 dashes - dash pattern for great circle (default [None,None], i.e. solid).

 Note:  cannot handle situations in which the great circle intersects
 the edge of the map projection domain, and then re-enters the domain.
        """
        gc = GreatCircle(lon1,lat1,lon2,lat2)
        if gc.antipodal:
            raise ValueError,'cannot draw great circle whose endpoints are antipodal'
        # points have spacing of dtheta radians.
        npoints = int(gc.distance/dtheta)+1
        lons, lats = gc.points(npoints)
        x, y = self(lons, lats)
        l = Line2D(x,y,linewidth=linewidth,linestyle=linestyle)
        l.set_color(color)
        if dashes[0] is not None:
            l.set_dashes(dashes)
        ax.add_line(l)
예제 #2
0
    def drawgreatcircle(self,ax,lon1,lat1,lon2,lat2,dtheta=0.02,color='k', \
                       linewidth=1.,linestyle='-',dashes=[None,None]):
        """
 draw a great circle on the map.

 ax - current axis instance.
 lon1,lat1 - longitude,latitude of one endpoint of the great circle.
 lon2,lat2 - longitude,latitude of the other endpoint of the great circle.
 dtheta - interval between points on arc in radians (default=0.02).
 color - color to draw great circle (default black).
 linewidth - line width for great circle (default 1.)
 linestyle - line style for great circle (default '-', i.e. solid).
 dashes - dash pattern for great circle (default [None,None], i.e. solid).

 Note:  cannot handle situations in which the great circle intersects
 the edge of the map projection domain, and then re-enters the domain.
        """
        gc = GreatCircle(lon1, lat1, lon2, lat2)
        if gc.antipodal:
            raise ValueError, 'cannot draw great circle whose endpoints are antipodal'
        # points have spacing of dtheta radians.
        npoints = int(gc.distance / dtheta) + 1
        lons, lats = gc.points(npoints)
        x, y = self(lons, lats)
        l = Line2D(x, y, linewidth=linewidth, linestyle=linestyle)
        l.set_color(color)
        if dashes[0] is not None:
            l.set_dashes(dashes)
        ax.add_line(l)
예제 #3
0
    def gcpoints(self,lon1,lat1,lon2,lat2,npoints):
        """
 compute npoints points along a great circle with endpoints
 (lon1,lat1) and (lon2,lat2).  Returns numarrays x,y
 with map projection coordinates.
        """
        gc = GreatCircle(lon1,lat1,lon2,lat2)
        lons, lats = gc.points(npoints)
        x, y = self(lons, lats)
        return x,y
예제 #4
0
    def gcpoints(self, lon1, lat1, lon2, lat2, npoints):
        """
 compute npoints points along a great circle with endpoints
 (lon1,lat1) and (lon2,lat2).  Returns numarrays x,y
 with map projection coordinates.
        """
        gc = GreatCircle(lon1, lat1, lon2, lat2)
        lons, lats = gc.points(npoints)
        x, y = self(lons, lats)
        return x, y
예제 #5
0
def angle(p1, p2, radians=False):
    """Calculate the angle in degrees between points *p1* and *p2*.
    
    If *radians* is False, *p1* and *p2* are assumed to be in degrees, and
    the returned angle will be in degrees. Otherwise, radians are assumed, and
    returned.
    
    """
    import numpy as np

    if radians:
        factor = 1.
    else:
        factor = _d2r

    lon1, lat1 = np.array(p1) * factor
    lon2, lat2 = np.array(p2) * factor

    from math import acos, sin, cos

    # From http://en.wikipedia.org/wiki/Great-circle_distance
    return acos(
        sin(lon1) * sin(lon2) +
        cos(lon1) * cos(lon2) * cos(lat1 - lat2)) / factor

    # WGS84
    a = 6378137.0
    b = 6356752.3142

    from greatcircle import GreatCircle
    circle = GreatCircle(a, b, lon1, lat1, lon2, lat2)

    return circle.distance
예제 #6
0
    def drawgreatcircle(self,lon1,lat1,lon2,lat2,dtheta=0.02,**kwargs):
        """
 draw a great circle on the map.

 lon1,lat1 - longitude,latitude of one endpoint of the great circle.
 lon2,lat2 - longitude,latitude of the other endpoint of the great circle.
 dtheta - points on great circle computed every dtheta radians (default 0.02).

 Other keyword arguments (**kwargs) control plotting of great circle line,
 see pylab plot documentation for details.

 Note:  cannot handle situations in which the great circle intersects
 the edge of the map projection domain, and then re-enters the domain.
        """
        # get current axes instance.
        ax = pylab.gca()
        gc = GreatCircle(lon1,lat1,lon2,lat2)
        if gc.antipodal:
            raise ValueError,'cannot draw great circle whose endpoints are antipodal'
        # points have spacing of dtheta radians.
        npoints = int(gc.distance/dtheta)+1
        lons, lats = gc.points(npoints)
        x, y = self(lons, lats)
        self.plot(x,y,**kwargs)
예제 #7
0
    def drawgreatcircle(self,lon1,lat1,lon2,lat2,dtheta=0.02,**kwargs):
        """
 draw a great circle on the map.

 lon1,lat1 - longitude,latitude of one endpoint of the great circle.
 lon2,lat2 - longitude,latitude of the other endpoint of the great circle.
 dtheta - increment in radians to compute points for drawing great circle
  (default 0.02).
 Other keyword arguments control plotting of great circle line - see
 pylab plot documentation.

 Note:  cannot handle situations in which the great circle intersects
 the edge of the map projection domain, and then re-enters the domain.
        """
        # get current axes instance.
        ax = pylab.gca()
        gc = GreatCircle(lon1,lat1,lon2,lat2)
        if gc.antipodal:
            raise ValueError,'cannot draw great circle whose endpoints are antipodal'
        # points have spacing of dtheta radians.
        npoints = int(gc.distance/dtheta)+1
        lons, lats = gc.points(npoints)
        x, y = self(lons, lats)
        self.plot(x,y,**kwargs)