geonames_local 3.3.3 → 3.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -3
- data/README.md +10 -21
- data/Rakefile +3 -11
- data/geonames_local.gemspec +22 -22
- data/lib/geonames_local/cli.rb +3 -3
- data/lib/geonames_local/config/geonames.sql +3 -3
- data/lib/geonames_local/features/spot.rb +5 -15
- data/lib/geonames_local/models/mongodb.rb +4 -12
- data/lib/geonames_local/models/postgis.rb +2 -2
- data/lib/geonames_local/regions/abbr.rb +24 -0
- data/lib/geonames_local/version.rb +1 -1
- data/lib/geonames_local.rb +3 -0
- data/spec/spec_ar_helper.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ba4f5b249b265786ed141a7cb788ecbbdb8d972
|
4
|
+
data.tar.gz: 5c72a80db053d42786b373207892e353ccac08d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5be133df0fde1cc8b007d7b4369d497b2b1e012fe234d7a2ae7c250433b98dfea5fdec5fd434c91c7ab1da33983ee46f5d1b58775eed08907a18ec3404f9c6c4
|
7
|
+
data.tar.gz: cf0e1a0d83460d355a70b7edf7fdd95c9c13c700502a5c08404d7cca4afcbfb637a3e9d014b0f5df55ba7880cd129788a99ece4bc8701b1382df698a914371b9
|
data/Gemfile
CHANGED
@@ -2,6 +2,7 @@ source 'http://rubygems.org'
|
|
2
2
|
gemspec # Specify gem's dependencies in mongoid_geospatial.gemspec
|
3
3
|
|
4
4
|
gem 'rake'
|
5
|
+
gem 'pry'
|
5
6
|
gem 'dbf'
|
6
7
|
|
7
8
|
platforms :ruby do
|
@@ -9,10 +10,7 @@ platforms :ruby do
|
|
9
10
|
end
|
10
11
|
|
11
12
|
gem 'georuby'
|
12
|
-
|
13
|
-
gem 'mongoid'
|
14
13
|
gem 'mongoid_geospatial'
|
15
14
|
|
16
|
-
gem 'pry'
|
17
15
|
gem 'rspec'
|
18
16
|
gem 'guard-rspec'
|
data/README.md
CHANGED
@@ -27,22 +27,16 @@ Create a config yml file:
|
|
27
27
|
|
28
28
|
geonames init
|
29
29
|
|
30
|
-
Will generate a
|
30
|
+
Will generate a `geonames.yml` file on your folder.
|
31
31
|
The file is self explanatory.
|
32
32
|
|
33
|
-
Geonames splits the nations/countries database from the rest, so:
|
33
|
+
Geonames *splits the nations/countries database* from the rest, so:
|
34
|
+
It'll also populate the nations collection automatically: `252` nations.
|
34
35
|
|
35
36
|
|
36
|
-
To populate the nations database for the first time use:
|
37
|
-
|
38
|
-
geonames -c geoconfig.yml nations
|
39
|
-
|
40
|
-
|
41
|
-
Then you can run geonames to populate regions/cities...
|
42
|
-
|
43
37
|
geonames -c geonames.yml
|
44
38
|
|
45
|
-
To run it. Use
|
39
|
+
To run it. Use `-v` for verbose.
|
46
40
|
|
47
41
|
|
48
42
|
If you are not sure your country/nation code, use:
|
@@ -50,25 +44,20 @@ If you are not sure your country/nation code, use:
|
|
50
44
|
geonames list <search>
|
51
45
|
|
52
46
|
|
47
|
+
Mongoid
|
48
|
+
-------
|
53
49
|
|
54
|
-
|
55
|
-
--------
|
50
|
+
Using **http://github.com/fireho/geopolitical** models:
|
56
51
|
|
57
|
-
So, supposing Mongoid, something like this is possible:
|
58
52
|
|
59
|
-
City.first.
|
53
|
+
City.first.region.nation.abbr
|
60
54
|
=> "BR"
|
61
55
|
|
62
56
|
|
63
|
-
== Postgis
|
64
|
-
|
65
|
-
TBD (by someone else)
|
66
|
-
Be sure to use a database based on the PostGIS template.
|
67
|
-
|
68
|
-
|
69
|
-
|
70
57
|
|
71
58
|
Next
|
72
59
|
----
|
73
60
|
|
74
61
|
- IP Geonames? http://ipinfodb.com
|
62
|
+
- Hoods? ftp://geoftp.ibge.gov.br/malhas_digitais/censo_2010/setores_censitarios/
|
63
|
+
- ActiveRecord/PostGIS - someone else
|
data/Rakefile
CHANGED
@@ -1,22 +1,14 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
2
|
require 'bundler/gem_tasks'
|
3
3
|
|
4
|
-
require 'rspec/core'
|
5
4
|
require 'rspec/core/rake_task'
|
5
|
+
require 'rubocop/rake_task'
|
6
6
|
|
7
|
-
RSpec::Core::RakeTask.new
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
12
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
13
|
-
spec.rcov = true
|
14
|
-
end
|
7
|
+
RSpec::Core::RakeTask.new
|
8
|
+
RuboCop::RakeTask.new
|
15
9
|
|
16
10
|
task default: :spec
|
17
11
|
|
18
|
-
require 'yard'
|
19
|
-
|
20
12
|
#
|
21
13
|
# Tokyo Tyrant rake tasks
|
22
14
|
#
|
data/geonames_local.gemspec
CHANGED
@@ -1,33 +1,33 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
require File.expand_path('../lib/geonames_local/version', __FILE__)
|
3
3
|
|
4
|
-
Gem::Specification.new do |
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'geonames_local'
|
6
|
+
s.version = Geonames::VERSION
|
7
|
+
s.homepage = 'http://github.com/nofxx/geonames_local'
|
8
|
+
|
9
|
+
s.authors = ['Marcos Piccinini']
|
10
|
+
s.default_executable = 'geonames'
|
11
|
+
s.description = 'Dumps geonames data to feed a local db'
|
12
|
+
s.email = 'x@nofxx.com'
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
15
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.name = 'geonames_local'
|
19
|
+
s.require_paths = ['lib']
|
20
|
+
s.summary = 'Dumps geonames data for local usage'
|
21
|
+
|
22
|
+
s.extra_rdoc_files = [
|
23
23
|
'MIT-LICENSE',
|
24
24
|
'README.md'
|
25
25
|
]
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
s.add_dependency('mongoid', ['>= 4.0.0'])
|
28
|
+
s.add_dependency('geopolitical', ['> 0.8.4'])
|
29
29
|
|
30
|
-
|
30
|
+
s.post_install_message = '
|
31
31
|
Geonames Local
|
32
32
|
--------------
|
33
33
|
|
data/lib/geonames_local/cli.rb
CHANGED
@@ -95,7 +95,7 @@ module Geonames
|
|
95
95
|
info "\nPopulating 'regions' and 'cities' database..."
|
96
96
|
zip = Geonames::Dump.new(Opt[:nations], :zip).data
|
97
97
|
dump = Geonames::Dump.new(Opt[:nations], :dump).data
|
98
|
-
info "\n---\nTotal #{dump.size} parsed. #{zip.size}
|
98
|
+
info "\n---\nTotal #{dump.size} parsed. #{zip.size} postal codes."
|
99
99
|
|
100
100
|
info 'Join dump << zip'
|
101
101
|
dump = unify!(dump, zip).group_by(&:kind)
|
@@ -156,8 +156,8 @@ module Geonames
|
|
156
156
|
load_adapter(Opt[:store])
|
157
157
|
info "Using adapter #{Opt[:store]}.."
|
158
158
|
wrapper.clean if Opt[:clean]
|
159
|
-
Benchmark.measure { work_nations } unless wrapper.nations_populated?
|
160
|
-
Benchmark.measure { work_spots }
|
159
|
+
puts Benchmark.measure { work_nations } unless wrapper.nations_populated?
|
160
|
+
puts Benchmark.measure { work_spots }
|
161
161
|
end
|
162
162
|
|
163
163
|
def load_adapter(name)
|
@@ -29,7 +29,7 @@ CREATE TABLE cities (
|
|
29
29
|
region_id integer,
|
30
30
|
name character varying(255) NOT NULL,
|
31
31
|
gid integer,
|
32
|
-
|
32
|
+
postal integer,
|
33
33
|
geom geometry,
|
34
34
|
CONSTRAINT enforce_dims_geom CHECK ((st_ndims(geom) = 2)),
|
35
35
|
CONSTRAINT enforce_geotype_geom CHECK (((geometrytype(geom) = 'POINT'::text) OR (geom IS NULL))),
|
@@ -127,10 +127,10 @@ CREATE INDEX index_cities_on_region_id ON cities USING btree (region_id);
|
|
127
127
|
--
|
128
128
|
-- TOC entry 2554 (class 1259 OID 21696)
|
129
129
|
-- Dependencies: 2245
|
130
|
-
-- Name:
|
130
|
+
-- Name: index_cities_on_postal; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
131
131
|
--
|
132
132
|
|
133
|
-
CREATE INDEX
|
133
|
+
CREATE INDEX index_cities_on_postal ON cities USING btree (postal);
|
134
134
|
|
135
135
|
|
136
136
|
--
|
@@ -20,20 +20,7 @@ module Geonames
|
|
20
20
|
kind == :zip ? parse_zip(params) : parse(params)
|
21
21
|
if @kind == :region
|
22
22
|
@name.gsub!(/Estado d\w\s/, '')
|
23
|
-
@
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
#
|
28
|
-
# Geonames does not have region/state abbr..#fail!
|
29
|
-
# This works 75% of the time in brazil heh
|
30
|
-
#
|
31
|
-
def get_abbr
|
32
|
-
s = @name.split(' ')
|
33
|
-
if s.length > 1
|
34
|
-
[s[0][0].chr, s[-1][0].chr].map(&:upcase).join
|
35
|
-
else
|
36
|
-
s[0][0..1].upcase
|
23
|
+
@name.gsub!(/Federal District/, 'Distrito Federal')
|
37
24
|
end
|
38
25
|
end
|
39
26
|
|
@@ -41,13 +28,16 @@ module Geonames
|
|
41
28
|
# Parse Geonames Dump Export
|
42
29
|
#
|
43
30
|
def parse(row)
|
44
|
-
gid,
|
31
|
+
gid, name, @ascii, @alternates, lat, lon, feat, kind,
|
45
32
|
@nation, _cc2, @region, @code, _adm3, _adm4, @pop, @ele,
|
46
33
|
@gtop, @tz, @up = row.split(/\t/)
|
47
34
|
|
35
|
+
@name = name #name.encode(Encoding::ISO_8859_1)
|
48
36
|
@gid = @geoname_id = gid.to_i
|
49
37
|
@kind = human_code(kind)
|
50
38
|
|
39
|
+
@abbr = @alternates.split(',').find { |n| n =~ /^[A-Z]{2,3}$/ }
|
40
|
+
|
51
41
|
parse_geom(lat, lon)
|
52
42
|
# puts "#{@kind} - #{@code} - #{@region}"
|
53
43
|
end
|
@@ -62,7 +62,7 @@ module Geonames
|
|
62
62
|
# info "------------------------"
|
63
63
|
{
|
64
64
|
name_translations: translate(name),
|
65
|
-
|
65
|
+
postal: pos_code, cash: cur_code, gid: gid,
|
66
66
|
abbr: abbr, slug: name.downcase, code: iso3, lang: langs
|
67
67
|
}
|
68
68
|
end
|
@@ -85,22 +85,14 @@ module Geonames
|
|
85
85
|
#
|
86
86
|
def parse_city(s)
|
87
87
|
region = Region.find_by(code: s.region)
|
88
|
-
slug = City.new(slug: s.ascii).slug
|
89
|
-
attempt = slug.dup
|
90
|
-
try = 1
|
91
|
-
until City.where(slug: attempt.downcase).first.nil?
|
92
|
-
attempt = "#{slug}-#{region.abbr}-#{try}"
|
93
|
-
try += 1
|
94
|
-
break if try > 7
|
95
|
-
end
|
96
88
|
# ---
|
97
89
|
# info s.inspect
|
98
|
-
info "City: #{s.zip} | #{
|
90
|
+
info "City: #{s.zip} | #{s.name} / #{region.try(:abbr)}"
|
99
91
|
{
|
100
92
|
name_translations: translate(s.name),
|
101
|
-
|
93
|
+
gid: s.gid, code: s.code,
|
102
94
|
souls: s.pop, geom: [s.lon, s.lat],
|
103
|
-
region: region,
|
95
|
+
region: region, postal: s.zip # tz
|
104
96
|
}
|
105
97
|
end
|
106
98
|
end
|
@@ -63,7 +63,7 @@ end
|
|
63
63
|
# t.references :province
|
64
64
|
# t.string :name, :null => false
|
65
65
|
# t.point :geom, :srid => 4326
|
66
|
-
# t.integer :gid, :
|
66
|
+
# t.integer :gid, :postal
|
67
67
|
# end
|
68
68
|
|
69
69
|
# create_table :provinces do |t|
|
@@ -79,7 +79,7 @@ end
|
|
79
79
|
# end
|
80
80
|
|
81
81
|
# add_index :cities, :name
|
82
|
-
# add_index :cities, :
|
82
|
+
# add_index :cities, :postal
|
83
83
|
# add_index :cities, :country_id
|
84
84
|
# add_index :cities, :province_id
|
85
85
|
# add_index :cities, :gid, :unique => true
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Geonames
|
2
|
+
module Regions
|
3
|
+
|
4
|
+
#
|
5
|
+
# Geonames does not have region/state abbr..#fail!
|
6
|
+
# This works 75% of the time in brazil heh
|
7
|
+
def self.abbr(name)
|
8
|
+
table = { # exceptions
|
9
|
+
'Amapá' => 'AP',
|
10
|
+
'Mato Grosso' => 'MT',
|
11
|
+
'Paraíba' => 'PB',
|
12
|
+
'Paraná' => 'PR',
|
13
|
+
'Roraima' => 'RR'
|
14
|
+
}[name]
|
15
|
+
return table if table
|
16
|
+
s = name.split(' ')
|
17
|
+
if s.length > 1 # Foo Bar -> 'FB'
|
18
|
+
[s[0][0].chr, s[-1][0].chr].map(&:upcase).join
|
19
|
+
else # Foobar -> 'FO'
|
20
|
+
s[0][0..1].upcase
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/geonames_local.rb
CHANGED
data/spec/spec_ar_helper.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geonames_local
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.
|
4
|
+
version: 3.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcos Piccinini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 4.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: geopolitical
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.8.
|
33
|
+
version: 0.8.4
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.8.
|
40
|
+
version: 0.8.4
|
41
41
|
description: Dumps geonames data to feed a local db
|
42
42
|
email: x@nofxx.com
|
43
43
|
executables:
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/geonames_local/models/mongodb.rb
|
72
72
|
- lib/geonames_local/models/postgis.rb
|
73
73
|
- lib/geonames_local/models/tokyo.rb
|
74
|
+
- lib/geonames_local/regions/abbr.rb
|
74
75
|
- lib/geonames_local/version.rb
|
75
76
|
- spec/geonames_local/cli_spec.rb
|
76
77
|
- spec/geonames_local/data/cache_spec.rb
|
@@ -116,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
117
|
version: '0'
|
117
118
|
requirements: []
|
118
119
|
rubyforge_project:
|
119
|
-
rubygems_version: 2.4.
|
120
|
+
rubygems_version: 2.4.7
|
120
121
|
signing_key:
|
121
122
|
specification_version: 4
|
122
123
|
summary: Dumps geonames data for local usage
|
@@ -134,4 +135,3 @@ test_files:
|
|
134
135
|
- spec/geonames_local_spec.rb
|
135
136
|
- spec/spec_ar_helper.rb
|
136
137
|
- spec/spec_helper.rb
|
137
|
-
has_rdoc:
|