Next / Previous / Contents / Shipman's homepage

11. class Gps: GPS waypoint

Each instance represents a waypoint recorded by a Global Positioning System. See the definition of the gps element in the schema.

The string representing the coordinates is required; textual description is optional.

birdnotes.py
# - - - - -   c l a s s   G p s

class Gps:
    """Represents a GPS waypoint.

      Exports:
        Gps(waypoint, text=None):
          [ (waypoint is a lat-long as a string) and
            (text is a description as a string, or None) ->
              if waypoint is a valid lat-long string ->
                return a new Gps instance with those values
              else -> raise ValueError ]
        .waypoint:   [ as passed to constructor, read-only ]
        .text:  [ as passed to constructor, read-write ]
        .latLon:
          [ a terrapos.LatLon instance representing self.waypoint ]
        Gps.readNode(node):    # Static method
          [ node is an rnc.GPS_N node as an et.Element ->
              if node conforms to birdnotes.rnc ->
                return a new Gps instance representing node
              else -> raise IOError ]
        .writeNode(parent):
          [ parent is an et.Element instance ->
              parent  :=  parent with a new rnc.GPS_N node added
                          representing self
              return that new node ]
    """

11.1. Gps.__init__()

In addition to the usual work of storing copies of the constructor's arguments, we'll use the terrapos module to valid the structure of the waypoint string, and store the equivalent LatLon instance as well.

birdnotes.py
# - - -   G p s . _ _ i n i t _ _

    def __init__(self, waypoint, text=None):
        """Constructor for Gps
        """
        #-- 1 --
        self.waypoint = waypoint
        self.text = text

        #-- 2 --
        # [ if waypoint is a valid lat-lon as a string ->
        #     self.latLon  :=  a terrapos.LatLon instance
        #                      representing waypoint
        #   else -> raise ValueError ]
        self.latLon = terrapos.scanLatLon(waypoint)