upoints.cities.Cities

Package upoints :: Module cities :: Class Cities |
[hide private]
[frames] | no frames]

# Class Cities

    object --+
             |
          list --+
                 |
      point.Points --+
                     |
                    Cities

Class for representing a group of City objects

Since: 0.5.1

Instance Methods | [hide private]
new list |
__init__(self, data=None) Initialise a new Cities object |
`list` |
import_locations(self, data) Parse GNU miscfiles cities data files |
Inherited from `point.Points`: `__repr__`, `bearing`, `destination`, `distance`, `final_bearing`, `forward`, `inverse`, `midpoint`, `range`, `sun_events`, `sunrise`, `sunset`, `to_grid_locator` Inherited from `list`: `__add__`, `__contains__`, `__delitem__`, `__delslice__`, `__eq__`, `__ge__`, `__getattribute__`, `__getitem__`, `__getslice__`, `__gt__`, `__hash__`, `__iadd__`, `__imul__`, `__iter__`, `__le__`, `__len__`, `__lt__`, `__mul__`, `__ne__`, `__new__`, `__reversed__`, `__rmul__`, `__setitem__`, `__setslice__`, `append`, `count`, `extend`, `index`, `insert`, `pop`, `remove`, `reverse`, `sort` Inherited from `object`: `__delattr__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__str__`

Properties | [hide private]
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, data=None) (Constructor) |
Initialise a new Cities object Parameters: `points` - Point objects to wrap `parse` - Whether to attempt import of `points` `units` - Unit type to be used for distances when parsing string locations Returns: new list Overrides: object.__init__

### import_locations(self, data) |
Parse GNU miscfiles cities data files import_locations() returns a list containing City objects. It expects data files in the same format that GNU miscfiles provided, that is:
    ID          : 1
    Type        : City
    Population  : 210700
    Size        :
    Name        : Aberdeen
     Country    : UK
     Region     : Scotland
    Location    : Earth
     Longitude  : -2.083
     Latitude   :   57.150
     Elevation  :
    Date        : 19961206
    Entered-By  : Rob.Hooft@EMBL-Heidelberg.DE
    //
    ID          : 2
    Type        : City
    Population  : 1950000
    Size        :
    Name        : Abidjan
     Country    : Ivory Coast
     Region     :
    Location    : Earth
     Longitude  : -3.867
     Latitude   :    5.333
     Elevation  :
    Date        : 19961206
    Entered-By  : Rob.Hooft@EMBL-Heidelberg.DE
When processed by import_locations() will return `list` object in the following style:
    [City(1, "City", 210700, None, "Aberdeen", "UK", "Scotland",
          "Earth", -2.083, 57.15, None, (1996, 12, 6, 0, 0, 0, 4,
          341, -1), "Rob.Hooft@EMBL-Heidelberg.DE"),
     City(2, "City", 1950000, None, "Abidjan", "Ivory Coast", "",
          "Earth", -3.867, 5.333, None, (1996, 12, 6, 0, 0, 0, 4,
          341, -1), "Rob.Hooft@EMBL-Heidelberg.DE")])
    >>> cities_file = open("city_data")
    >>> cities = Cities(cities_file)
    >>> for city in sorted(cities, key=lambda x: x.identifier):
    ...     print("%i - %s (%s;%s)" % (city.identifier, city.name, city.latitude,
    ...                                city.longitude))
    126 - London (51.5;-0.083)
    127 - Luxembourg (49.617;6.117)
    128 - Lyon (45.767;4.867)
    >>> cities_file.seek(0)
    >>> manual_list = cities_file.read().split("//\n")
    >>> cities = Cities(manual_list)
Parameters: `data` (`file`, `list` or `str`) - NOAA station data to read Returns: `list` Places as City objects Raises: `TypeError` - Invalid value for data Overrides: point.Points.import_locations