14.4 Geographic Location Look-up Table

This type of look-up table files are lists of words with their corresponding geographic locations as numerical longitude and latitude value pairs. These files contain three columns separated by a comma, thus they are simple CSV (comma separated values) files, similar to frequency look-up table files. The first column contains words, the second column contains the longitude values and the third column contains the latitude values. Longitude values need to be between -180.0 and 180.0 and latitude values between -90.0 and 90.0. These files should have a file extension '.csv'. The following example is extracted from a postcode geographic location look-up table.

# ====================================================================

2000, 151.20710, -33.87060
2007, 151.19761, -33.87849
2008, 151.19655, -33.88829
2009, 151.19395, -33.87014
2010, 151.21524, -33.88299

It is possible to load more than one geographic location look-up table files into one combined geographic location look-up table, by simply giving a list of file names when the table is loaded, as shown in the example below. If an entry is listed in more than one file with different locations, and error is triggered.

The default value for the attribute default is the value [], i.e. an empty list. So if a value is searched in a table that does not exist, an empty list is returned and the calling program can act upon this. The default value can be changed when a geographic location look-up table is initialised using the default argument.

Assuming the lookup.py module has been imported using the import lookup command, an example geographic location look-up table can be initialised and loaded from several files as shown in the following example.

# ====================================================================

pc_location_table = lookup.GeocodeLookupTable(name = 'PCGeoLocTable')

pc_location_table.load(['postcode_nsw.csv',
                        'postcode_qld.csv',
                        'postcode_tas.csv',
                        'postcode_act.csv'])

print pc_location_table.length

print pc_location_table['2000']  # Returns [151.2071, -33.8706]
print pc_location_table['9999']  # Should return [] because '9999' is
                                 # not a valid postcode