geonames_local 0.5.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +28 -0
- data/Gemfile +14 -0
- data/Rakefile +10 -56
- data/bin/geonames +1 -1
- data/geonames.yml +5 -4
- data/geonames_local.gemspec +23 -103
- data/lib/geonames_local/adapters/mongodb.rb +4 -1
- data/lib/geonames_local/cli.rb +92 -3
- data/lib/geonames_local/config/geonames.yml +4 -4
- data/lib/geonames_local/data/dump.rb +1 -1
- data/lib/geonames_local/data/shp.rb +3 -4
- data/lib/geonames_local/features/spot.rb +11 -5
- data/lib/geonames_local/geonames.rb +0 -1
- data/lib/geonames_local/models/{mongo.rb → mongodb.rb} +0 -0
- data/lib/geonames_local/models/{ar.rb → postgis.rb} +10 -2
- data/lib/geonames_local/models/tokyo.rb +11 -6
- data/lib/geonames_local/version.rb +3 -0
- metadata +47 -79
- data/VERSION +0 -1
data/.gitignore
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
*flymake.rb
|
13
|
+
|
14
|
+
## VIM
|
15
|
+
*.swp
|
16
|
+
|
17
|
+
## PROJECT::GENERAL
|
18
|
+
coverage
|
19
|
+
rdoc
|
20
|
+
pkg
|
21
|
+
|
22
|
+
## PROJECT::SPECIFIC
|
23
|
+
*.tct
|
24
|
+
*.pid
|
25
|
+
*.log
|
26
|
+
*.qgr
|
27
|
+
*.lex
|
28
|
+
shps
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
gemspec # Specify gem's dependencies in mongoid_geospatial.gemspec
|
3
|
+
|
4
|
+
group :development do
|
5
|
+
gem 'mongoid', '~> 3.0'
|
6
|
+
# gem 'pg'
|
7
|
+
gem 'rgeo'
|
8
|
+
gem 'georuby'
|
9
|
+
gem 'dbf'
|
10
|
+
gem 'rspec'
|
11
|
+
gem 'guard-rspec'
|
12
|
+
gem 'pry'
|
13
|
+
# gem 'fuubar'
|
14
|
+
end
|
data/Rakefile
CHANGED
@@ -1,67 +1,22 @@
|
|
1
|
-
|
2
|
-
require
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "geonames_local"
|
8
|
-
gem.summary = "Dump and feed a tokyo local geonames db"
|
9
|
-
gem.description = "Dump and feed a tokyo cabinet for local geonames search"
|
10
|
-
gem.email = "x@nofxx.com"
|
11
|
-
gem.homepage = "http://github.com/nofxx/geonames_local"
|
12
|
-
gem.authors = ["Marcos Piccinini"]
|
13
|
-
|
14
|
-
gem.add_dependency "nofxx-georuby", ">= 1.7.1"
|
15
|
-
gem.add_development_dependency "rspec", ">= 1.2.9"
|
16
|
-
|
17
|
-
gem.post_install_message = <<-POST_INSTALL_MESSAGE
|
18
|
-
|
19
|
-
Geonames Local
|
20
|
-
--------------
|
21
|
-
|
22
|
-
To use the adapter, install the corresponding gem:
|
23
|
-
|
24
|
-
PostgreSQL => pg
|
25
|
-
MongoDB => mongodb (optional: mongo_ext)
|
26
|
-
Tokyo => tokyocabinet
|
27
|
-
|
28
|
-
PostgreSQL
|
29
|
-
----------
|
30
|
-
|
31
|
-
Be sure to use a database based on the PostGIS template.
|
32
|
-
|
33
|
-
MongoDB
|
34
|
-
-------
|
35
|
-
|
36
|
-
MongoDB 2D support is new, only mongo >= 1.3.3 mongodb gem >= 0.19.2
|
37
|
-
http://github.com/mongodb/mongo-ruby-driver
|
4
|
+
require 'rspec/core'
|
5
|
+
require 'rspec/core/rake_task'
|
38
6
|
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
Jeweler::GemcutterTasks.new
|
43
|
-
rescue LoadError
|
44
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
7
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
8
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
45
9
|
end
|
46
10
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
spec.pattern = 'spec/*_spec.rb'
|
51
|
-
spec.rspec_opts = ['--backtrace --colour']
|
11
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
12
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
13
|
+
spec.rcov = true
|
52
14
|
end
|
53
15
|
|
54
16
|
task :default => :spec
|
55
17
|
|
56
|
-
require '
|
57
|
-
Rake::RDocTask.new do |rdoc|
|
58
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
18
|
+
require 'yard'
|
59
19
|
|
60
|
-
rdoc.rdoc_dir = 'rdoc'
|
61
|
-
rdoc.title = "geonames_local #{version}"
|
62
|
-
rdoc.rdoc_files.include('README*')
|
63
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
64
|
-
end
|
65
20
|
|
66
21
|
#
|
67
22
|
# Tokyo Tyrant rake tasks
|
@@ -117,4 +72,3 @@ def tyrant_running?
|
|
117
72
|
end
|
118
73
|
tyrant_pid
|
119
74
|
end
|
120
|
-
|
data/bin/geonames
CHANGED
data/geonames.yml
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#
|
2
2
|
# Geonames Local Config Example
|
3
3
|
#
|
4
|
-
:store: postgres
|
5
|
-
:codes: [br]
|
4
|
+
:store: mongodb # postgres / tokyo
|
5
|
+
:codes: [br] # to store all countries informations in the countries table, just write [country]
|
6
6
|
:level: city
|
7
7
|
:min_pop: 100000
|
8
8
|
:mapping:
|
@@ -10,6 +10,7 @@
|
|
10
10
|
:geom: true
|
11
11
|
:db:
|
12
12
|
:host: localhost
|
13
|
-
:dbname:
|
14
|
-
:user:
|
13
|
+
:dbname: geonames_test
|
14
|
+
:user:
|
15
15
|
:password:
|
16
|
+
:purge: false
|
data/geonames_local.gemspec
CHANGED
@@ -1,74 +1,32 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/geonames_local/version', __FILE__)
|
5
3
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = %q{geonames_local}
|
6
|
+
gem.version = Geonames::VERSION
|
7
|
+
gem.homepage = %q{http://github.com/nofxx/geonames_local}
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
gem.authors = ["Marcos Piccinini"]
|
10
|
+
gem.default_executable = %q{geonames}
|
11
|
+
gem.description = %q{Dump and feed a tokyo cabinet for local geonames search}
|
12
|
+
gem.email = %q{x@nofxx.com}
|
13
|
+
|
14
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
15
|
+
gem.files = `git ls-files`.split("\n")
|
16
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
gem.name = "geonames_local"
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.summary = %q{Dump and feed a tokyo local geonames db}
|
20
|
+
|
21
|
+
|
22
|
+
gem.extra_rdoc_files = [
|
18
23
|
"LICENSE",
|
19
24
|
"README.rdoc"
|
20
25
|
]
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
"Rakefile",
|
26
|
-
"VERSION",
|
27
|
-
"bin/geonames",
|
28
|
-
"geonames.yml",
|
29
|
-
"geonames_local.gemspec",
|
30
|
-
"lib/geonames_ar.rb",
|
31
|
-
"lib/geonames_cli.rb",
|
32
|
-
"lib/geonames_local.rb",
|
33
|
-
"lib/geonames_local/adapters/mongodb.rb",
|
34
|
-
"lib/geonames_local/adapters/postgres.rb",
|
35
|
-
"lib/geonames_local/adapters/tokyo.rb",
|
36
|
-
"lib/geonames_local/cli.rb",
|
37
|
-
"lib/geonames_local/config/codes.yml",
|
38
|
-
"lib/geonames_local/config/geonames.sql",
|
39
|
-
"lib/geonames_local/config/geonames.yml",
|
40
|
-
"lib/geonames_local/data/dump.rb",
|
41
|
-
"lib/geonames_local/data/export.rb",
|
42
|
-
"lib/geonames_local/data/shp.rb",
|
43
|
-
"lib/geonames_local/data/sync.rb",
|
44
|
-
"lib/geonames_local/features/road.rb",
|
45
|
-
"lib/geonames_local/features/spot.rb",
|
46
|
-
"lib/geonames_local/features/zone.rb",
|
47
|
-
"lib/geonames_local/geonames.rb",
|
48
|
-
"lib/geonames_local/models/ar.rb",
|
49
|
-
"lib/geonames_local/models/mongo.rb",
|
50
|
-
"lib/geonames_local/models/tokyo.rb",
|
51
|
-
"spec/geonames_local/adapters/mongodb_spec.rb",
|
52
|
-
"spec/geonames_local/adapters/postgres_spec.rb",
|
53
|
-
"spec/geonames_local/adapters/tokyo_spec.rb",
|
54
|
-
"spec/geonames_local/cli_spec.rb",
|
55
|
-
"spec/geonames_local/data/cache_spec.rb",
|
56
|
-
"spec/geonames_local/data/dump_spec.rb",
|
57
|
-
"spec/geonames_local/data/shp_spec.rb",
|
58
|
-
"spec/geonames_local/features/road_spec.rb",
|
59
|
-
"spec/geonames_local/features/spot_spec.rb",
|
60
|
-
"spec/geonames_local/features/zone_spec.rb",
|
61
|
-
"spec/geonames_local/models/ar_spec.rb",
|
62
|
-
"spec/geonames_local/models/mongo_spec.rb",
|
63
|
-
"spec/geonames_local_spec.rb",
|
64
|
-
"spec/spec_ar_helper.rb",
|
65
|
-
"spec/spec_helper.rb",
|
66
|
-
"spec/spec_mongo_helper.rb",
|
67
|
-
"task/benchmark.rb",
|
68
|
-
"task/benchmark_cabinet.rb"
|
69
|
-
]
|
70
|
-
s.homepage = %q{http://github.com/nofxx/geonames_local}
|
71
|
-
s.post_install_message = %q{
|
26
|
+
|
27
|
+
gem.add_dependency('georuby', ['>= 3.0.0'])
|
28
|
+
|
29
|
+
gem.post_install_message = %q{
|
72
30
|
Geonames Local
|
73
31
|
--------------
|
74
32
|
|
@@ -91,42 +49,4 @@ http://github.com/mongodb/mongo-ruby-driver
|
|
91
49
|
|
92
50
|
Have fun because:
|
93
51
|
}
|
94
|
-
s.require_paths = ["lib"]
|
95
|
-
s.rubygems_version = %q{1.3.7}
|
96
|
-
s.summary = %q{Dump and feed a tokyo local geonames db}
|
97
|
-
s.test_files = [
|
98
|
-
"spec/geonames_local/adapters/mongodb_spec.rb",
|
99
|
-
"spec/geonames_local/adapters/postgres_spec.rb",
|
100
|
-
"spec/geonames_local/adapters/tokyo_spec.rb",
|
101
|
-
"spec/geonames_local/cli_spec.rb",
|
102
|
-
"spec/geonames_local/data/cache_spec.rb",
|
103
|
-
"spec/geonames_local/data/dump_spec.rb",
|
104
|
-
"spec/geonames_local/data/shp_spec.rb",
|
105
|
-
"spec/geonames_local/features/road_spec.rb",
|
106
|
-
"spec/geonames_local/features/spot_spec.rb",
|
107
|
-
"spec/geonames_local/features/zone_spec.rb",
|
108
|
-
"spec/geonames_local/models/ar_spec.rb",
|
109
|
-
"spec/geonames_local/models/mongo_spec.rb",
|
110
|
-
"spec/geonames_local_spec.rb",
|
111
|
-
"spec/spec_ar_helper.rb",
|
112
|
-
"spec/spec_helper.rb",
|
113
|
-
"spec/spec_mongo_helper.rb"
|
114
|
-
]
|
115
|
-
|
116
|
-
if s.respond_to? :specification_version then
|
117
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
118
|
-
s.specification_version = 3
|
119
|
-
|
120
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
121
|
-
s.add_runtime_dependency(%q<nofxx-georuby>, [">= 1.7.1"])
|
122
|
-
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
123
|
-
else
|
124
|
-
s.add_dependency(%q<nofxx-georuby>, [">= 1.7.1"])
|
125
|
-
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
126
|
-
end
|
127
|
-
else
|
128
|
-
s.add_dependency(%q<nofxx-georuby>, [">= 1.7.1"])
|
129
|
-
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
130
|
-
end
|
131
52
|
end
|
132
|
-
|
data/lib/geonames_local/cli.rb
CHANGED
@@ -70,6 +70,9 @@ BANNER
|
|
70
70
|
exit
|
71
71
|
end
|
72
72
|
|
73
|
+
#
|
74
|
+
# Return Codes and Exit
|
75
|
+
#
|
73
76
|
if argv[0] =~ /list|codes/
|
74
77
|
Codes.each do |key,val|
|
75
78
|
str = [val.values, key.to_s].join(" ").downcase
|
@@ -94,19 +97,105 @@ BANNER
|
|
94
97
|
end
|
95
98
|
exit
|
96
99
|
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# Require georuby optionally
|
103
|
+
#
|
97
104
|
require "geo_ruby" if Opt[:mapping] && Opt[:mapping][:geom]
|
98
105
|
|
106
|
+
#
|
107
|
+
# Export Data as CSV or JSON
|
108
|
+
#
|
99
109
|
if argv[0] =~ /csv|json/
|
100
110
|
Geonames::Export.new(Country.all).to_csv
|
111
|
+
|
112
|
+
#
|
113
|
+
# Do the magic! Import Geonames Data
|
114
|
+
#
|
101
115
|
else
|
116
|
+
db = load_adapter(Opt[:store])
|
102
117
|
info "Using adapter #{Opt[:store]}.."
|
103
|
-
|
104
|
-
|
118
|
+
|
119
|
+
if Opt[:codes][0] == "country"
|
120
|
+
Geonames::Dump.work(Opt[:codes], :dump)
|
121
|
+
else
|
122
|
+
Geonames::Dump.work(Opt[:codes], :zip)
|
123
|
+
Geonames::Dump.work(Opt[:codes], :dump)
|
124
|
+
end
|
125
|
+
|
105
126
|
info "\n---\nTotal #{Cache[:dump].length} parsed. #{Cache[:zip].length} zips."
|
106
|
-
Sync.work!
|
127
|
+
# Sync.work!
|
128
|
+
info "Join dump << zip"
|
129
|
+
unify!
|
130
|
+
write_to_store!(db)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def load_adapter(name)
|
135
|
+
begin
|
136
|
+
require "geonames_local/adapters/#{name}"
|
137
|
+
require "geonames_local/models/#{name}"
|
138
|
+
Geonames.class_eval(name.capitalize).new(Opt[:db])
|
139
|
+
rescue LoadError
|
140
|
+
puts "Can't find adapter #{name}"
|
141
|
+
stop!
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def write_to_store!(db)
|
146
|
+
if Opt[:codes][0] == "country"
|
147
|
+
Cache[:countries] = Cache[:dump]
|
148
|
+
do_write(db, Cache[:countries])
|
149
|
+
else
|
150
|
+
groups = Cache[:dump].group_by(&:kind)
|
151
|
+
|
152
|
+
Cache[:provinces] = groups[:provinces]
|
153
|
+
Cache[:cities] = groups[:cities]
|
154
|
+
|
155
|
+
do_write(db, Cache[:provinces])
|
156
|
+
do_write(db, Cache[:cities])
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def do_write(db, values)
|
161
|
+
return if values.empty?
|
162
|
+
|
163
|
+
if Opt[:codes][0] == "country"
|
164
|
+
key = table = "countries"
|
165
|
+
else
|
166
|
+
key = values[0].table
|
167
|
+
end
|
168
|
+
start = Time.now
|
169
|
+
writt = 0
|
170
|
+
info "\nWriting #{values.length} #{key}..."
|
171
|
+
values.each do |val|
|
172
|
+
meth = val.respond_to?(:gid) ? [val.gid] : [val.name, true]
|
173
|
+
unless db.find(table || val.table, *meth)
|
174
|
+
db.insert(table || val.table, val)
|
175
|
+
writt += 1
|
176
|
+
end
|
107
177
|
end
|
178
|
+
total = Time.now - start
|
179
|
+
info "#{writt} #{key} written in #{total} sec (#{(writt/total).to_i}/s)"
|
108
180
|
end
|
109
181
|
|
182
|
+
def unify!
|
183
|
+
start = Time.now
|
184
|
+
Cache[:dump].map! do |spot|
|
185
|
+
if other = Cache[:zip].find { |d| d.code == spot.code }
|
186
|
+
spot.zip = other.zip
|
187
|
+
spot
|
188
|
+
else
|
189
|
+
spot
|
190
|
+
end
|
191
|
+
end
|
192
|
+
info "Done. #{(Time.now-start).to_i}s"
|
193
|
+
end
|
194
|
+
|
195
|
+
def stop!
|
196
|
+
puts "Closing Geonames..."
|
197
|
+
exit
|
198
|
+
end
|
110
199
|
end
|
111
200
|
|
112
201
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
#
|
2
2
|
# Geonames Local Config Example
|
3
3
|
#
|
4
|
-
|
5
|
-
:
|
6
|
-
:codes: [br, it]
|
4
|
+
:store: mongodb
|
5
|
+
:codes: [br] # to store all countries informations in the countries table, just write [country]
|
7
6
|
:level: city
|
8
7
|
:mapping:
|
9
8
|
:name: name
|
10
9
|
:geom: true
|
11
10
|
:db:
|
12
11
|
:host: localhost
|
13
|
-
:dbname:
|
12
|
+
:dbname: rtrac_development
|
14
13
|
:user: postgres
|
15
14
|
:password:
|
15
|
+
:purge: false
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'iconv'
|
1
|
+
# require 'iconv'
|
2
2
|
#---
|
3
3
|
# Iconv cool tip from http://po-ru.com/diary/fixing-invalid-utf-8-in-ruby-revisited/
|
4
4
|
|
@@ -9,7 +9,7 @@ module Geonames
|
|
9
9
|
@file = file
|
10
10
|
@fname = file.split("/")[-1] rescue nil
|
11
11
|
@type = Object.module_eval("::#{Opt[:type].capitalize}", __FILE__, __LINE__)
|
12
|
-
@ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
|
12
|
+
# @ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
|
13
13
|
@sample = nil
|
14
14
|
if file
|
15
15
|
shp2pg; parse; write
|
@@ -23,7 +23,7 @@ module Geonames
|
|
23
23
|
|
24
24
|
def parse_line(l)
|
25
25
|
return if l =~ /^SET\s|^BEGIN;|^COPY\s|^END;|^\\/
|
26
|
-
utf =
|
26
|
+
utf = l.encode('UTF-8')
|
27
27
|
unless @sample
|
28
28
|
info "Free sample\n" + utf.inspect
|
29
29
|
@sample = true
|
@@ -73,4 +73,3 @@ module Geonames
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
76
|
-
|
@@ -42,15 +42,21 @@ module Geonames
|
|
42
42
|
@kind = human_code(kind)
|
43
43
|
@province = adm1
|
44
44
|
@code = adm2
|
45
|
+
|
46
|
+
# puts "#{@kind} - #{@code} - #{@province}"
|
45
47
|
end
|
46
48
|
|
47
49
|
#
|
48
50
|
# Parse Geonames Zip Export
|
49
51
|
def parse_zip(row)
|
50
|
-
country, zip, @name, province, cc, dunno, adm1, adm2, lat, lon = row.split(/\t/)
|
52
|
+
# country, zip, @name, province, cc, dunno, adm1, adm2, lat, lon = row.split(/\t/)
|
53
|
+
# country, zip, @name, state, state_code, procince, province_code, community, community_code, lat, lon, acc = row.split(/\t/)
|
54
|
+
country, zip, @name, adm1, adm1_code, adm2, adm2_code, adm3, adm3_code, lat, lon, acc = row.split(/\t/)
|
51
55
|
parse_geom(lat, lon)
|
52
|
-
@code = adm1
|
53
|
-
@kind = :city
|
56
|
+
# @code = adm1
|
57
|
+
# @kind = :city
|
58
|
+
@code = adm1_code
|
59
|
+
@kind = :cities
|
54
60
|
@zip = zip.split("-")[0]
|
55
61
|
end
|
56
62
|
|
@@ -85,8 +91,8 @@ module Geonames
|
|
85
91
|
|
86
92
|
def human_code(code)
|
87
93
|
case code
|
88
|
-
when 'ADM1' then :
|
89
|
-
when 'ADM2' then :
|
94
|
+
when 'ADM1' then :provinces
|
95
|
+
when 'ADM2', 'ADM3', 'ADM4' then :cities
|
90
96
|
else :other
|
91
97
|
end
|
92
98
|
end
|
@@ -10,7 +10,6 @@ module Geonames
|
|
10
10
|
Opt = {}
|
11
11
|
Cache = {:dump => [], :zip => [], :roads => [], :zones => []}
|
12
12
|
Codes = YAML.load(File.read(File.join(File.dirname(__FILE__), 'config', 'codes.yml')))
|
13
|
-
VERSION = File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION'))
|
14
13
|
|
15
14
|
def info(txt)
|
16
15
|
if Opt[:verbose]
|
File without changes
|
@@ -10,6 +10,7 @@ module Geonames
|
|
10
10
|
|
11
11
|
validates_presence_of :country
|
12
12
|
validates_presence_of :name
|
13
|
+
# validates_uniqueness_of :name, :scope => :province_id
|
13
14
|
|
14
15
|
def abbr
|
15
16
|
province.try(:abbr) || country.abbr
|
@@ -29,20 +30,27 @@ module Geonames
|
|
29
30
|
self.geom = Point.from_x_y(@x.to_f, @y.to_f)
|
30
31
|
end
|
31
32
|
end
|
32
|
-
|
33
33
|
end
|
34
34
|
|
35
35
|
class Province < ActiveRecord::Base
|
36
36
|
has_many :cities
|
37
37
|
belongs_to :country
|
38
|
+
|
39
|
+
validates_uniqueness_of :name, :abbr, :scope => :country_id
|
38
40
|
end
|
39
41
|
|
40
42
|
class Country < ActiveRecord::Base
|
41
|
-
attr_accessor :code, :gid, :iso, :capital, :pop
|
42
43
|
has_many :provinces
|
43
44
|
has_many :cities
|
45
|
+
validates_presence_of :name, :abbr
|
46
|
+
validates_uniqueness_of :name, :abbr
|
47
|
+
end
|
48
|
+
|
49
|
+
class Spot < ActiveRecord::Base
|
50
|
+
validates_presence_of :name
|
44
51
|
end
|
45
52
|
|
53
|
+
|
46
54
|
end
|
47
55
|
end
|
48
56
|
end
|
@@ -2,8 +2,8 @@ module Geonames
|
|
2
2
|
module Models
|
3
3
|
module Tokyo
|
4
4
|
|
5
|
-
class Country
|
6
|
-
attr_accessor :code, :name, :gid, :iso, :capital, :pop
|
5
|
+
class Country
|
6
|
+
attr_accessor :code, :name, :gid, :iso, :capital, :pop, :currency
|
7
7
|
|
8
8
|
def self.all
|
9
9
|
Tokyo.new.all({ :kind => "country" }).map do |c|
|
@@ -39,9 +39,9 @@ class Country
|
|
39
39
|
parse(params)
|
40
40
|
end
|
41
41
|
|
42
|
-
def parse
|
43
|
-
@iso, @iso3, @ison, @fips, @name, @capital, @area, @pop, continent, tld,
|
44
|
-
currency, phone,
|
42
|
+
def parse(row)
|
43
|
+
@iso, @iso3, @ison, @fips, @name, @capital, @area, @pop, @continent, @tld,
|
44
|
+
@currency, @currency_name, @phone, @postal_format, @postal_regex, @langs, @gid, @neighbours = row.split(/\t/)
|
45
45
|
@code = iso
|
46
46
|
end
|
47
47
|
|
@@ -50,7 +50,12 @@ class Country
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def to_hash
|
53
|
-
{ "gid" => @gid.to_s, "name" => @name, "kind" => "country", "code" => @code}
|
53
|
+
# { "gid" => @gid.to_s, "name" => @name, "kind" => "country", "code" => @code, "currency" => @currency}
|
54
|
+
{ "gid" => @gid.to_s, "iso" => @iso, "iso3" => @iso3, "iso_num" => @ison, "fips" => @fips,
|
55
|
+
"name" => @name, "capital" => @capital, "area" => @area, "population" => @pop,
|
56
|
+
"continent" => @continent, "tld" => @tld, "currency_code" => @currency, "currency_name" => @currency_name,
|
57
|
+
"phone" => @phone, "postal_code_format" => @postal_format, "postal_code_regex" => @postal_regex,
|
58
|
+
"languages" => @langs, "neighbours" => @neighbours }
|
54
59
|
end
|
55
60
|
|
56
61
|
def export
|
metadata
CHANGED
@@ -1,67 +1,47 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: geonames_local
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 5
|
8
|
-
- 0
|
9
|
-
version: 0.5.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Marcos Piccinini
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
name: nofxx-georuby
|
22
|
-
prerelease: false
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
12
|
+
date: 2012-10-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: georuby
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
- 1
|
30
|
-
- 7
|
31
|
-
- 1
|
32
|
-
version: 1.7.1
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
33
22
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: rspec
|
37
23
|
prerelease: false
|
38
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
25
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
- 1
|
45
|
-
- 2
|
46
|
-
- 9
|
47
|
-
version: 1.2.9
|
48
|
-
type: :development
|
49
|
-
version_requirements: *id002
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.0.0
|
50
30
|
description: Dump and feed a tokyo cabinet for local geonames search
|
51
31
|
email: x@nofxx.com
|
52
|
-
executables:
|
32
|
+
executables:
|
53
33
|
- geonames
|
54
34
|
extensions: []
|
55
|
-
|
56
|
-
extra_rdoc_files:
|
35
|
+
extra_rdoc_files:
|
57
36
|
- LICENSE
|
58
37
|
- README.rdoc
|
59
|
-
files:
|
38
|
+
files:
|
60
39
|
- .document
|
40
|
+
- .gitignore
|
41
|
+
- Gemfile
|
61
42
|
- LICENSE
|
62
43
|
- README.rdoc
|
63
44
|
- Rakefile
|
64
|
-
- VERSION
|
65
45
|
- bin/geonames
|
66
46
|
- geonames.yml
|
67
47
|
- geonames_local.gemspec
|
@@ -83,9 +63,10 @@ files:
|
|
83
63
|
- lib/geonames_local/features/spot.rb
|
84
64
|
- lib/geonames_local/features/zone.rb
|
85
65
|
- lib/geonames_local/geonames.rb
|
86
|
-
- lib/geonames_local/models/
|
87
|
-
- lib/geonames_local/models/
|
66
|
+
- lib/geonames_local/models/mongodb.rb
|
67
|
+
- lib/geonames_local/models/postgis.rb
|
88
68
|
- lib/geonames_local/models/tokyo.rb
|
69
|
+
- lib/geonames_local/version.rb
|
89
70
|
- spec/geonames_local/adapters/mongodb_spec.rb
|
90
71
|
- spec/geonames_local/adapters/postgres_spec.rb
|
91
72
|
- spec/geonames_local/adapters/tokyo_spec.rb
|
@@ -104,50 +85,36 @@ files:
|
|
104
85
|
- spec/spec_mongo_helper.rb
|
105
86
|
- task/benchmark.rb
|
106
87
|
- task/benchmark_cabinet.rb
|
107
|
-
has_rdoc: true
|
108
88
|
homepage: http://github.com/nofxx/geonames_local
|
109
89
|
licenses: []
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
----------\n\n\
|
117
|
-
Be sure to use a database based on the PostGIS template.\n\n\
|
118
|
-
MongoDB\n\
|
119
|
-
-------\n\n\
|
120
|
-
MongoDB 2D support is new, only mongo >= 1.3.3 mongodb gem >= 0.19.2\n\
|
121
|
-
http://github.com/mongodb/mongo-ruby-driver\n\n\
|
122
|
-
Have fun because:\n"
|
90
|
+
post_install_message: ! "\nGeonames Local\n--------------\n\nTo use the adapter, install
|
91
|
+
the corresponding gem:\n\n PostgreSQL => pg\n MongoDB => mongodb (optional:
|
92
|
+
mongo_ext)\n Tokyo => tokyocabinet\n\nPostgreSQL\n----------\n\nBe sure
|
93
|
+
to use a database based on the PostGIS template.\n\nMongoDB\n-------\n\nMongoDB
|
94
|
+
2D support is new, only mongo >= 1.3.3 mongodb gem >= 0.19.2\nhttp://github.com/mongodb/mongo-ruby-driver\n\nHave
|
95
|
+
fun because:\n"
|
123
96
|
rdoc_options: []
|
124
|
-
|
125
|
-
require_paths:
|
97
|
+
require_paths:
|
126
98
|
- lib
|
127
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
100
|
none: false
|
129
|
-
requirements:
|
130
|
-
- -
|
131
|
-
- !ruby/object:Gem::Version
|
132
|
-
|
133
|
-
|
134
|
-
version: "0"
|
135
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
106
|
none: false
|
137
|
-
requirements:
|
138
|
-
- -
|
139
|
-
- !ruby/object:Gem::Version
|
140
|
-
|
141
|
-
- 0
|
142
|
-
version: "0"
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
143
111
|
requirements: []
|
144
|
-
|
145
112
|
rubyforge_project:
|
146
|
-
rubygems_version: 1.
|
113
|
+
rubygems_version: 1.8.23
|
147
114
|
signing_key:
|
148
115
|
specification_version: 3
|
149
116
|
summary: Dump and feed a tokyo local geonames db
|
150
|
-
test_files:
|
117
|
+
test_files:
|
151
118
|
- spec/geonames_local/adapters/mongodb_spec.rb
|
152
119
|
- spec/geonames_local/adapters/postgres_spec.rb
|
153
120
|
- spec/geonames_local/adapters/tokyo_spec.rb
|
@@ -164,3 +131,4 @@ test_files:
|
|
164
131
|
- spec/spec_ar_helper.rb
|
165
132
|
- spec/spec_helper.rb
|
166
133
|
- spec/spec_mongo_helper.rb
|
134
|
+
has_rdoc:
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.5.0
|