upoints.geonames.Locations

Package upoints :: Module geonames :: Class Locations |
[hide private]
[frames] | no frames]

# Class Locations

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

Class for representing a group of Location objects

Since: 0.5.1

Instance Methods | [hide private]
new list |
__init__(self, data=None, tzfile=None) Initialise a new Locations object |
`list` |
import_locations(self, data) Parse geonames.org country database exports |
`list` |
import_timezones_file(self, data) Parse geonames.org timezone exports |
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, tzfile=None) (Constructor) |
Initialise a new Locations 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 geonames.org country database exports import_locations() returns a list of trigpoints.Trigpoint objects generated from the data exported by geonames. It expects data files in the following tab separated format:
    2633441     Afon Wyre       Afon Wyre       River Wayrai,River Wyrai,Wyre   52.3166667      -4.1666667      H       STM     GB      GB      00                              0               -9999   Europe/London   1994-01-13
    2633442     Wyre    Wyre    Viera   59.1166667      -2.9666667      T       ISL     GB      GB      V9                              0               1       Europe/London   2004-09-24
    2633443     Wraysbury       Wraysbury       Wyrardisbury    51.45   -0.55   P       PPL     GB              P9                              0               28      Europe/London   2006-08-21
Files containing the data in this format can be downloaded from the geonames site in their database export page. Files downloaded from the geonames site when processed by import_locations() will return `list` objects of the following style:
    [Location(2633441, "Afon Wyre", "Afon Wyre",
              ['River Wayrai', 'River Wyrai', 'Wyre'],
              52.3166667, -4.1666667, "H", "STM", "GB", ['GB'], "00",
              None, None, None, 0, None, -9999, "Europe/London",
              datetime.date(1994, 1, 13)),
     Location(2633442, "Wyre", "Wyre", ['Viera'], 59.1166667,
              -2.9666667, "T", "ISL", "GB", ['GB'], "V9", None, None,
              None, 0, None, 1, "Europe/London",
              datetime.date(2004, 9, 24)),
     Location(2633443, "Wraysbury", "Wraysbury", ['Wyrardisbury'],
              51.45, -0.55, "P", "PPL", "GB", None, "P9", None, None,
              None, 0, None, 28, "Europe/London",
              datetime.date(2006, 8, 21))]
    >>> locations = Locations(open("geonames"))
    >>> for location in sorted(locations, key=lambda x: x.geonameid):
    ...     print("%i - %s" % (location.geonameid, location))
    2633441 - Afon Wyre (River Wayrai, River Wyrai, Wyre - N52.317°;
    W004.167°)
    2633442 - Wyre (Viera - N59.117°; W002.967°)
    2633443 - Wraysbury (Wyrardisbury - N51.450°; W000.550°)
    >>> broken_locations = Locations(open("broken_geonames"))
    Traceback (most recent call last):
        ...
    FileFormatError: Incorrect data format, if you're using a file
    downloaded from geonames.org please report this to James Rowe
    <jnrowe@ukfsn.org>
Parameters: `data` (`file`, `list` or `str`) - geonames locations data to read Returns: `list` geonames identifiers with Location objects Raises: `FileFormatError` - Unknown file format Overrides: point.Points.import_locations

### import_timezones_file(self, data) |
Parse geonames.org timezone exports import_timezones_file() returns a dictionary with keys containing the timezone identifier, and values consisting of a UTC offset and UTC offset during daylight savings time in minutes. It expects data files in the following format:
    Europe/Andorra      1.0     2.0
    Asia/Dubai  4.0     4.0
    Asia/Kabul  4.5     4.5
Files containing the data in this format can be downloaded from the geonames site in their database export page. Files downloaded from the geonames site when processed by import_timezones_file() will return `dict` object of the following style:
    {"Europe/Andorra": (60, 120),
     "Asia/Dubai": (240, 240),
     "Asia/Kabul": (270, 270)}
    >>> timezones = Locations(None, open("geonames_timezones")).timezones
    >>> for key, value in sorted(timezones.items()):
    ...     print("%s - %s" % (key, value))
    Asia/Dubai - [240, 240]
    Asia/Kabul - [270, 270]
    Europe/Andorra - [60, 120]
    >>> header_skip_check = Locations(None,
    ...                               open("geonames_timezones_header"))
    >>> print(header_skip_check) # doctest: +ELLIPSIS
    Locations(None, <open file ...>)
    >>> broken_file_check = Locations(None,
    ...                               open("geonames_timezones_broken"))
    Traceback (most recent call last):
        ...
    FileFormatError: Incorrect data format, if you're using a file
    downloaded from geonames.org please report this to James Rowe
    <jnrowe@ukfsn.org>
Parameters: `data` (`file`, `list` or `str`) - geonames timezones data to read Returns: `list` geonames timezone identifiers with their UTC offsets Raises: `FileFormatError` - Unknown file format