geonames_rails 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
@@ -46,7 +46,9 @@ class CreateGeonamesTables < ActiveRecord::Migration
|
|
46
46
|
# [1] name : name of geographical point (utf8) varchar(200)
|
47
47
|
t.string :name, :null => false
|
48
48
|
# [2] asciiname : name of geographical point in plain ascii characters, varchar(200)
|
49
|
+
t.string :asciiname
|
49
50
|
# [3] alternatenames : alternatenames, comma separated varchar(4000)
|
51
|
+
t.text :alternatenames
|
50
52
|
# [4] latitude : latitude in decimal degrees (wgs84)
|
51
53
|
t.decimal :latitude, :precision => 14, :scale => 8, :null => false
|
52
54
|
# [5] longitude : longitude in decimal degrees (wgs84)
|
@@ -13,8 +13,12 @@ module GeonamesRails
|
|
13
13
|
:iso_number,
|
14
14
|
:name,
|
15
15
|
:capital,
|
16
|
+
:population,
|
16
17
|
:continent,
|
17
|
-
:
|
18
|
+
:currency_name,
|
19
|
+
:currency_code,
|
20
|
+
:geonames_id,
|
21
|
+
:population)
|
18
22
|
c.save!
|
19
23
|
|
20
24
|
"#{created_or_updating} db record for #{iso_code}"
|
@@ -25,23 +29,26 @@ module GeonamesRails
|
|
25
29
|
def write_cities(country_code, city_mappings)
|
26
30
|
country = Country.find_by_iso_code_two_letter(country_code)
|
27
31
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
32
|
+
unless country.nil?
|
33
|
+
city_mappings.each do |city_mapping|
|
34
|
+
city = City.find_or_initialize_by_geonames_id(city_mapping[:geonames_id])
|
35
|
+
city.country_id = country.id
|
36
|
+
|
37
|
+
city.attributes = city_mapping.slice(:name,
|
38
|
+
:asciiname,
|
39
|
+
:alternatenames,
|
40
|
+
:latitude,
|
41
|
+
:longitude,
|
42
|
+
:country_iso_code_two_letters,
|
43
|
+
:population,
|
44
|
+
:geonames_timezone_id,
|
45
|
+
:geonames_id)
|
46
|
+
|
47
|
+
city.save!
|
48
|
+
end
|
49
|
+
|
50
|
+
"Processed #{country.name}(#{country_code}) with #{city_mappings.length} cities"
|
42
51
|
end
|
43
|
-
|
44
|
-
"Processed #{country.name}(#{country_code}) with #{city_mappings.length} cities"
|
45
52
|
end
|
46
53
|
|
47
54
|
end
|