geonames_local 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +26 -11
- data/Rakefile +5 -12
- data/VERSION +1 -1
- data/bin/geonames +1 -1
- data/geonames.yml +3 -2
- data/geonames_local.gemspec +65 -68
- data/lib/geonames_ar.rb +2 -4
- data/lib/geonames_cli.rb +2 -1
- data/lib/geonames_local/adapters/mongodb.rb +2 -1
- data/lib/geonames_local/adapters/postgres.rb +28 -13
- data/lib/geonames_local/cli.rb +6 -56
- data/lib/geonames_local/data/dump.rb +4 -4
- data/lib/geonames_local/data/sync.rb +74 -0
- data/lib/geonames_local/features/spot.rb +9 -4
- data/lib/geonames_local/models/ar.rb +50 -0
- data/lib/geonames_local/{model/country.rb → models/mongo.rb} +27 -26
- data/lib/geonames_local/{mongo/country.rb → models/tokyo.rb} +23 -1
- data/lib/geonames_local.rb +1 -3
- data/spec/geonames_local/adapters/mongodb_spec.rb +14 -9
- data/spec/geonames_local/cli_spec.rb +5 -0
- data/spec/geonames_local/data/dump_spec.rb +4 -0
- data/spec/geonames_local/features/spot_spec.rb +146 -66
- data/spec/geonames_local/models/ar_spec.rb +73 -0
- data/spec/geonames_local/{mongo/city_spec.rb → models/mongo_spec.rb} +7 -8
- data/spec/spec_ar_helper.rb +78 -37
- data/spec/spec_helper.rb +4 -3
- data/spec/spec_mongo_helper.rb +3 -2
- metadata +24 -26
- data/.gitignore +0 -28
- data/lib/geonames_local/model/city.rb +0 -26
- data/lib/geonames_local/model/province.rb +0 -18
- data/lib/geonames_local/mongo/city.rb +0 -7
- data/lib/geonames_local/mongo/province.rb +0 -18
- data/spec/geonames_local/model/ar_spec.rb +0 -19
- data/spec/spec.opts +0 -1
@@ -3,6 +3,10 @@ module Geonames
|
|
3
3
|
URL = "http://download.geonames.org/export/"
|
4
4
|
TMP = "/tmp/geonames/"
|
5
5
|
|
6
|
+
def self.work(codes=:all, kind=:dump)
|
7
|
+
new(codes, kind)
|
8
|
+
end
|
9
|
+
|
6
10
|
def initialize(codes, kind)
|
7
11
|
@codes = codes
|
8
12
|
@kind = kind
|
@@ -67,10 +71,6 @@ module Geonames
|
|
67
71
|
end
|
68
72
|
|
69
73
|
|
70
|
-
def self.work(codes=:all, kind=:dump)
|
71
|
-
new(codes, kind)
|
72
|
-
end
|
73
|
-
|
74
74
|
end
|
75
75
|
|
76
76
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Geonames
|
2
|
+
class Sync
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def work!
|
6
|
+
unify!
|
7
|
+
write_to_store!
|
8
|
+
end
|
9
|
+
|
10
|
+
def load_adapter(name)
|
11
|
+
begin
|
12
|
+
require "geonames_local/adapters/#{name}"
|
13
|
+
Geonames.class_eval(name.capitalize).new(Opt[:db])
|
14
|
+
rescue LoadError
|
15
|
+
puts "Can't find adapter #{name}"
|
16
|
+
stop!
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def write_to_store!
|
21
|
+
groups = Cache[:dump].group_by(&:kind)
|
22
|
+
Cache[:provinces] = groups[:province]
|
23
|
+
# ensure this order....
|
24
|
+
do_write(groups[:province])
|
25
|
+
do_write(groups[:city])
|
26
|
+
end
|
27
|
+
|
28
|
+
def do_write(values)
|
29
|
+
return if values.empty?
|
30
|
+
db = load_adapter(Opt[:store])
|
31
|
+
key = values[0].table
|
32
|
+
start = Time.now
|
33
|
+
writt = 0
|
34
|
+
min_pop = Opt[:min_pop]
|
35
|
+
info "\nWriting #{values.length} #{key}..."
|
36
|
+
info "\nWriting spots with pop > #{Opt[:min_pop]} hab." if min_pop
|
37
|
+
values.each do |val|
|
38
|
+
if min_pop
|
39
|
+
next unless val.pop && val.pop.to_i >= min_pop
|
40
|
+
end
|
41
|
+
arg = val.respond_to?(:gid) ? [val.gid] : [val.name, true]
|
42
|
+
unless db.find(val.table, *arg)
|
43
|
+
db.insert(val.table, val)
|
44
|
+
writt += 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
total = Time.now - start
|
48
|
+
info "#{writt} #{key} written in #{total} sec (#{(writt/total).to_i}/s)"
|
49
|
+
end
|
50
|
+
|
51
|
+
def unify!
|
52
|
+
info "Join dump << zip"
|
53
|
+
start = Time.now
|
54
|
+
Cache[:dump].map! do |spot|
|
55
|
+
if other = Cache[:zip].find { |d| d.code == spot.code }
|
56
|
+
spot.zip = other.zip
|
57
|
+
spot
|
58
|
+
else
|
59
|
+
spot
|
60
|
+
end
|
61
|
+
end
|
62
|
+
info "Done. #{(Time.now-start).to_i}s"
|
63
|
+
end
|
64
|
+
|
65
|
+
def stop!
|
66
|
+
puts "Closing Geonames..."
|
67
|
+
exit
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -35,9 +35,8 @@ module Geonames
|
|
35
35
|
# Parse Geonames Dump Export
|
36
36
|
def parse(row)
|
37
37
|
gid, @name, @ascii, @alternates, lat, lon, feat, kind,
|
38
|
-
@country, cc2, adm1, adm2, adm3, adm4, pop, ele,
|
39
|
-
gtop, @tz, @up = row.split(/\t/)
|
40
|
-
|
38
|
+
@country, cc2, adm1, adm2, adm3, adm4, @pop, @ele,
|
39
|
+
@gtop, @tz, @up = row.split(/\t/)
|
41
40
|
parse_geom(lat, lon)
|
42
41
|
@gid = @geoname_id = gid.to_i
|
43
42
|
@kind = human_code(kind)
|
@@ -51,7 +50,7 @@ module Geonames
|
|
51
50
|
country, zip, @name, province, cc, dunno, adm1, adm2, lat, lon = row.split(/\t/)
|
52
51
|
parse_geom(lat, lon)
|
53
52
|
@code = adm1
|
54
|
-
@kind = :
|
53
|
+
@kind = :city
|
55
54
|
@zip = zip.split("-")[0]
|
56
55
|
end
|
57
56
|
|
@@ -62,9 +61,15 @@ module Geonames
|
|
62
61
|
|
63
62
|
if defined?("GeoRuby")
|
64
63
|
@geom = GeoRuby::SimpleFeatures::Point.from_x_y(@lon, @lat)
|
64
|
+
else
|
65
|
+
{ :lat => @lat, :lon => @lon }
|
65
66
|
end
|
66
67
|
end
|
67
68
|
|
69
|
+
def alt
|
70
|
+
@ele || @gtop
|
71
|
+
end
|
72
|
+
|
68
73
|
#
|
69
74
|
# Parse Time
|
70
75
|
def updated_at
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Geonames
|
2
|
+
module Models
|
3
|
+
module AR
|
4
|
+
|
5
|
+
class City < ActiveRecord::Base
|
6
|
+
attr_accessor :x, :y, :z
|
7
|
+
|
8
|
+
belongs_to :province
|
9
|
+
belongs_to :country
|
10
|
+
|
11
|
+
validates_presence_of :country
|
12
|
+
validates_presence_of :name
|
13
|
+
|
14
|
+
def abbr
|
15
|
+
province.try(:abbr) || country.abbr
|
16
|
+
end
|
17
|
+
|
18
|
+
def geom=(val)
|
19
|
+
self[:geom] = case val
|
20
|
+
when Array then Point.xy(*val)
|
21
|
+
else val
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Instantiate self.geom as a Point
|
26
|
+
def validation
|
27
|
+
self.country ||= province.country
|
28
|
+
unless !@x || !@y || @x == "" || @y == ""
|
29
|
+
self.geom = Point.from_x_y(@x.to_f, @y.to_f)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
class Province < ActiveRecord::Base
|
36
|
+
has_many :cities
|
37
|
+
belongs_to :country
|
38
|
+
end
|
39
|
+
|
40
|
+
class Country < ActiveRecord::Base
|
41
|
+
attr_accessor :code, :gid, :iso, :capital, :pop
|
42
|
+
has_many :provinces
|
43
|
+
has_many :cities
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
@@ -1,33 +1,15 @@
|
|
1
1
|
module Geonames
|
2
|
-
|
3
|
-
|
2
|
+
module Models
|
3
|
+
module Mongo
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
new(c)
|
5
|
+
class City < Geonames::Spot
|
6
|
+
set_coll "cities"
|
8
7
|
end
|
9
|
-
end
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
# [4] name
|
16
|
-
# [5] capital
|
17
|
-
# [6] areaInSqKm
|
18
|
-
# [7] population
|
19
|
-
# [8] continent
|
20
|
-
# [9] top level domain
|
21
|
-
# [10] Currency code
|
22
|
-
# [11] Currency name
|
23
|
-
# [12] Phone
|
24
|
-
# [13] Postal Code Format
|
25
|
-
# [14] Postal Code Regex
|
26
|
-
# [15] Languages
|
27
|
-
# [16] Geoname id
|
28
|
-
# [17] Neighbours
|
29
|
-
# [18] Equivalent Fips Code
|
30
|
-
#
|
9
|
+
class Country < Geonames::Spot
|
10
|
+
attr_accessor :code, :name, :gid, :iso, :capital, :pop
|
11
|
+
set_coll "countries"
|
12
|
+
|
31
13
|
def self.parse(row)
|
32
14
|
new(row)
|
33
15
|
end
|
@@ -57,5 +39,24 @@ module Geonames
|
|
57
39
|
def export_header
|
58
40
|
["gid", "code", "name"]
|
59
41
|
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class Province
|
45
|
+
attr_accessor :code, :name, :gid
|
46
|
+
|
47
|
+
def self.all
|
48
|
+
Tokyo.new.all({ :kind => "province" }).map do |c|
|
49
|
+
new(c)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def initialize(params)
|
54
|
+
@code = params["code"]
|
55
|
+
@name = params["name"]
|
56
|
+
@gid = params["gid"]
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
60
61
|
end
|
61
62
|
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
module Geonames
|
2
|
-
|
2
|
+
module Models
|
3
|
+
module Tokyo
|
4
|
+
|
5
|
+
class Country
|
3
6
|
attr_accessor :code, :name, :gid, :iso, :capital, :pop
|
4
7
|
|
5
8
|
def self.all
|
@@ -57,5 +60,24 @@ module Geonames
|
|
57
60
|
def export_header
|
58
61
|
["gid", "code", "name"]
|
59
62
|
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
class Province
|
67
|
+
attr_accessor :code, :name, :gid
|
68
|
+
|
69
|
+
def self.all
|
70
|
+
Tokyo.new.all({ :kind => "province" }).map do |c|
|
71
|
+
new(c)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def initialize(params)
|
76
|
+
@code = params["code"]
|
77
|
+
@name = params["name"]
|
78
|
+
@gid = params["gid"]
|
79
|
+
end
|
80
|
+
|
60
81
|
end
|
82
|
+
|
61
83
|
end
|
data/lib/geonames_local.rb
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/../../../lib/geonames_local/adapters/mongodb')
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe "Mongo Models" do
|
5
5
|
|
6
6
|
SPECDB = "geonames_spec"
|
7
7
|
|
8
|
-
before(
|
8
|
+
before() do
|
9
9
|
Mongodb.new({:dbname => SPECDB}).purge
|
10
10
|
@mong = Mongodb.new({:dbname => SPECDB})
|
11
|
+
|
11
12
|
end
|
12
13
|
|
13
14
|
def mock_spot(name)
|
14
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)
|
15
16
|
end
|
16
17
|
|
17
|
-
describe "Parsing
|
18
|
+
describe "Parsing dump" do
|
18
19
|
before do
|
19
20
|
@mock_spot = mock("Spot")
|
20
21
|
end
|
@@ -37,7 +38,7 @@ describe Mongodb do
|
|
37
38
|
it "should store geom with sinusoidal projection" do
|
38
39
|
@mock_spot.should_receive(:to_hash).and_return({"id" => 8, "name" => "Sao Tome", "geom" => [5,8]})
|
39
40
|
@mong.insert("cities", @mock_spot)
|
40
|
-
@mong.find("cities", 8)["geom"][0].should
|
41
|
+
@mong.find("cities", 8)["geom"][0].should be_within(0.01).of(4.95)
|
41
42
|
@mong.find("cities", 8)["geom"][1].should eql(8)
|
42
43
|
end
|
43
44
|
|
@@ -47,7 +48,7 @@ describe Mongodb do
|
|
47
48
|
|
48
49
|
describe "Finds" do
|
49
50
|
|
50
|
-
before(
|
51
|
+
before() do
|
51
52
|
@mong.insert("cities", {"id" => 9, "name" => "Sao Paulo", "geom" => [15,15]})
|
52
53
|
@mong.insert("cities", {"id" => 10, "name" => "Sao Tome", "geom" => [-7,-34]})
|
53
54
|
@mong.insert("cities", {"id" => 11, "name" => "Sao Benedito", "geom" => [-9,-39]})
|
@@ -59,7 +60,7 @@ describe Mongodb do
|
|
59
60
|
|
60
61
|
it "should find geo" do
|
61
62
|
@mong.find_near("cities", -5, -35).first["name"].should eql("Sao Tome")
|
62
|
-
@mong.find_near("cities", -5, -35).first["geom"][0].should
|
63
|
+
@mong.find_near("cities", -5, -35).first["geom"][0].should be_within(0.1).of(-5.80,)
|
63
64
|
@mong.find_near("cities", -5, -35).first["geom"][1].should eql(-34)
|
64
65
|
end
|
65
66
|
|
@@ -72,8 +73,12 @@ describe Mongodb do
|
|
72
73
|
@mong.find_within("cities", [[10, 10],[20, 20]]).first["name"].should eql("Sao Paulo")
|
73
74
|
end
|
74
75
|
|
76
|
+
it "should find within tiny radius" do
|
77
|
+
@mong.find_within("cities", [[-6, -36], 2]).length.should eql(0)
|
78
|
+
end
|
79
|
+
|
75
80
|
it "should find within radius" do
|
76
|
-
@mong.find_within("cities", [[-6, -36],
|
81
|
+
@mong.find_within("cities", [[-6, -36], 3]).length.should eql(1)
|
77
82
|
end
|
78
83
|
|
79
84
|
it "should find within wider radius" do
|
@@ -85,12 +90,12 @@ describe Mongodb do
|
|
85
90
|
end
|
86
91
|
|
87
92
|
it "should find geoNear" do
|
88
|
-
@mong.near("cities", -5, -35).first["dis"].should
|
93
|
+
@mong.near("cities", -5, -35).first["dis"].should be_within(0.01).of(1.97)
|
89
94
|
@mong.near("cities", -5, -35).first["obj"]["name"].should eql("Sao Tome")
|
90
95
|
end
|
91
96
|
|
92
97
|
it "should find geoNear" do
|
93
|
-
@mong.near("cities", -5, -35).first["dis"].should
|
98
|
+
@mong.near("cities", -5, -35).first["dis"].should be_within(0.01).of(1.97)
|
94
99
|
@mong.near("cities", -5, -35).first["obj"]["name"].should eql("Sao Tome")
|
95
100
|
end
|
96
101
|
|
@@ -6,192 +6,272 @@ describe Spot do
|
|
6
6
|
|
7
7
|
describe "Parsing Dump" do
|
8
8
|
|
9
|
-
|
10
|
-
@spot = Spot.new("6319037\tMaxaranguape\tMaxaranguape\t\t-5.46874226086957\t-35.3565714695652\tA\tADM2\tBR\t22\t2407500\t6593\t\t12\t\t\t\tAmerica/Recife\t2006-12-17", :dump)
|
11
|
-
end
|
9
|
+
let(:spot) { Spot.new("6319037\tMaxaranguape\tMaxaranguape\t\t-5.46874226086957\t-35.3565714695652\tA\tADM2\tBR\t22\t2407500\t6593\t\t12\t\t\t\tAmerica/Recife\t2006-12-17", :dump) }
|
12
10
|
|
13
11
|
it "should parse geoid integer" do
|
14
|
-
|
15
|
-
|
12
|
+
spot.geoname_id.should eql(6319037)
|
13
|
+
spot.gid.should eql(6319037)
|
16
14
|
end
|
17
15
|
|
18
16
|
it "should parse code" do
|
19
|
-
|
17
|
+
spot.code.should eql("6593")
|
20
18
|
end
|
21
19
|
|
22
20
|
it "should parse province code" do
|
23
|
-
|
21
|
+
spot.province.should eql("2407500")
|
24
22
|
end
|
25
23
|
|
26
24
|
it "should parse name" do
|
27
|
-
|
28
|
-
|
25
|
+
spot.name.should eql("Maxaranguape")
|
26
|
+
spot.ascii.should eql("Maxaranguape")
|
29
27
|
end
|
30
28
|
|
31
29
|
it "should parse geostuff" do
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
spot.lat.should be_within(0.001).of(-5.4687)
|
31
|
+
spot.y.should be_within(0.001).of(-5.4687)
|
32
|
+
spot.lon.should be_within(0.001).of(-35.3565)
|
35
33
|
end
|
36
34
|
|
37
35
|
it "should parse spot kind" do
|
38
|
-
|
36
|
+
spot.kind.should eql(:city)
|
39
37
|
end
|
40
38
|
|
41
39
|
it "should parse spot country" do
|
42
|
-
|
40
|
+
spot.country.should eql("BR")
|
43
41
|
end
|
44
42
|
|
45
43
|
it "shuold parse timezone" do
|
46
|
-
|
44
|
+
spot.tz.should eql("America/Recife")
|
47
45
|
end
|
48
46
|
|
49
47
|
it "should parse updated_at" do
|
50
|
-
|
51
|
-
|
48
|
+
spot.updated_at.should be_instance_of(Time)
|
49
|
+
spot.updated_at.day.should eql(17)
|
52
50
|
end
|
53
51
|
end
|
54
52
|
|
55
|
-
describe "More
|
53
|
+
describe "More Parsing" do
|
56
54
|
|
57
|
-
|
58
|
-
@spot = Geonames::Spot.new("3384862\tRiacho Zuza\tRiacho Zuza\t\t-9.4333333\t-37.6666667\tH\tSTMI\tBR\t\t02\t\t\t\t0\t\t241\tAmerica/Maceio\t1993-12-17\n", :dump)
|
59
|
-
end
|
55
|
+
let(:spot) { Geonames::Spot.new("3384862\tRiacho Zuza\tRiacho Zuza\t\t-9.4333333\t-37.6666667\tH\tSTMI\tBR\t\t02\t\t\t\t0\t\t241\tAmerica/Maceio\t1993-12-17\n", :dump) }
|
60
56
|
|
61
57
|
it "should parse geoid integer" do
|
62
|
-
|
58
|
+
spot.geoname_id.should eql(3384862)
|
63
59
|
end
|
64
60
|
|
65
61
|
it "should parse name" do
|
66
|
-
|
67
|
-
|
62
|
+
spot.name.should eql("Riacho Zuza")
|
63
|
+
spot.ascii.should eql("Riacho Zuza")
|
68
64
|
end
|
69
65
|
|
70
66
|
it "should parse geostuff" do
|
71
|
-
|
72
|
-
|
67
|
+
spot.lat.should be_within(0.001).of(-9.4333333)
|
68
|
+
spot.lon.should be_within(0.001).of(-37.6666667)
|
73
69
|
end
|
74
70
|
|
75
71
|
it "should parse spot kind" do
|
76
|
-
|
72
|
+
spot.kind.should eql(:other)
|
77
73
|
end
|
78
74
|
|
79
75
|
it "should parse spot country" do
|
80
|
-
|
76
|
+
spot.country.should eql("BR")
|
81
77
|
end
|
82
78
|
|
83
79
|
it "shuold parse timezone" do
|
84
|
-
|
80
|
+
spot.tz.should eql("America/Maceio")
|
85
81
|
end
|
86
82
|
|
87
83
|
it "should parse updated_at" do
|
88
|
-
|
89
|
-
|
84
|
+
spot.updated_at.should be_instance_of(Time)
|
85
|
+
spot.updated_at.day.should eql(17)
|
90
86
|
end
|
91
87
|
end
|
92
88
|
|
93
89
|
describe "Parsing Province" do
|
94
90
|
|
95
|
-
|
96
|
-
@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)
|
97
|
-
end
|
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) }
|
98
92
|
|
99
93
|
it "should be kind of province" do
|
100
|
-
|
94
|
+
spot.kind.should eql(:province)
|
101
95
|
end
|
102
96
|
|
103
97
|
it "should parse geoid" do
|
104
|
-
|
105
|
-
|
98
|
+
spot.geoname_id.should eql(3457153)
|
99
|
+
spot.gid.should eql(3457153)
|
106
100
|
end
|
107
101
|
|
108
102
|
it "should parse code" do
|
109
|
-
|
103
|
+
spot.code.should be_empty
|
110
104
|
end
|
111
105
|
|
112
106
|
it "should parse province code" do
|
113
|
-
|
107
|
+
spot.province.should eql("15")
|
114
108
|
end
|
115
109
|
|
116
110
|
it "should create abbr" do
|
117
|
-
|
111
|
+
spot.abbr.should eql("MG")
|
118
112
|
end
|
119
113
|
|
120
114
|
it "should parse name" do
|
121
|
-
|
122
|
-
|
115
|
+
spot.name.should eql("Minas Gerais")
|
116
|
+
spot.ascii.should eql("Estado de Minas Gerais")
|
123
117
|
end
|
124
118
|
|
125
119
|
it "should parse geostuff" do
|
126
|
-
|
127
|
-
|
120
|
+
spot.lat.should be_within(0.001).of(-18.0)
|
121
|
+
spot.lon.should be_within(0.001).of(-44.0)
|
128
122
|
end
|
129
123
|
|
130
124
|
end
|
131
125
|
|
132
|
-
describe "Parsing
|
126
|
+
describe "Parsing City" do
|
127
|
+
|
128
|
+
let(:spot) { Spot.new "3386859\tTamboril\tTamboril\t\t-4.9931\t-40.26738\tA\tADM2\tBR\t\t06\t2313203\t\t\t25455\t\t401\tAmerica/Fortaleza\t2011-04-21" }
|
129
|
+
|
130
|
+
it "should parse name" do
|
131
|
+
spot.name.should eql("Tamboril")
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should parse ascii name" do
|
135
|
+
spot.name.should eql("Tamboril")
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should parse x" do
|
139
|
+
spot.x.should be_within(0.001).of(-40.26738)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should parse y" do
|
143
|
+
spot.y.should be_within(0.001).of(-4.9931)
|
144
|
+
end
|
133
145
|
|
134
|
-
|
135
|
-
|
146
|
+
it "should parse tz" do
|
147
|
+
spot.tz.should eql("America/Fortaleza")
|
136
148
|
end
|
137
149
|
|
150
|
+
it "should parse kind" do
|
151
|
+
spot.kind.should eql(:city)
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should parse country" do
|
155
|
+
spot.country.should eql("BR")
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should parse province" do
|
159
|
+
pending
|
160
|
+
spot.province.should eql("C")
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should parse pop" do
|
164
|
+
spot.pop.should eql("25455")
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
describe "Parsing Big City" do
|
170
|
+
|
171
|
+
let(:spot) { Spot.new "6322846\tLondrina\tLondrina\t\t-23.58643\t-51.08739\tA\tADM2\tBR\t\t18\t4113700\t\t\t506645\t\t544\tAmerica/Sao_Paulo\t2011-04-21" }
|
172
|
+
|
173
|
+
it "should parse name" do
|
174
|
+
spot.name.should eql("Londrina")
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should parse ascii name" do
|
178
|
+
spot.name.should eql("Londrina")
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should parse x" do
|
182
|
+
spot.x.should be_within(0.001).of(-51.08739)
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should parse y" do
|
186
|
+
spot.y.should be_within(0.001).of(-23.58643)
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should parse tz" do
|
190
|
+
spot.tz.should eql("America/Sao_Paulo")
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should parse kind" do
|
194
|
+
spot.kind.should eql(:city)
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should parse country" do
|
198
|
+
spot.country.should eql("BR")
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should parse province" do
|
202
|
+
pending
|
203
|
+
spot.province.should eql("C")
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should parse pop" do
|
207
|
+
spot.pop.should eql("506645")
|
208
|
+
end
|
209
|
+
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
describe "Parsing Zip" do
|
214
|
+
|
215
|
+
let(:spot) { Geonames::Spot.new("BR\t76375-000\tHidrolina\tGoias\t29\t\t5209804\t\t-14.7574\t-49.3596\t\n", :zip) }
|
216
|
+
|
138
217
|
it "should parse zip oO" do
|
139
|
-
|
218
|
+
spot.zip.should eql("76375")
|
140
219
|
end
|
141
220
|
|
142
221
|
it "should be a city" do
|
143
|
-
|
222
|
+
spot.kind.should eql(:city)
|
144
223
|
end
|
145
224
|
|
146
225
|
it "should parse code" do
|
147
|
-
|
226
|
+
spot.code.should eql("5209804")
|
148
227
|
end
|
149
228
|
|
150
229
|
it "should parse geoid integer" do
|
151
|
-
|
230
|
+
spot.gid.should be_nil # eql(3384862)
|
152
231
|
end
|
153
232
|
|
154
233
|
it "should parse name" do
|
155
|
-
|
156
|
-
|
234
|
+
spot.name.should eql("Hidrolina")
|
235
|
+
spot.ascii.should be_nil # eql("Hidrolina")
|
157
236
|
end
|
158
237
|
|
159
|
-
it "should parse
|
160
|
-
|
161
|
-
|
238
|
+
it "should parse lat" do
|
239
|
+
spot.lat.should be_within(0.001).of(-14.7574)
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should parse lon" do
|
243
|
+
spot.lon.should be_within(0.001).of(-49.3596)
|
162
244
|
end
|
163
245
|
|
164
246
|
end
|
165
247
|
|
166
248
|
describe "From Hash" do
|
167
249
|
|
168
|
-
|
169
|
-
@spot = Spot.from_hash({"id" => 9, "name" => "Sao Rock", "geom" => [15,15], "kind" => "cities", "country" => "BR", "gid" => 13232, "tz" => "America/Foo", "ascii" => "Rock"})
|
170
|
-
end
|
250
|
+
let(:spot) { Spot.from_hash({"id" => 9, "name" => "Sao Rock", "geom" => [15,15], "kind" => "cities", "country" => "BR", "gid" => 13232, "tz" => "America/Foo", "ascii" => "Rock"}) }
|
171
251
|
|
172
252
|
it "should be an spot" do
|
173
|
-
|
253
|
+
spot.should be_instance_of Spot
|
174
254
|
end
|
175
255
|
|
176
256
|
it "should set the name" do
|
177
|
-
|
257
|
+
spot.name.should eql("Sao Rock")
|
178
258
|
end
|
179
259
|
|
180
260
|
it "should set the geom" do
|
181
|
-
|
182
|
-
|
261
|
+
spot.geom.should be_instance_of(GeoRuby::SimpleFeatures::Point)
|
262
|
+
spot.geom.x.should eql(15)
|
183
263
|
end
|
184
264
|
|
185
265
|
it "should set the tz" do
|
186
|
-
|
266
|
+
spot.tz.should eql("America/Foo")
|
187
267
|
end
|
188
268
|
|
189
269
|
it "should set the ascii" do
|
190
|
-
|
270
|
+
spot.ascii.should eql("Rock")
|
191
271
|
end
|
192
272
|
|
193
273
|
it "should set the country abbr" do
|
194
|
-
|
274
|
+
spot.country.should eql("BR")
|
195
275
|
end
|
196
276
|
|
197
277
|
end
|