geonames

geonames - Imports geonames.org data files.

class upoints.geonames.Location(geonameid, name, asciiname, alt_names, latitude, longitude, feature_class, feature_code, country, alt_country, admin1, admin2, admin3, admin4, population, altitude, gtopo30, tzname, modified_date, timezone=None)[source]

Bases: upoints.trigpoints.Trigpoint

Class for representing a location from a geonames.org data file.

All country codes are specified with their two letter ISO-3166 country code.

New in version 0.3.0.

Variables:__TIMEZONESdateutil.gettz cache to speed up generation

Initialise a new Location object.

Parameters:
  • geonameid (int) – ID of record in geonames database
  • name (unicode) – Name of geographical location
  • asciiname (str) – Name of geographical location in ASCII encoding
  • alt_names (list of unicode) – Alternate names for the location
  • latitude (float) – Location’s latitude
  • longitude (float) – Location’s longitude
  • feature_class (str) – Location’s type
  • feature_code (str) – Location’s code
  • country (str) – Location’s country
  • alt_country (str) – Alternate country codes for location
  • admin1 (str) – FIPS code (subject to change to ISO code), ISO code for the US and CH
  • admin2 (str) – Code for the second administrative division, a county in the US
  • admin3 (str) – Code for third level administrative division
  • admin4 (str) – Code for fourth level administrative division
  • population (int) – Location’s population, if applicable
  • altitude (int) – Location’s elevation
  • gtopo30 (int) – Average elevation of 900 square metre region, if available
  • tzname (str) – The timezone identifier using POSIX timezone names
  • modified_date (datetime.date) – Location’s last modification date in the geonames databases
  • timezone (int) – The non-DST timezone offset from UTC in minutes
class upoints.geonames.Locations(data=None, tzfile=None)[source]

Bases: upoints.point.Points

Class for representing a group of Location objects.

New in version 0.5.1.

Initialise a new Locations object.

import_locations(data)[source]

Parse geonames.org country database exports.

import_locations() returns a list of trigpoints.Trigpoint objects generated from the data exported by geonames.org.

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.org 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))]
Parameters:data (iter) – geonames.org locations data to read
Returns:geonames.org identifiers with Location objects
Return type:list
Raises:FileFormatError – Unknown file format
import_timezones_file(data)[source]

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)}
Parameters:data (iter) – geonames.org timezones data to read
Returns:geonames.org timezone identifiers with their UTC offsets
Return type:list
Raises:FileFormatError – Unknown file format
upoints.geonames.tz = None

dateutil module reference if available