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:
- Overrides:
point.Points.import_locations
|