code: def average_azimuth(self):
          
          if len(self.points) == 2:
              return self.points[0].azimuth(self.points[1])
          lons = numpy.array([point.longitude for point in self.points])
          lats = numpy.array([point.latitude for point in self.points])
          azimuths = geodetic.azimuth(lons[:-1], lats[:-1], lons[1:], lats[1:])
          distances = geodetic.geodetic_distance(lons[:-1], lats[:-1],
                                                 lons[1:], lats[1:])
          azimuths = numpy.radians(azimuths)
          # convert polar coordinates to Cartesian ones and calculate
          # the average coordinate of each component
          avg_x = numpy.mean(distances * numpy.sin(azimuths))
          avg_y = numpy.mean(distances * numpy.cos(azimuths))
          # find the mean azimuth from that mean vector
          azimuth = numpy.degrees(numpy.arctan2(avg_x, avg_y))
          if azimuth < 0:
              azimuth += 360
          return azimuth
docs: Calculate and return weighted average azimuth of all line's segments
          in decimal degrees.
  
          Uses formula from
          http://en.wikipedia.org/wiki/Mean_of_circular_quantities
  
          >>> from openquake.hazardlib.geo.point import Point as P
          >>> '%.1f' % Line([P(0, 0), P(1e-5, 1e-5)]).average_azimuth()
          '45.0'
          >>> '%.1f' % Line([P(0, 0), P(0, 1e-5), P(1e-5, 1e-5)]).average_azimuth()
          '45.0'
          >>> line = Line([P(0, 0), P(-2e-5, 0), P(-2e-5, 1.154e-5)])
          >>> '%.1f' % line.average_azimuth()
          '300.0'