geonames_local 3.1.1 → 3.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e73d4bb7dd75933118a18ad64f13563e47b64e5
4
- data.tar.gz: fc75d8a753756a87433b16c9da287cb9bd9bc090
3
+ metadata.gz: 6c076a06bf13c93cdc9f86aa0a7b215f92fc148b
4
+ data.tar.gz: 01481b044838b7b3cde40de3ff0103ad7c932771
5
5
  SHA512:
6
- metadata.gz: 82c9f917f022ba89fe63b7cb817e04f4652ba37eaf651760cd5a1c4409a2d090cbf495b23e0117c9f7eedeb860da3f6164aff83f22ebd58be3d72d81ae5a2f2c
7
- data.tar.gz: 50d6134373286472f0980f4e68046c355eba088c89311a2b3f0148ff4463284d0c0456d147f19dca033586e4cc1159900cca452e217680a378b12e1eb4e71bc7
6
+ metadata.gz: 76f0ce5d8302588eedf7b05b25f2e1868169dc138c74e9618c8e16efe98a00f24bf085bfa8db0a049d4d1fe2cfa846c1981df5bcb58bf513f85f11c4919bbc64
7
+ data.tar.gz: df126c44103aaa93d2e20197c053894de6778622220f5031c2f399766342cd9351d27273a5d379ea98d4ed863daf011d219cc26636368f0f29ed4e10af360a37
data/.gitignore CHANGED
@@ -26,3 +26,5 @@ pkg
26
26
  *.qgr
27
27
  *.lex
28
28
  shps
29
+ Gemfile.lock
30
+ tmp/*
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+ require 'guard'
4
+
5
+ guard 'rspec' do
6
+ watch(%r{^spec/.+_spec\.rb$})
7
+ watch(%r{^lib/(.+)\.rb$}) { "spec" } # { |m| "spec spec/lib/#{m[1]}_spec.rb" }
8
+ watch('spec/spec_helper.rb') { "spec" }
9
+ end
data/README.rdoc CHANGED
@@ -1,17 +1,16 @@
1
1
  = Geonames Local
2
2
 
3
- Downloads and store Geonames.org data locally (MongoDB, PostGIS, Tokyo).
3
+ Downloads and store Geonames.org data locally (MongoDB, Mongoid).
4
4
  Making every Geoname API operation possible on your servers.
5
5
  No hit limit, fast as possible.
6
6
 
7
7
 
8
8
  == Usage
9
9
 
10
- To use one adapter, install the corresponding gem:
10
+ Install where you want to populate the DB:
11
+
12
+ gem install geonames_local
11
13
 
12
- MongoDB => mongoid, geopolitical (optional: mongo_ext)
13
- PostgreSQL => pg
14
- Tokyo => tokyocabinet
15
14
 
16
15
  You will also need in your system:
17
16
 
@@ -21,8 +20,13 @@ You will also need in your system:
21
20
 
22
21
  === Config YML
23
22
 
23
+
24
+ Create a config yml file:
25
+
26
+
24
27
  geonames conf
25
28
 
29
+
26
30
  Will generate a "geonames.yml" file on your folder.
27
31
  The file is self explanatory.
28
32
 
@@ -30,13 +34,13 @@ The file is self explanatory.
30
34
 
31
35
  To run it. Use -v for verbose.
32
36
 
33
- If you are not sure your country code, use:
37
+ If you are not sure your country/nation code, use:
34
38
 
35
39
  geonames list <search>
36
40
 
37
- To populate the countries database for the first time use:
41
+ To populate the nations database for the first time use:
38
42
 
39
- geonames -c geoconfig.yml countries
43
+ geonames -c geoconfig.yml nations
40
44
 
41
45
 
42
46
  == Mongoid
@@ -53,42 +57,6 @@ TBD (by someone else)
53
57
  Be sure to use a database based on the PostGIS template.
54
58
 
55
59
 
56
- === Migration
57
-
58
- Default PG migration:
59
-
60
- create_table :cities do |t|
61
- t.references :country, :null => false
62
- t.references :province
63
- t.string :name, :null => false
64
- t.point :geom, :srid => 4326
65
- t.integer :gid, :zip
66
- end
67
-
68
- create_table :provinces do |t|
69
- t.references :country, :null => false
70
- t.string :name, :null => false
71
- t.string :abbr, :limit => 2, :null => false
72
- t.integer :gid
73
- end
74
-
75
- create_table :countries do |t|
76
- t.string :name, :limit => 30, :null => false
77
- t.string :abbr, :limit => 2, :null => false
78
- end
79
-
80
- add_index :cities, :name
81
- add_index :cities, :zip
82
- add_index :cities, :country_id
83
- add_index :cities, :province_id
84
- add_index :cities, :gid, :unique => true
85
- add_index :cities, :geom, :spatial => true
86
- add_index :provinces, :name
87
- add_index :provinces, :abbr
88
- add_index :provinces, :country_id
89
- add_index :provinces, :gid, :unique => true
90
- add_index :countries, :abbr, :unique => true
91
- add_index :countries, :name, :unique => true
92
60
 
93
61
 
94
62
  == TODO/Problems
@@ -18,7 +18,7 @@ module Geonames
18
18
  class << self
19
19
 
20
20
  def nations data, clean
21
- Nation.delete_all # if clean
21
+ Nation.delete_all if clean
22
22
  data.each do |row|
23
23
  create Nation, parse_nation(row) rescue nil
24
24
  end
@@ -26,7 +26,7 @@ module Geonames
26
26
 
27
27
 
28
28
  def batch data, clean = false
29
- [Region, City].each(&:delete_all) #if clean
29
+ [Region, City].each(&:delete_all) if clean
30
30
 
31
31
  @regions, @cities = data[:region], data[:city]
32
32
  @regions.each { |r| create Region, parse_region(r) }
@@ -81,8 +81,8 @@ module Geonames
81
81
  try += 1
82
82
  break if try > 7
83
83
  end
84
-
85
- info s.inspect
84
+ # ---
85
+ # info s.inspect
86
86
  info "City: #{s.zip} | #{slug} - #{s.name} / #{region.try(:abbr)}"
87
87
  {
88
88
  name_translations: translate(s.name),
@@ -54,3 +54,41 @@ module Geonames
54
54
  #end
55
55
  end
56
56
  end
57
+
58
+
59
+ # === Migration
60
+
61
+ # Default PG migration:
62
+
63
+ # create_table :cities do |t|
64
+ # t.references :country, :null => false
65
+ # t.references :province
66
+ # t.string :name, :null => false
67
+ # t.point :geom, :srid => 4326
68
+ # t.integer :gid, :zip
69
+ # end
70
+
71
+ # create_table :provinces do |t|
72
+ # t.references :country, :null => false
73
+ # t.string :name, :null => false
74
+ # t.string :abbr, :limit => 2, :null => false
75
+ # t.integer :gid
76
+ # end
77
+
78
+ # create_table :countries do |t|
79
+ # t.string :name, :limit => 30, :null => false
80
+ # t.string :abbr, :limit => 2, :null => false
81
+ # end
82
+
83
+ # add_index :cities, :name
84
+ # add_index :cities, :zip
85
+ # add_index :cities, :country_id
86
+ # add_index :cities, :province_id
87
+ # add_index :cities, :gid, :unique => true
88
+ # add_index :cities, :geom, :spatial => true
89
+ # add_index :provinces, :name
90
+ # add_index :provinces, :abbr
91
+ # add_index :provinces, :country_id
92
+ # add_index :provinces, :gid, :unique => true
93
+ # add_index :countries, :abbr, :unique => true
94
+ # add_index :countries, :name, :unique => true
@@ -1,3 +1,3 @@
1
1
  module Geonames
2
- VERSION = '3.1.1'
2
+ VERSION = '3.1.3'
3
3
  end
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+ require "spec_helper"
3
3
  require "geo_ruby"
4
4
 
5
5
  describe Spot do
@@ -17,8 +17,8 @@ describe Spot do
17
17
  spot.code.should eql("6593")
18
18
  end
19
19
 
20
- it "should parse province code" do
21
- spot.province.should eql("2407500")
20
+ it "should parse region code" do
21
+ spot.region.should eql("2407500")
22
22
  end
23
23
 
24
24
  it "should parse name" do
@@ -36,8 +36,8 @@ describe Spot do
36
36
  spot.kind.should eql(:city)
37
37
  end
38
38
 
39
- it "should parse spot country" do
40
- spot.country.should eql("BR")
39
+ it "should parse spot nation" do
40
+ spot.nation.should eql("BR")
41
41
  end
42
42
 
43
43
  it "shuold parse timezone" do
@@ -72,8 +72,8 @@ describe Spot do
72
72
  spot.kind.should eql(:other)
73
73
  end
74
74
 
75
- it "should parse spot country" do
76
- spot.country.should eql("BR")
75
+ it "should parse spot nation" do
76
+ spot.nation.should eql("BR")
77
77
  end
78
78
 
79
79
  it "shuold parse timezone" do
@@ -86,12 +86,12 @@ describe Spot do
86
86
  end
87
87
  end
88
88
 
89
- describe "Parsing Province" do
89
+ describe "Parsing Region" do
90
90
 
91
91
  let(:spot) { Geonames::Spot.new("3457153\tEstado de Minas Gerais\tEstado de Minas Gerais\tMinas,Minas Geraes,Minas Gerais\t-18.0\t-44.0\tA\tADM1\tBR\tBR\t15\t\t\t\t16672613\t\t1219\tAmerica/Sao_Paulo\t2007-05-15\n", :dump) }
92
92
 
93
- it "should be kind of province" do
94
- spot.kind.should eql(:province)
93
+ it "should be kind of region" do
94
+ spot.kind.should eql(:region)
95
95
  end
96
96
 
97
97
  it "should parse geoid" do
@@ -103,8 +103,8 @@ describe Spot do
103
103
  spot.code.should be_empty
104
104
  end
105
105
 
106
- it "should parse province code" do
107
- spot.province.should eql("15")
106
+ it "should parse region code" do
107
+ spot.region.should eql("15")
108
108
  end
109
109
 
110
110
  it "should create abbr" do
@@ -151,12 +151,12 @@ describe Spot do
151
151
  spot.kind.should eql(:city)
152
152
  end
153
153
 
154
- it "should parse country" do
155
- spot.country.should eql("BR")
154
+ it "should parse nation" do
155
+ spot.nation.should eql("BR")
156
156
  end
157
157
 
158
- it "should parse province" do
159
- spot.province.should eql("06")
158
+ it "should parse region" do
159
+ spot.region.should eql("06")
160
160
  end
161
161
 
162
162
  it "should parse pop" do
@@ -193,13 +193,12 @@ describe Spot do
193
193
  spot.kind.should eql(:city)
194
194
  end
195
195
 
196
- it "should parse country" do
197
- spot.country.should eql("BR")
196
+ it "should parse nation" do
197
+ spot.nation.should eql("BR")
198
198
  end
199
199
 
200
- it "should parse province" do
201
- pending
202
- spot.province.should eql("18")
200
+ it "should parse region" do
201
+ spot.region.should eql("18")
203
202
  end
204
203
 
205
204
  it "should parse pop" do
@@ -211,10 +210,10 @@ describe Spot do
211
210
 
212
211
  describe "Parsing Zip" do
213
212
 
214
- let(:spot) { Geonames::Spot.new("BR\t76375-000\tHidrolina\tGoias\t29\t\t5209804\t\t\t-14.7574\t-49.3596\t\n", :zip) }
213
+ let(:spot) { Geonames::Spot.new("BR\t76375-000\tHidrolina\tGoias\t\t5209804\t29\t\t\t-14.7574\t-49.3596\t\n", :zip) }
215
214
 
216
215
  it "should parse zip oO" do
217
- spot.zip.should eql("76375")
216
+ spot.zip.should eql("76375-000")
218
217
  end
219
218
 
220
219
  it "should be a city" do
@@ -246,7 +245,7 @@ describe Spot do
246
245
 
247
246
  describe "From Hash" do
248
247
 
249
- let(:spot) { Spot.from_hash({"id" => 9, "name" => "Sao Rock", "geom" => [15,15], "kind" => "city", "country" => "BR", "gid" => 13232, "tz" => "America/Foo", "ascii" => "Rock"}) }
248
+ let(:spot) { Spot.from_hash({"id" => 9, "name" => "Sao Rock", "geom" => [15,15], "kind" => "city", "nation" => "BR", "gid" => 13232, "tz" => "America/Foo", "ascii" => "Rock"}) }
250
249
 
251
250
  it "should be an spot" do
252
251
  spot.should be_instance_of Spot
@@ -269,8 +268,8 @@ describe Spot do
269
268
  spot.ascii.should eql("Rock")
270
269
  end
271
270
 
272
- it "should set the country abbr" do
273
- spot.country.should eql("BR")
271
+ it "should set the nation abbr" do
272
+ spot.nation.should eql("BR")
274
273
  end
275
274
 
276
275
  end
@@ -1,42 +1,152 @@
1
1
  # -*- coding: utf-8 -*-
2
- require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require "spec_helper"
3
3
 
4
- require 'geonames_local/models/mongodb'
5
- include Models::Mongo
4
+ # require 'geonames_local/models/mongodb'
5
+ # include Models::Mongo
6
6
 
7
- describe "City" do
7
+ # describe "City" do
8
8
 
9
- # before(:all) do
10
- # Models::Mongo::City.insert("cities", {"id" => 9, "name" => "Sao Paulo", "geom" => [15,15]})
11
- # Models::Mongo::City.insert("cities", {"id" => 66, "name" => "Rock City", "geom" => [2,3]})
12
- # end
9
+ # # before(:all) do
10
+ # # Models::Mongo::City.insert("cities", {"id" => 9, "name" => "Sao Paulo", "geom" => [15,15]})
11
+ # # Models::Mongo::City.insert("cities", {"id" => 66, "name" => "Rock City", "geom" => [2,3]})
12
+ # # end
13
13
 
14
- after(:all) do
15
- Mongodb.new({:dbname => "geonames_test"}).purge
16
- end
14
+ # after(:all) do
15
+ # Mongodb.new({:dbname => "geonames_test"}).purge
16
+ # end
17
17
 
18
- it "should set a collection name" do
19
- City.collection.should eql("cities")
20
- end
18
+ # it "should set a collection name" do
19
+ # City.collection.should eql("cities")
20
+ # end
21
21
 
22
- it "should find all cities" do
23
- Models::Mongo::City.all.should_not be_empty
24
- end
22
+ # it "should find all cities" do
23
+ # Models::Mongo::City.all.should_not be_empty
24
+ # end
25
25
 
26
- it "should be a city instance" do
27
- Models::Mongo::City.nearest(1,1).should be_instance_of(Models::Mongo::City)
28
- end
26
+ # it "should be a city instance" do
27
+ # Models::Mongo::City.nearest(1,1).should be_instance_of(Models::Mongo::City)
28
+ # end
29
29
 
30
- it "should find city nearest point" do
31
- Models::Mongo::City.nearest(1,1).name.should eql("Rock City")
32
- end
30
+ # it "should find city nearest point" do
31
+ # Models::Mongo::City.nearest(1,1).name.should eql("Rock City")
32
+ # end
33
33
 
34
- it "should find by name" do
35
- Models::Mongo::City.find_by_name("Rock")[0].name.should eql("Rock City")
36
- end
34
+ # it "should find by name" do
35
+ # Models::Mongo::City.find_by_name("Rock")[0].name.should eql("Rock City")
36
+ # end
37
37
 
38
- it "should find by name" do
39
- City.find_by_name("rock").first.name.should eql("Rock City")
40
- end
38
+ # it "should find by name" do
39
+ # City.find_by_name("rock").first.name.should eql("Rock City")
40
+ # end
41
41
 
42
- end
42
+ # end
43
+ # require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
44
+ # require File.expand_path(File.dirname(__FILE__) + '/../../../lib/geonames_local/adapters/mongodb')
45
+
46
+ # describe "Mongo Models" do
47
+
48
+ # SPECDB = "geonames_spec"
49
+
50
+ # before() do
51
+ # Mongodb.new({:dbname => SPECDB}).purge
52
+ # @mong = Mongodb.new({:dbname => SPECDB})
53
+
54
+ # end
55
+
56
+ # def mock_spot(name)
57
+ # Spot.new("1\t#{name}\t#{name}\t\t-5.46874226086957\t-35.3565714695652\tA\tADM2\tBR\t22\t2407500\t6593\t\t12\t\t\t\tAmerica/Recife\t2006-12-17", :dump)
58
+ # end
59
+
60
+ # describe "Parsing dump" do
61
+ # before do
62
+ # @mock_spot = mock("Spot")
63
+ # end
64
+
65
+ # it "should find all" do
66
+ # @mong.all("cities").each { |c| p c["geom"]} #should eql([])
67
+ # end
68
+
69
+ # it "should store something" do
70
+ # @mock_spot.should_receive(:to_hash).and_return({"id" => 7, "name" => "Sao Tome", "geom" => [5,5]})
71
+ # @mong.insert("cities", @mock_spot)
72
+ # @mong.count("cities").should eql(1)
73
+ # end
74
+
75
+ # it "should store a spot" do
76
+ # @mong.insert("cities", mock_spot("Loco"))
77
+ # @mong.find("cities", 1)["name"].should eql("Loco")
78
+ # end
79
+
80
+ # it "should store geom with sinusoidal projection" do
81
+ # @mock_spot.should_receive(:to_hash).and_return({"id" => 8, "name" => "Sao Tome", "geom" => [5,8]})
82
+ # @mong.insert("cities", @mock_spot)
83
+ # @mong.find("cities", 8)["geom"][0].should be_within(0.01).of(4.95)
84
+ # @mong.find("cities", 8)["geom"][1].should eql(8)
85
+ # end
86
+
87
+ # it "should have some indexes" do
88
+ # @mong.index_info("cities").to_a.length.should eql(3)
89
+ # end
90
+
91
+ # describe "Finds" do
92
+
93
+ # before() do
94
+ # @mong.insert("cities", {"id" => 9, "name" => "Sao Paulo", "geom" => [15,15]})
95
+ # @mong.insert("cities", {"id" => 10, "name" => "Sao Tome", "geom" => [-7,-34]})
96
+ # @mong.insert("cities", {"id" => 11, "name" => "Sao Benedito", "geom" => [-9,-39]})
97
+ # end
98
+
99
+ # it "should make sure it's on the collection" do
100
+ # @mong.count("cities").should eql(3)
101
+ # end
102
+
103
+ # it "should find geo" do
104
+ # @mong.find_near("cities", -5, -35).first["name"].should eql("Sao Tome")
105
+ # @mong.find_near("cities", -5, -35).first["geom"][0].should be_within(0.1).of(-5.80,)
106
+ # @mong.find_near("cities", -5, -35).first["geom"][1].should eql(-34)
107
+ # end
108
+
109
+ # it "should find geo limited" do
110
+ # @mong.find_near("cities", -5, -35, 1).length.should eql(1)
111
+ # end
112
+
113
+ # it "should find within box" do
114
+ # @mong.find_within("cities", [[10, 10],[20, 20]]).length.should eql(1)
115
+ # @mong.find_within("cities", [[10, 10],[20, 20]]).first["name"].should eql("Sao Paulo")
116
+ # end
117
+
118
+ # it "should find within tiny radius" do
119
+ # @mong.find_within("cities", [[-6, -36], 2]).length.should eql(0)
120
+ # end
121
+
122
+ # it "should find within radius" do
123
+ # @mong.find_within("cities", [[-6, -36], 3]).length.should eql(1)
124
+ # end
125
+
126
+ # it "should find within wider radius" do
127
+ # @mong.find_within("cities", [[-6, -36], 5]).length.should eql(2)
128
+ # end
129
+
130
+ # it "should find within wider radius limited" do
131
+ # @mong.find_within("cities", [[-6, -36], 5], 1).length.should eql(1)
132
+ # end
133
+
134
+ # it "should find geoNear" do
135
+ # @mong.near("cities", -5, -35).first["dis"].should be_within(0.01).of(1.97)
136
+ # @mong.near("cities", -5, -35).first["obj"]["name"].should eql("Sao Tome")
137
+ # end
138
+
139
+ # it "should find geoNear" do
140
+ # @mong.near("cities", -5, -35).first["dis"].should be_within(0.01).of(1.97)
141
+ # @mong.near("cities", -5, -35).first["obj"]["name"].should eql("Sao Tome")
142
+ # end
143
+
144
+ # it "should find geoNear limited" do
145
+ # @mong.near("cities", -5, -35, 1).length.should eql(1)
146
+ # end
147
+
148
+ # end
149
+
150
+ # end
151
+
152
+ # end
@@ -11,31 +11,31 @@
11
11
  # end
12
12
 
13
13
  # def brasil
14
- # Models::AR::Country.find_or_create_by_name(:name => "Brazil", :abbr => "BR")
14
+ # Models::AR::Nation.find_or_create_by_name(:name => "Brazil", :abbr => "BR")
15
15
  # end
16
16
 
17
- # describe "Country" do
17
+ # describe "Nation" do
18
18
 
19
19
  # it "should create countries" do
20
- # Models::AR::Country.create(:name => "Chad", :abbr => "TD").should be_valid
20
+ # Models::AR::Nation.create(:name => "Chad", :abbr => "TD").should be_valid
21
21
  # end
22
22
 
23
23
  # it "should write to db" do
24
24
  # lambda do
25
- # Models::AR::Country.create(:name => "Itália", :abbr => "IT")
26
- # end.should change(Models::AR::Country, :count).by(1)
25
+ # Models::AR::Nation.create(:name => "Itália", :abbr => "IT")
26
+ # end.should change(Models::AR::Nation, :count).by(1)
27
27
  # end
28
28
 
29
29
  # end
30
30
 
31
- # describe "Province" do
31
+ # describe "Region" do
32
32
 
33
33
  # it "should be a class instance of ar" do
34
- # Models::AR::Province.new.should be_instance_of Models::AR::Province
34
+ # Models::AR::Region.new.should be_instance_of Models::AR::Region
35
35
  # end
36
36
 
37
37
  # it "should create" do
38
- # Models::AR::Province.create(:name => "Chadland", :country => brasil).should be_valid
38
+ # Models::AR::Region.create(:name => "Chadland", :nation => brasil).should be_valid
39
39
  # end
40
40
  # end
41
41
 
@@ -46,7 +46,7 @@
46
46
  # end
47
47
 
48
48
  # it "should create" do
49
- # Models::AR::City.create(:name => "Chadland", :country => brasil).should be_valid
49
+ # Models::AR::City.create(:name => "Chadland", :nation => brasil).should be_valid
50
50
  # end
51
51
  # end
52
52
  # # DatabaseCleaner.clean
@@ -56,8 +56,8 @@
56
56
  # before do
57
57
  # # DatabaseCleaner.clean
58
58
  # @br ||= brasil
59
- # Models::AR::City.create!("name" => "São Tomé", "geom" => [15,15], :country => @br)
60
- # Models::AR::City.create!("name" => "Rock CIty", "geom" => [18,16], :country => @br)
59
+ # Models::AR::City.create!("name" => "São Tomé", "geom" => [15,15], :nation => @br)
60
+ # Models::AR::City.create!("name" => "Rock CIty", "geom" => [18,16], :nation => @br)
61
61
  # end
62
62
 
63
63
  # it "should record" do
@@ -20,9 +20,9 @@ describe "Tokyo" do
20
20
  # end
21
21
 
22
22
  # it "should return all countries" do
23
- # all = Geonames::Country.all
23
+ # all = Geonames::Nation.all
24
24
  # all.should be_instance_of Array
25
- # all[0].should be_instance_of Geonames::Country
25
+ # all[0].should be_instance_of Geonames::Nation
26
26
  # all[0].gid.should eql(1)
27
27
  # end
28
28
 
@@ -43,13 +43,13 @@
43
43
 
44
44
  # create_table :cities, :force => true do |t|
45
45
  # t.references :country, :null => false
46
- # t.references :province
46
+ # t.references :region
47
47
  # t.string :name, :null => false
48
48
  # t.point :geom, :srid => 4326
49
49
  # t.integer :gid, :zip
50
50
  # end
51
51
 
52
- # create_table :provinces, :force => true do |t|
52
+ # create_table :regions, :force => true do |t|
53
53
  # t.references :country, :null => false
54
54
  # t.string :name, :null => false
55
55
  # t.string :abbr, :limit => 3
@@ -65,12 +65,12 @@
65
65
  # add_index :cities, :gid
66
66
  # add_index :cities, :zip
67
67
  # add_index :cities, :country_id
68
- # add_index :cities, :province_id
68
+ # add_index :cities, :region_id
69
69
  # add_index :cities, :geom, :spatial => true
70
- # add_index :provinces, :name
71
- # add_index :provinces, :abbr
72
- # add_index :provinces, :gid
73
- # add_index :provinces, :country_id
70
+ # add_index :regions, :name
71
+ # add_index :regions, :abbr
72
+ # add_index :regions, :gid
73
+ # add_index :regions, :country_id
74
74
  # add_index :countries, :abbr, :unique => true
75
75
  # add_index :countries, :name, :unique => true
76
76
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geonames_local
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcos Piccinini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-05 00:00:00.000000000 Z
11
+ date: 2013-10-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Dumps geonames data to feed a local db
14
14
  email: x@nofxx.com
@@ -19,8 +19,9 @@ extra_rdoc_files:
19
19
  - MIT-LICENSE
20
20
  - README.rdoc
21
21
  files:
22
- - .gitignore
22
+ - ".gitignore"
23
23
  - Gemfile
24
+ - Guardfile
24
25
  - MIT-LICENSE
25
26
  - README.rdoc
26
27
  - Rakefile
@@ -43,9 +44,6 @@ files:
43
44
  - lib/geonames_local/models/postgis.rb
44
45
  - lib/geonames_local/models/tokyo.rb
45
46
  - lib/geonames_local/version.rb
46
- - spec/geonames_local/adapters/mongodb_spec.rb
47
- - spec/geonames_local/adapters/postgis_spec.rb
48
- - spec/geonames_local/adapters/tokyo_spec.rb
49
47
  - spec/geonames_local/cli_spec.rb
50
48
  - spec/geonames_local/data/cache_spec.rb
51
49
  - spec/geonames_local/data/dump_spec.rb
@@ -55,6 +53,7 @@ files:
55
53
  - spec/geonames_local/features/zone_spec.rb
56
54
  - spec/geonames_local/models/mongodb_spec.rb
57
55
  - spec/geonames_local/models/postgis_spec.rb
56
+ - spec/geonames_local/models/tokyo_spec.rb
58
57
  - spec/geonames_local_spec.rb
59
58
  - spec/spec_ar_helper.rb
60
59
  - spec/spec_helper.rb
@@ -81,12 +80,12 @@ require_paths:
81
80
  - lib
82
81
  required_ruby_version: !ruby/object:Gem::Requirement
83
82
  requirements:
84
- - - '>='
83
+ - - ">="
85
84
  - !ruby/object:Gem::Version
86
85
  version: '0'
87
86
  required_rubygems_version: !ruby/object:Gem::Requirement
88
87
  requirements:
89
- - - '>='
88
+ - - ">="
90
89
  - !ruby/object:Gem::Version
91
90
  version: '0'
92
91
  requirements: []
@@ -96,9 +95,6 @@ signing_key:
96
95
  specification_version: 4
97
96
  summary: Dumps geonames data for local usage
98
97
  test_files:
99
- - spec/geonames_local/adapters/mongodb_spec.rb
100
- - spec/geonames_local/adapters/postgis_spec.rb
101
- - spec/geonames_local/adapters/tokyo_spec.rb
102
98
  - spec/geonames_local/cli_spec.rb
103
99
  - spec/geonames_local/data/cache_spec.rb
104
100
  - spec/geonames_local/data/dump_spec.rb
@@ -108,6 +104,7 @@ test_files:
108
104
  - spec/geonames_local/features/zone_spec.rb
109
105
  - spec/geonames_local/models/mongodb_spec.rb
110
106
  - spec/geonames_local/models/postgis_spec.rb
107
+ - spec/geonames_local/models/tokyo_spec.rb
111
108
  - spec/geonames_local_spec.rb
112
109
  - spec/spec_ar_helper.rb
113
110
  - spec/spec_helper.rb
@@ -1,110 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
- require File.expand_path(File.dirname(__FILE__) + '/../../../lib/geonames_local/adapters/mongodb')
3
-
4
- describe "Mongo Models" do
5
-
6
- SPECDB = "geonames_spec"
7
-
8
- before() do
9
- Mongodb.new({:dbname => SPECDB}).purge
10
- @mong = Mongodb.new({:dbname => SPECDB})
11
-
12
- end
13
-
14
- def mock_spot(name)
15
- Spot.new("1\t#{name}\t#{name}\t\t-5.46874226086957\t-35.3565714695652\tA\tADM2\tBR\t22\t2407500\t6593\t\t12\t\t\t\tAmerica/Recife\t2006-12-17", :dump)
16
- end
17
-
18
- describe "Parsing dump" do
19
- before do
20
- @mock_spot = mock("Spot")
21
- end
22
-
23
- it "should find all" do
24
- @mong.all("cities").each { |c| p c["geom"]} #should eql([])
25
- end
26
-
27
- it "should store something" do
28
- @mock_spot.should_receive(:to_hash).and_return({"id" => 7, "name" => "Sao Tome", "geom" => [5,5]})
29
- @mong.insert("cities", @mock_spot)
30
- @mong.count("cities").should eql(1)
31
- end
32
-
33
- it "should store a spot" do
34
- @mong.insert("cities", mock_spot("Loco"))
35
- @mong.find("cities", 1)["name"].should eql("Loco")
36
- end
37
-
38
- it "should store geom with sinusoidal projection" do
39
- @mock_spot.should_receive(:to_hash).and_return({"id" => 8, "name" => "Sao Tome", "geom" => [5,8]})
40
- @mong.insert("cities", @mock_spot)
41
- @mong.find("cities", 8)["geom"][0].should be_within(0.01).of(4.95)
42
- @mong.find("cities", 8)["geom"][1].should eql(8)
43
- end
44
-
45
- it "should have some indexes" do
46
- @mong.index_info("cities").to_a.length.should eql(3)
47
- end
48
-
49
- describe "Finds" do
50
-
51
- before() do
52
- @mong.insert("cities", {"id" => 9, "name" => "Sao Paulo", "geom" => [15,15]})
53
- @mong.insert("cities", {"id" => 10, "name" => "Sao Tome", "geom" => [-7,-34]})
54
- @mong.insert("cities", {"id" => 11, "name" => "Sao Benedito", "geom" => [-9,-39]})
55
- end
56
-
57
- it "should make sure it's on the collection" do
58
- @mong.count("cities").should eql(3)
59
- end
60
-
61
- it "should find geo" do
62
- @mong.find_near("cities", -5, -35).first["name"].should eql("Sao Tome")
63
- @mong.find_near("cities", -5, -35).first["geom"][0].should be_within(0.1).of(-5.80,)
64
- @mong.find_near("cities", -5, -35).first["geom"][1].should eql(-34)
65
- end
66
-
67
- it "should find geo limited" do
68
- @mong.find_near("cities", -5, -35, 1).length.should eql(1)
69
- end
70
-
71
- it "should find within box" do
72
- @mong.find_within("cities", [[10, 10],[20, 20]]).length.should eql(1)
73
- @mong.find_within("cities", [[10, 10],[20, 20]]).first["name"].should eql("Sao Paulo")
74
- end
75
-
76
- it "should find within tiny radius" do
77
- @mong.find_within("cities", [[-6, -36], 2]).length.should eql(0)
78
- end
79
-
80
- it "should find within radius" do
81
- @mong.find_within("cities", [[-6, -36], 3]).length.should eql(1)
82
- end
83
-
84
- it "should find within wider radius" do
85
- @mong.find_within("cities", [[-6, -36], 5]).length.should eql(2)
86
- end
87
-
88
- it "should find within wider radius limited" do
89
- @mong.find_within("cities", [[-6, -36], 5], 1).length.should eql(1)
90
- end
91
-
92
- it "should find geoNear" do
93
- @mong.near("cities", -5, -35).first["dis"].should be_within(0.01).of(1.97)
94
- @mong.near("cities", -5, -35).first["obj"]["name"].should eql("Sao Tome")
95
- end
96
-
97
- it "should find geoNear" do
98
- @mong.near("cities", -5, -35).first["dis"].should be_within(0.01).of(1.97)
99
- @mong.near("cities", -5, -35).first["obj"]["name"].should eql("Sao Tome")
100
- end
101
-
102
- it "should find geoNear limited" do
103
- @mong.near("cities", -5, -35, 1).length.should eql(1)
104
- end
105
-
106
- end
107
-
108
- end
109
-
110
- end
@@ -1,12 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
- require File.expand_path(File.dirname(__FILE__) + '/../../../lib/geonames_local/adapters/postgis')
3
-
4
- describe Postgis do
5
-
6
- def wipe_db
7
- end
8
-
9
- describe "Parsing Dump" do
10
- # before(:all)
11
- end
12
- end