geonames_local 0.0.3 → 0.0.4
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/.gitignore +2 -1
- data/VERSION +1 -1
- data/geonames.yml +14 -0
- data/geonames_local.gemspec +96 -0
- data/lib/config/geonames.yml +1 -1
- data/lib/data/cache.rb +5 -0
- data/lib/data/postgres.rb +34 -10
- data/lib/data/shp.rb +76 -0
- data/lib/features/road.rb +40 -1
- data/lib/features/spot.rb +2 -1
- data/lib/features/zone.rb +24 -0
- data/lib/geonames_local.rb +4 -1
- data/lib/work/cli.rb +19 -4
- data/spec/data/cache_spec.rb +4 -0
- data/spec/data/postgres_spec.rb +11 -0
- data/spec/data/shp_spec.rb +20 -0
- data/spec/data/tokyo_spec.rb +20 -20
- data/spec/features/road_spec.rb +68 -0
- data/spec/features/spot_spec.rb +191 -0
- data/spec/features/zone_spec.rb +62 -0
- data/spec/geonames_local_spec.rb +3 -80
- data/spec/spec_helper.rb +2 -1
- data/spec/work/cli_spec.rb +8 -0
- metadata +21 -2
data/.gitignore
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/geonames.yml
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{geonames_local}
|
8
|
+
s.version = "0.0.4"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Marcos Piccinini"]
|
12
|
+
s.date = %q{2010-01-29}
|
13
|
+
s.default_executable = %q{geonames}
|
14
|
+
s.description = %q{Dump and feed a tokyo cabinet for local geonames search}
|
15
|
+
s.email = %q{x@nofxx.com}
|
16
|
+
s.executables = ["geonames"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".gitignore",
|
24
|
+
"LICENSE",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/geonames",
|
29
|
+
"geonames.yml",
|
30
|
+
"geonames_local.gemspec",
|
31
|
+
"lib/config/codes.yml",
|
32
|
+
"lib/config/geonames.yml",
|
33
|
+
"lib/data/cache.rb",
|
34
|
+
"lib/data/geoquery.rb",
|
35
|
+
"lib/data/postgres.rb",
|
36
|
+
"lib/data/shp.rb",
|
37
|
+
"lib/data/tokyo.rb",
|
38
|
+
"lib/features/city.rb",
|
39
|
+
"lib/features/country.rb",
|
40
|
+
"lib/features/province.rb",
|
41
|
+
"lib/features/road.rb",
|
42
|
+
"lib/features/spot.rb",
|
43
|
+
"lib/features/zone.rb",
|
44
|
+
"lib/geonames_local.rb",
|
45
|
+
"lib/work/cli.rb",
|
46
|
+
"lib/work/dump.rb",
|
47
|
+
"lib/work/export.rb",
|
48
|
+
"spec/data/cache_spec.rb",
|
49
|
+
"spec/data/postgres_spec.rb",
|
50
|
+
"spec/data/shp_spec.rb",
|
51
|
+
"spec/data/tokyo_spec.rb",
|
52
|
+
"spec/features/road_spec.rb",
|
53
|
+
"spec/features/spot_spec.rb",
|
54
|
+
"spec/features/zone_spec.rb",
|
55
|
+
"spec/geonames_local_spec.rb",
|
56
|
+
"spec/spec.opts",
|
57
|
+
"spec/spec_helper.rb",
|
58
|
+
"spec/work/cli_spec.rb",
|
59
|
+
"task/benchmark.rb",
|
60
|
+
"task/benchmark_cabinet.rb"
|
61
|
+
]
|
62
|
+
s.homepage = %q{http://github.com/nofxx/geonames_local}
|
63
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
64
|
+
s.require_paths = ["lib"]
|
65
|
+
s.rubygems_version = %q{1.3.5}
|
66
|
+
s.summary = %q{Dump and feed a tokyo local geonames db}
|
67
|
+
s.test_files = [
|
68
|
+
"spec/data/cache_spec.rb",
|
69
|
+
"spec/data/postgres_spec.rb",
|
70
|
+
"spec/data/shp_spec.rb",
|
71
|
+
"spec/data/tokyo_spec.rb",
|
72
|
+
"spec/features/road_spec.rb",
|
73
|
+
"spec/features/spot_spec.rb",
|
74
|
+
"spec/features/zone_spec.rb",
|
75
|
+
"spec/geonames_local_spec.rb",
|
76
|
+
"spec/spec_helper.rb",
|
77
|
+
"spec/work/cli_spec.rb"
|
78
|
+
]
|
79
|
+
|
80
|
+
if s.respond_to? :specification_version then
|
81
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
82
|
+
s.specification_version = 3
|
83
|
+
|
84
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
85
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
86
|
+
s.add_runtime_dependency(%q<tokyotyrant>, [">= 1.10"])
|
87
|
+
else
|
88
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
89
|
+
s.add_dependency(%q<tokyotyrant>, [">= 1.10"])
|
90
|
+
end
|
91
|
+
else
|
92
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
93
|
+
s.add_dependency(%q<tokyotyrant>, [">= 1.10"])
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
data/lib/config/geonames.yml
CHANGED
data/lib/data/cache.rb
ADDED
data/lib/data/postgres.rb
CHANGED
@@ -16,35 +16,54 @@ module Geonames
|
|
16
16
|
@conn.exec("SELECT countries.id FROM countries WHERE UPPER(countries.abbr) = UPPER('#{some.country}')")[0]["id"] rescue nil
|
17
17
|
c ||= write("countries", {:name => Codes[some.country.downcase.to_sym][:pt_br], :abbr => some.country })
|
18
18
|
|
19
|
-
p =
|
19
|
+
p = nil
|
20
|
+
ci = nil
|
21
|
+
if some.kind_of? Spot
|
22
|
+
p = Provinces[some.province] ||= find("provinces", Cache[:provinces].
|
20
23
|
find{ |p| p.province == some.province}.gid)
|
21
|
-
|
24
|
+
else
|
25
|
+
ci = find("cities", some.city)
|
26
|
+
p = @conn.exec("SELECT cities.province_id FROM cities WHERE cities.id = #{ci}")[0]["province_id"] rescue nil
|
27
|
+
end
|
28
|
+
[c, p, ci]
|
22
29
|
end
|
23
30
|
|
24
31
|
#
|
25
32
|
# Insert a record
|
26
33
|
def insert(some)
|
27
|
-
country_id, province_id = get_some_ids(some)
|
28
|
-
|
34
|
+
country_id, province_id, city_id = get_some_ids(some)
|
35
|
+
case some.table
|
36
|
+
when :cities
|
29
37
|
write("cities", {:name => some.name, :country_id => country_id,
|
30
38
|
:geom => some.geom.as_hex_ewkb, :gid => some.gid,
|
31
39
|
:zip => some.zip, :province_id => province_id})
|
32
|
-
|
40
|
+
when :provinces
|
33
41
|
write("provinces", { :name => some.name, :abbr => some.abbr,
|
34
42
|
:country_id => country_id, :gid => some.gid })
|
43
|
+
when :roads
|
44
|
+
write("roads", { :name => some.name, :geom => some.geom.as_hex_ewkb, :kind => some.kind,
|
45
|
+
:country_id => country_id, :city_id => city_id, :province_id => province_id })
|
35
46
|
end
|
36
47
|
end
|
37
48
|
|
38
49
|
#
|
39
50
|
# Find a record`s ID
|
40
|
-
def find(
|
41
|
-
|
51
|
+
def find(table, id, name=nil)
|
52
|
+
begin
|
53
|
+
if name
|
54
|
+
@conn.exec("SELECT #{table}.id FROM #{table} WHERE (#{table}.name = E'#{id}')")[0]["id"]
|
55
|
+
else
|
56
|
+
@conn.exec("SELECT #{table}.id FROM #{table} WHERE #{table}.gid = #{id}")[0]["id"]
|
57
|
+
end
|
58
|
+
rescue => e
|
59
|
+
nil
|
60
|
+
end
|
42
61
|
end
|
43
62
|
|
44
63
|
#
|
45
64
|
# F'oo -> F''oo (for pg)
|
46
65
|
def escape_name(name)
|
47
|
-
name.gsub("'", "''")
|
66
|
+
name.to_s.gsub("'", "''")
|
48
67
|
end
|
49
68
|
|
50
69
|
#
|
@@ -52,9 +71,10 @@ module Geonames
|
|
52
71
|
def pg_values(arr)
|
53
72
|
arr.map do |v|
|
54
73
|
case v
|
55
|
-
when
|
74
|
+
when Numeric then v.to_s
|
75
|
+
when Symbol, String then "E'#{escape_name(v)}'"
|
56
76
|
when NilClass then 'NULL'
|
57
|
-
else
|
77
|
+
else
|
58
78
|
end
|
59
79
|
end.join(",")
|
60
80
|
end
|
@@ -65,5 +85,9 @@ module Geonames
|
|
65
85
|
for_pg = pg_values(hsh.values)
|
66
86
|
@conn.exec("INSERT INTO #{table} (#{hsh.keys.join(",")}) VALUES(#{for_pg}) RETURNING id")[0]["id"]
|
67
87
|
end
|
88
|
+
|
89
|
+
def exec(comm)
|
90
|
+
@conn.exec(comm)
|
91
|
+
end
|
68
92
|
end
|
69
93
|
end
|
data/lib/data/shp.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'iconv'
|
2
|
+
#---
|
3
|
+
# Iconv cool tip from http://po-ru.com/diary/fixing-invalid-utf-8-in-ruby-revisited/
|
4
|
+
|
5
|
+
module Geonames
|
6
|
+
class SHP
|
7
|
+
|
8
|
+
def initialize(file)
|
9
|
+
@file = file
|
10
|
+
@fname = file.split("/")[-1] rescue nil
|
11
|
+
@type = Object.module_eval("::#{Opt[:type].capitalize}", __FILE__, __LINE__)
|
12
|
+
@ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
|
13
|
+
@sample = nil
|
14
|
+
shp2pg if file
|
15
|
+
parse if file
|
16
|
+
write if file
|
17
|
+
end
|
18
|
+
|
19
|
+
def shp2pg
|
20
|
+
info "Converting SRID"
|
21
|
+
`shp2pgsql -D -as 4326 #{@file} nil > /tmp/#{@fname}.dump`
|
22
|
+
end
|
23
|
+
|
24
|
+
def parse_line(l)
|
25
|
+
return if l =~ /^SET\s|^BEGIN;|^COPY\s|^END;|^\\/
|
26
|
+
utf = @ic.iconv(l)
|
27
|
+
unless @sample
|
28
|
+
info "Free sample\n" + utf.inspect
|
29
|
+
@sample = true
|
30
|
+
end
|
31
|
+
@type.new(Opt[:map], utf, Opt[:country].upcase, Opt[:city])
|
32
|
+
end
|
33
|
+
|
34
|
+
def parse
|
35
|
+
info "Parsing dump"
|
36
|
+
start = Time.now
|
37
|
+
red = 0
|
38
|
+
File.open("/tmp/#{@fname}.dump") do |f|
|
39
|
+
while line = f.gets
|
40
|
+
if record = parse_line(line.chomp)
|
41
|
+
@table ||= record.table
|
42
|
+
Cache[@table] << record
|
43
|
+
red += 1
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
info "#{red} parsed. #{Time.now-start}s"
|
48
|
+
end
|
49
|
+
|
50
|
+
def reduce!
|
51
|
+
hsh = Cache[:roads].group_by { |r| r.name }
|
52
|
+
arr = []
|
53
|
+
hsh.map do |key, vals|
|
54
|
+
first = vals.delete_at(0)
|
55
|
+
# p vals[0].geom.geometries.concat(vals[1].geom.geometries)
|
56
|
+
vals.map(&:geom).each do |g|
|
57
|
+
first.geom.geometries.concat g.geometries
|
58
|
+
end
|
59
|
+
# = GeoRuby::SimpleFeatures::MultiLineString.
|
60
|
+
# from_line_strings([*vals.map(&:geom).map(&:geometries)])
|
61
|
+
first
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def write
|
66
|
+
db = Postgres.new(Opt[:db])
|
67
|
+
Geonames::CLI.do_write(db, Cache[:zones])
|
68
|
+
Geonames::CLI.do_write(db, reduce!)
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.import(file)
|
72
|
+
new(file)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
data/lib/features/road.rb
CHANGED
@@ -1,2 +1,41 @@
|
|
1
|
-
|
1
|
+
require "rubygems"
|
2
|
+
require "geo_ruby"
|
3
|
+
|
4
|
+
class Road
|
5
|
+
attr_reader :city, :province, :country, :zone, :name, :geom, :kind, :table
|
6
|
+
|
7
|
+
def initialize(keys, vals, country=nil, city=nil)
|
8
|
+
s = vals.split("\t")
|
9
|
+
r = {}
|
10
|
+
keys.each_with_index do |k, i|
|
11
|
+
r[k] = s[i]
|
12
|
+
end
|
13
|
+
@name = r[:name]
|
14
|
+
@zone = r[:zone]
|
15
|
+
kind = r[:kind] || @name.split(" ")[0]
|
16
|
+
@kind = parse_kind(kind)
|
17
|
+
@city = city
|
18
|
+
@country = country
|
19
|
+
parse_geom(r[:geom])
|
20
|
+
@table = :roads
|
2
21
|
end
|
22
|
+
|
23
|
+
def parse_geom(hex)
|
24
|
+
@geom = GeoRuby::SimpleFeatures::Geometry.from_hex_ewkb(hex)
|
25
|
+
end
|
26
|
+
|
27
|
+
def geom=(g)
|
28
|
+
@geom = g
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse_kind(k)
|
32
|
+
case k
|
33
|
+
when /^tun/i then :tunnel
|
34
|
+
when /^av/i then :avenue
|
35
|
+
when /^r/i then :street
|
36
|
+
when /\d/ then :road
|
37
|
+
else :unknown
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/lib/features/spot.rb
CHANGED
@@ -5,6 +5,7 @@ module Geonames
|
|
5
5
|
alias :x :lon
|
6
6
|
alias :y :lat
|
7
7
|
alias :geoname_id :gid
|
8
|
+
alias :table :kind
|
8
9
|
|
9
10
|
#
|
10
11
|
# = Geonames Spot
|
@@ -58,7 +59,7 @@ module Geonames
|
|
58
59
|
# Parse Geom to float or GeoRuby Point
|
59
60
|
def parse_geom(lat, lon)
|
60
61
|
@lat, @lon = lat.to_f, lon.to_f
|
61
|
-
|
62
|
+
|
62
63
|
if defined?("GeoRuby")
|
63
64
|
@geom = GeoRuby::SimpleFeatures::Point.from_x_y(@lon, @lat)
|
64
65
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "geo_ruby"
|
3
|
+
|
4
|
+
class Zone
|
5
|
+
attr_reader :city, :name, :geom, :kind
|
6
|
+
|
7
|
+
def initialize(keys, vals, city=nil)
|
8
|
+
s = vals.split("\t")
|
9
|
+
r = {}
|
10
|
+
keys.each_with_index do |k, i|
|
11
|
+
r[k] = s[i]
|
12
|
+
end
|
13
|
+
@name = r[:name]
|
14
|
+
@zone = r[:zone]
|
15
|
+
@kind = :zone # @name.split(" ")[0] unless kind
|
16
|
+
@city = city
|
17
|
+
parse_geom(r[:geom])
|
18
|
+
end
|
19
|
+
|
20
|
+
def parse_geom(hex)
|
21
|
+
@geom = GeoRuby::SimpleFeatures::Geometry.from_hex_ewkb(hex)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/lib/geonames_local.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
require 'features/spot'
|
2
2
|
require 'features/country'
|
3
3
|
require 'features/city'
|
4
|
+
require 'features/road'
|
5
|
+
require 'features/zone'
|
4
6
|
require 'rubygems'
|
5
7
|
require 'logger'
|
8
|
+
require 'data/shp'
|
6
9
|
require 'data/tokyo'
|
7
10
|
require 'data/postgres'
|
8
11
|
require 'work/cli'
|
@@ -11,7 +14,7 @@ require 'work/export'
|
|
11
14
|
|
12
15
|
module Geonames
|
13
16
|
Opt = {}
|
14
|
-
Cache = {:dump => [], :zip => []}
|
17
|
+
Cache = {:dump => [], :zip => [], :roads => [], :zones => []}
|
15
18
|
Codes = YAML.load(File.read(File.join(File.dirname(__FILE__),'config', 'codes.yml')))
|
16
19
|
VERSION = File.read(File.join(File.dirname(__FILE__), '..', 'VERSION'))
|
17
20
|
|
data/lib/work/cli.rb
CHANGED
@@ -20,12 +20,19 @@ BANNER
|
|
20
20
|
opts.separator ""
|
21
21
|
opts.separator "Config file:"
|
22
22
|
opts.on("-c", "--config CONFIG", String, "Geonames Config file path" ) { |file| options[:config] = file }
|
23
|
+
opts.on("-i", "--import CONFIG", String, "Geonames Import SHP/DBF/GPX" ) { |file| options[:shp] = file }
|
23
24
|
opts.separator ""
|
24
25
|
opts.separator "Tyrant Options:"
|
25
26
|
opts.on("-t", "--tyrant", "Use tyrant" ) { options[:tyrant] = true }
|
26
27
|
opts.on("-s", "--server SERVER", String, "Tyrant Server URL" ) { |url| options[:server] = url }
|
27
28
|
opts.on("-p", "--port PORT", Integer, "Tyrant Server Port") { |val| options[:port] = val.to_i }
|
28
29
|
opts.separator ""
|
30
|
+
opts.separator "SHP Options:"
|
31
|
+
opts.on("--map TYPE", Array, "Use zone/road to import" ) { |s| options[:map] = s.map(&:to_sym) }
|
32
|
+
opts.on("--type TYPE", String, "Use zone/road to import" ) { |s| options[:type] = s }
|
33
|
+
opts.on("--city CITY", String, "Use city gid to import" ) { |s| options[:city] = s }
|
34
|
+
opts.on("--country COUNTRY", String, "Use country gid to import" ) { |s| options[:country] = s }
|
35
|
+
opts.separator ""
|
29
36
|
opts.separator "Common Options:"
|
30
37
|
opts.on("-h", "--help", "Show this message" ) { puts opts; exit }
|
31
38
|
opts.on("-v", "--verbose", "Turn on logging to STDOUT" ) { |bool| options[:verbose] = bool }
|
@@ -46,6 +53,7 @@ BANNER
|
|
46
53
|
end
|
47
54
|
private_class_method :parse_options
|
48
55
|
|
56
|
+
# Ugly but works?
|
49
57
|
def self.work(argv)
|
50
58
|
trap(:INT) { stop! }
|
51
59
|
trap(:TERM) { stop! }
|
@@ -55,6 +63,11 @@ BANNER
|
|
55
63
|
Opt.merge! YAML.load(File.read(Opt[:config]))
|
56
64
|
end
|
57
65
|
|
66
|
+
if shp = Opt[:shp]
|
67
|
+
SHP.import(shp)
|
68
|
+
exit
|
69
|
+
end
|
70
|
+
|
58
71
|
if argv[0] =~ /list|codes/
|
59
72
|
Codes.each do |key,val|
|
60
73
|
str = [val.values, key.to_s].join(" ").downcase
|
@@ -107,13 +120,15 @@ BANNER
|
|
107
120
|
end
|
108
121
|
|
109
122
|
def self.do_write(db, val)
|
110
|
-
|
123
|
+
return if val.empty?
|
124
|
+
key = val[0].table
|
111
125
|
start = Time.now
|
112
126
|
writt = 0
|
113
|
-
info "\nWriting #{key}..."
|
127
|
+
info "\nWriting #{val.length} #{key}..."
|
114
128
|
val.each do |v|
|
115
|
-
|
116
|
-
|
129
|
+
meth = v.respond_to?(:gid) ? [v.gid] : [v.name, true]
|
130
|
+
unless db.find(v.table, *meth)
|
131
|
+
db.insert(v)
|
117
132
|
writt += 1
|
118
133
|
end
|
119
134
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe SHP do
|
4
|
+
|
5
|
+
Cache[:roads] = [Road.new([:name,:zone,:geom],"R DOUTOR VITAL BRASIL\t\\N\t0105000020E6100000010000000102000020E6100000020000009561DC0DA22B47C0EAB12D03CEF237C0136058FE7C2B47C0DE54A4C2D8F237C0"),
|
6
|
+
Road.new([:name,:zone,:geom],"R DOUTOR VITAL BRASIL\t\\N\t0105000020E6100000010000000102000020E610000003000000136058FE7C2B47C0DE54A4C2D8F237C0094E7D20792B47C0CCB56801DAF237C0CDCAF6216F2B47C08F1B7E37DDF237C0"),
|
7
|
+
Road.new([:name,:zone,:geom], "R DOUTOR VITAL BRASIL\t\\N\t0105000020E6100000010000000102000020E610000003000000A0F99CBB5D2B47C07A8F334DD8F237C019C6DD205A2B47C008E8BE9CD9F237C009C38025572B47C00DA5F622DAF237C0"),
|
8
|
+
Road.new([:name,:zone,:geom],"R DOUTOR VITAL BRASIL\t\\N\t0105000020E6100000010000000102000020E61000000300000009C38025572B47C00DA5F622DAF237C0155454FD4A2B47C082397AFCDEF237C0FB213658382B47C053060E68E9F237C0")]
|
9
|
+
|
10
|
+
Opt[:type] = "road"
|
11
|
+
|
12
|
+
it "should merge two records linestrings" do
|
13
|
+
@s = SHP.new(nil)
|
14
|
+
r = @s.reduce!
|
15
|
+
r.length.should eql(1)
|
16
|
+
r[0].geom.as_hex_ewkb.should_not eql(Cache[:roads][0].geom.as_hex_ewkb)
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
end
|
data/spec/data/tokyo_spec.rb
CHANGED
@@ -2,28 +2,28 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
2
|
|
3
3
|
describe "Tokyo" do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
# it "should write down a spot" do
|
6
|
+
# t = Geonames::Tokyo.new('localhost', 1978)
|
7
|
+
# m = mock(Geonames::Spot, { :gid => 888, :to_hash => { "gid" => 888, "kind" => "city", "lat" => 5.5 }})
|
8
|
+
# t.write(m)
|
9
|
+
# end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
# it "should read it up" do
|
12
|
+
# t = Geonames::Tokyo.new('localhost', 1978)
|
13
|
+
# record = t.find(888)
|
14
|
+
# record.should be_instance_of Geonames::Spot
|
15
|
+
# end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
# it "should not duplicate" do
|
18
|
+
# t = Geonames::Tokyo.new('localhost', 1978)
|
19
|
+
# t.all({ :gid => 888}).length.should eql(1)
|
20
|
+
# end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
# it "should return all countries" do
|
23
|
+
# all = Geonames::Country.all
|
24
|
+
# all.should be_instance_of Array
|
25
|
+
# all[0].should be_instance_of Geonames::Country
|
26
|
+
# all[0].gid.should eql(1)
|
27
|
+
# end
|
28
28
|
|
29
29
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require "geo_ruby"
|
3
|
+
|
4
|
+
describe Road do
|
5
|
+
|
6
|
+
describe "Parsing Dump" do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@road = Road.new([:zone, :name, :geom], "RIO COMPRIDO\tAV PAULO DE FRONTIN\t0105000020E6100000010000000102000020E61000000700000029A117E0C79A45C0D50B2027B3EE36C0782289C2C99A45C0ED188FFFC5EE36C0E6D342ABCA9A45C0AB8A7A7BD0EE36C00216B5BFCC9A45C07359511DDFEE36C0C489F290CE9A45C0DEA42096F7EE36C0453B2C65CD9A45C0DFCF664816EF36C04089595CCD9A45C00A220DA31AEF36C0")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should parse zone" do
|
13
|
+
@road.zone.should eql("RIO COMPRIDO")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should parse code" do
|
17
|
+
@road.name.should eql("AV PAULO DE FRONTIN")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should parse kind" do
|
21
|
+
@road.kind.should eql(:avenue)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should parse geom" do
|
25
|
+
@road.geom.should be_kind_of(GeoRuby::SimpleFeatures::MultiLineString)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should have 1 geometry" do
|
29
|
+
@road.geom.should have(1).geometries
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have 1 geometry linestring" do
|
33
|
+
geom = @road.geom.geometries[0]
|
34
|
+
geom.should be_kind_of(GeoRuby::SimpleFeatures::LineString)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should have 1 geometry linestring with n points" do
|
38
|
+
@road.geom.geometries[0].should have(7).points
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "Another parse" do
|
44
|
+
before do
|
45
|
+
@road = Road.new([:length, :name, :null, :null, :geom], "35.487\tMS-380\t2\t\N\t0105000020E6100000010000000102000020E6100000120000005A4B85AD49DC4BC0D9438EB3AE8736C04D5707662DDA4BC07FD132464F8336C05AF6FA9F8FD84BC0C43ACFACA97E36C07DAC68ABFED14BC0ADFF26E9687936C036ED20214BD04BC035B173E5557A36C0C115051259CD4BC0E4C9CF15617636C0429724EA1AC94BC04C0D087A5E7536C04C0FAB81C5C54BC0FD07B789257336C07FB8E40122BE4BC026F0474B218036C053A51A37ABBD4BC0E03173F8698036C0D642B66B34BD4BC0BC4E66A4B28036C0D696B79FBDBC4BC05337214FFB8036C01CA71ED346BC4BC043DCA3F8438136C07879EB05D0BB4BC0212EEEA08C8136C0B5131E3859BB4BC08F1D0048D58136C0A17BB669E2BA4BC0259BD9ED1D8236C007B7B49A6BBA4BC07D977A92668236C0BE2439F759B94BC0B67D375CCC8236C0")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should parse code" do
|
49
|
+
@road.name.should eql("MS-380")
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should parse kind" do
|
53
|
+
@road.kind.should eql(:road)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should parse geom" do
|
57
|
+
@road.geom.should be_kind_of(GeoRuby::SimpleFeatures::MultiLineString)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
# RIO COMPRIDO\tAV PAULO DE FRONTIN\t0105000020E6100000010000000102000020E61000000700000029A117E0C79A45C0D50B2027B3EE36C0782289C2C99A45C0ED188FFFC5EE36C0E6D342ABCA9A45C0AB8A7A7BD0EE36C00216B5BFCC9A45C07359511DDFEE36C0C489F290CE9A45C0DEA42096F7EE36C0453B2C65CD9A45C0DFCF664816EF36C04089595CCD9A45C00A220DA31AEF36C0
|
65
|
+
# RIO COMPRIDO\tELEV ENG FREYSSINET\t0105000020E6100000010000000102000020E61000001600000029A117E0C79A45C0D50B2027B3EE36C0616EE6DEC39A45C03A36CF0E94EE36C0E8C4CE25C09A45C0C7CC5FA884EE36C06FC623BBAD9A45C0CC16549751EE36C0C886FA2AA99A45C03FFE37E23EEE36C0D8A69F2DA79A45C036DFE40921EE36C0C5B0C586A89A45C060E6BA0F0FEE36C0417340F4B29A45C0CCD0A07BB9ED36C0F28BB536B89A45C01F0BB3CE94ED36C038AED593BA9A45C0AD84B8EA77ED36C0C8D80C30BD9A45C0DB5E15A837ED36C0642CEC83C29A45C04E78D9AEA9EC36C01FF44297C79A45C08091F28337EC36C0D0C63FCECA9A45C0ACC190D2E7EB36C06160C265CC9A45C0F4BA5997ABEB36C0141C44A2D19A45C046DA3ABC0BEB36C00A5183F3D49A45C0A800B9F987EA36C08F84CC8CD69A45C078B5508D41EA36C0FDEFEEEDD49A45C06F668B46D8E936C06DF2C8EBD39A45C05C575FADBEE936C05718F576D39A45C0D31DF017B1E936C056E59516D29A45C0F9EE1635A7E936C0
|
66
|
+
# GAMBOA\tTUN JOAO RICARDO\t0105000020E6100000010000000102000020E6100000060000008156E6D6F19845C06D89F7CECCE536C00A1B72A6CF9845C07AAC746217E636C016E1A9D1C99845C0A3B9AA0C24E636C0EE90F8C5C49845C047B01D022FE636C05F1D9379BB9845C0ADEA1C3443E636C0B146DDF6B19845C05FC1548D57E636C0
|
67
|
+
# SANTO CRISTO\tVD S PEDRO E S PAULO\t0105000020E6100000010000000102000020E610000006000000AC45D194B79945C04409BB661DE636C0B49FF422B89945C081E6846525E636C022FF9BAC949945C031F0CFDF8FE636C0978E80ED8F9945C056113F209EE636C0AF1242F7879945C001FE5FA5B8E636C09AB3B4607D9945C0A38B9395DCE636C0
|
68
|
+
|
@@ -0,0 +1,191 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
3
|
+
require "geo_ruby"
|
4
|
+
|
5
|
+
describe Spot do
|
6
|
+
|
7
|
+
describe "Parsing Dump" do
|
8
|
+
|
9
|
+
before do
|
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
|
12
|
+
|
13
|
+
it "should parse geoid integer" do
|
14
|
+
@spot.geoname_id.should eql(6319037)
|
15
|
+
@spot.gid.should eql(6319037)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should parse code" do
|
19
|
+
@spot.code.should eql("6593")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should parse province code" do
|
23
|
+
@spot.province.should eql("2407500")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should parse name" do
|
27
|
+
@spot.name.should eql("Maxaranguape")
|
28
|
+
@spot.ascii.should eql("Maxaranguape")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should parse geostuff" do
|
32
|
+
@spot.lat.should be_close(-5.4687, 0.001)
|
33
|
+
@spot.y.should be_close(-5.4687, 0.001)
|
34
|
+
@spot.lon.should be_close(-35.3565, 0.001)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should parse spot kind" do
|
38
|
+
@spot.kind.should eql(:cities)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should parse spot country" do
|
42
|
+
@spot.country.should eql("BR")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "shuold parse timezone" do
|
46
|
+
@spot.tz.should eql("America/Recife")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should parse updated_at" do
|
50
|
+
@spot.updated_at.should be_instance_of(Time)
|
51
|
+
@spot.updated_at.day.should eql(17)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "More Parseing" do
|
56
|
+
|
57
|
+
before do
|
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
|
60
|
+
|
61
|
+
it "should parse geoid integer" do
|
62
|
+
@spot.geoname_id.should eql(3384862)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should parse name" do
|
66
|
+
@spot.name.should eql("Riacho Zuza")
|
67
|
+
@spot.ascii.should eql("Riacho Zuza")
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should parse geostuff" do
|
71
|
+
@spot.lat.should be_close(-9.4333333, 0.001)
|
72
|
+
@spot.lon.should be_close(-37.6666667, 0.001)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should parse spot kind" do
|
76
|
+
@spot.kind.should eql(:other)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should parse spot country" do
|
80
|
+
@spot.country.should eql("BR")
|
81
|
+
end
|
82
|
+
|
83
|
+
it "shuold parse timezone" do
|
84
|
+
@spot.tz.should eql("America/Maceio")
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should parse updated_at" do
|
88
|
+
@spot.updated_at.should be_instance_of(Time)
|
89
|
+
@spot.updated_at.day.should eql(17)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "Parsing Province" do
|
94
|
+
|
95
|
+
before do
|
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
|
98
|
+
|
99
|
+
it "should be kind of province" do
|
100
|
+
@spot.kind.should eql(:provinces)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should parse geoid" do
|
104
|
+
@spot.geoname_id.should eql(3457153)
|
105
|
+
@spot.gid.should eql(3457153)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should parse code" do
|
109
|
+
@spot.code.should be_empty
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should parse province code" do
|
113
|
+
@spot.province.should eql("15")
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should create abbr" do
|
117
|
+
@spot.abbr.should eql("MG")
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should parse name" do
|
121
|
+
@spot.name.should eql("Minas Gerais")
|
122
|
+
@spot.ascii.should eql("Estado de Minas Gerais")
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should parse geostuff" do
|
126
|
+
@spot.lat.should be_close(-18.0, 0.001)
|
127
|
+
@spot.lon.should be_close(-44.0, 0.001)
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "Parsing Zip" do
|
133
|
+
|
134
|
+
before do
|
135
|
+
@spot = Geonames::Spot.new("BR\t76375-000\tHidrolina\tGoias\t29\t\t5209804\t\t-14.7574\t-49.3596\t\n", :zip)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should parse zip oO" do
|
139
|
+
@spot.zip.should eql("76375")
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should be a city" do
|
143
|
+
@spot.kind.should eql(:cities)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should parse code" do
|
147
|
+
@spot.code.should eql("5209804")
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should parse geoid integer" do
|
151
|
+
@spot.gid.should be_nil # eql(3384862)
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should parse name" do
|
155
|
+
@spot.name.should eql("Hidrolina")
|
156
|
+
@spot.ascii.should be_nil # eql("Hidrolina")
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should parse geostuff" do
|
160
|
+
@spot.lat.should be_close(-14.7574, 0.001)
|
161
|
+
@spot.lon.should be_close(-49.3596, 0.001)
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
# 6319037 Maxaranguape Maxaranguape -5.46874226086957 -35.3565714695652 A ADM2 BR 22 2407500 6593 12 America/Recife 2006-12-17
|
169
|
+
# 6319038 Mossoró Mossoro -5.13813983076923 -37.2784795923077 A ADM2 BR 22 2408003 205822 33 America/Fortaleza 2006-12-17
|
170
|
+
# 6319039 Nísia Floresta Nisia Floresta -6.06240228440367 -35.1690981651376 A ADM2 BR 22 2408201 15817 15 America/Recife 2006-12-17
|
171
|
+
# 6319040 Paraú Parau -5.73215878787879 -37.1366413030303 A ADM2 BR
|
172
|
+
# 22 2408706 4093 94 America/Fortaleza 2006-12-17
|
173
|
+
|
174
|
+
# "BR\t76375-000\tHidrolina\tGoias\t29\t\t5209804\t\t-14.7574\t-49.3596\t\n"
|
175
|
+
# "BR\t73920-000\tIaciara\tGoias\t29\t\t5209903\t\t-14.0819\t-46.7211\t\n"
|
176
|
+
# "BR\t75550-000\tInaciolândia\tGoias\t29\t\t5209937\t\t-18.4989\t-49.9016\t\n"
|
177
|
+
# "BR\t75955-000\tIndiara\tGoias\t29\t\t5209952\t^C\t-17.2276\t-49.9667\t\n"
|
178
|
+
# "IT\t89900\tVena\tCalabria\t\tVibo Valentia\tVV\t\t38.6578\t16.0602\t4\n"
|
179
|
+
# "IT\t89900\tVibo Marina\tCalabria\t\tVibo Valentia\tVV\t\t38.7143\t16.1135\t4\n"
|
180
|
+
# "IT\t89900\tTriparni\tCalabria\t\tVibo Valentia\tVV\t\t38.6839\t16.0672\t4\n"
|
181
|
+
# "IT\t89900\tPiscopio\tCalabria\t\tVibo Valentia\tVV\t\t38.6635\t16.112\t4\n"
|
182
|
+
|
183
|
+
# "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"
|
184
|
+
# "3457415\tEstado de Mato Grosso do Sul\tEstado de Mato Grosso do Sul\tEstado do Mato Grosso do Sul,Mato Grosso do Sul\t-21.0\t-55.0\tA\tADM1\tBR\t\t11\t\t\t\t2233378\t\t446\tAmerica/Campo_Grande\t2007-05-15\n"
|
185
|
+
# "3457419\tEstado de Mato Grosso\tEstado de Mato Grosso\tMato Grosso\t-13.0\t-56.0\tA\tADM1\tBR\t\t14\t\t\t\t2235832\t\t335\tAmerica/Cuiaba\t2007-05-15\n"
|
186
|
+
# "3462372\tEstado de Goiás\tEstado de Goias\tGoias,Goiaz,Goiás,Goyaz\t-15.5807107391621\t-49.63623046875\tA\tADM1\tBR\t\t29\t\t\t\t5521522\t\t695\tAmerica/Araguaina\t2009-10-04\n"
|
187
|
+
# "3463504\tDistrito Federal\tDistrito Federal\tDistrito Federal,Distrito Federal de Brasilia,Distrito Federal de Brasília,Futuro Distrito Federal,Municipio Federal,Novo Distrito Federal\t-15.75\t-47.75\tA\tADM1\tBR\t\t07\t\t\t\t1821946\t\t1035\tAmerica/Sao_Paulo\t2007-05-15\n"
|
188
|
+
|
189
|
+
# "3165361\tToscana\tToscana\tTaskana,Toscan-a,Toscana,Toscane,Toscann-a,Toskana,Toskania,Toskanio,Toskansko,Toskánsko,Toskāna,Toszkana,Toszkána,Tuscany,Tuschena,Tuschèna,Tuscia,toseukana ju,tosukana zhou,tuo si ka na,twsqnh,Таскана,Тоскана,טוסקנה,تسکانہ,ტოსკანა,トスカーナ州,托斯卡纳,토스카나 주\t43.4166667\t11.0\tA\tADM1\tIT\t\t16\t\t\t\t3718210\t\t249\tEurope/Rome\t2010-01-17\n"
|
190
|
+
# "3169778\tRegione Puglia\tRegione Puglia\tApulia,Apulie,Apulien,Apulië,Pouilles,Puglia\t41.25\t16.25\tA\tADM1\tIT\t\t13\t\t\t\t4021957\t\t95\tEurope/Rome\t2009-03-11\n"
|
191
|
+
# "3170831\tRegione Piemonte\tRegione Piemonte\tPedemons,Pedemontium,Piamonte,Piedmont,Piemont,Piemonte,Piémont,Piëmont,Regione Piemonte\t45.0\t8.0\tA\tADM1\tIT\t\t12\t\t\t\t4294081\t\t185\tEurope/Rome\t2008-08-18\n"
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require "geo_ruby"
|
3
|
+
|
4
|
+
describe Zone do
|
5
|
+
|
6
|
+
describe "Parsing Dump" do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@zone = Zone.new([:name, :null, :geom], "Copacabana\t2\t0106000020E6100000010000000103000020E6100000010000001B000000DE024322029645C0E3263B4536F736C06A78FF7D099745C05F4C17BC3AF836C016ECF835959745C0A6303C5AF6F836C031D79B0DEE9745C02A86A360EDF936C0BBC7A929259845C054515A9559FB36C0050527EF109845C02AD15A3969FC36C0A5705221BD9745C031151F7ACBFC36C0A96DC310049845C0055C26CBE0FC36C0C0FA3CDA6E9845C02424EED2F6FC36C08D80123FF49845C03C190018D7FB36C02E4C5C15199945C0A11ABD694CFB36C00D94B215269945C0F04B5E66CAFA36C03440A3EA169945C029ADE30D51FA36C082988494F89845C06DF6F65FD3F936C0E1CC3ABED39845C00B593959CFF836C0C0ED50117D9845C045937E53F2F736C03440A3EA169945C0CDFE644A93F636C0BA204AE9E29845C0C2EF96F233F636C08C60DFA8C29845C0A38B4DC61DF636C06DA128929D9845C03DE8AF4604F636C047CEF70F499845C08B67D19D49F636C0E87201390A9845C073BEF5F5B5F636C05F50930A799745C0B707094838F636C06CEAA05AAD9645C049A9FD439CF536C034760E48739645C0B9F4FBDC84F536C0F2A307AC159645C0CCEA3108E3F636C0DE024322029645C0E3263B4536F736C0")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should parse code" do
|
13
|
+
@zone.name.should eql("Copacabana")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should parse kind" do
|
17
|
+
@zone.kind.should eql(:zone)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should parse geom" do
|
21
|
+
@zone.geom.should be_kind_of(GeoRuby::SimpleFeatures::MultiPolygon)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should have 1 geometry" do
|
25
|
+
@zone.geom.should have(1).geometries
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should have 1 geometry polygon" do
|
29
|
+
geom = @zone.geom.geometries[0]
|
30
|
+
geom.should be_kind_of(GeoRuby::SimpleFeatures::Polygon)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should have 1 geometry polygon with n points" do
|
34
|
+
@zone.geom.geometries[0][0].should have(27).points
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "Another parse" do
|
40
|
+
before do
|
41
|
+
@zone = Zone.new([:name, :null, :geom], "Botafogo\t4\t0106000020E6100000010000000103000020E610000001000000260000008C60DFA8C29845C0A38B4DC61DF636C0D68132D5E79845C090FADA554EF536C069D119B12A9945C0D857001102F436C0298D2075189945C0BFEDCBEBA8F336C049DBDD0FFA9845C0EEE2E7537BF336C0D68132D5E79845C0C2DCE6FB5FF336C0A761EE3BB99845C0FD7DA07637F336C048D58ABADF9845C061341567FBF136C0D5CD0D24649845C01D4DDC69AEF136C0106FC79E3B9845C058EE95E485F136C0739E6AE14F9845C043737CCFE3F036C0C10619C0459845C0466297DF9AF036C0BD63D9FE0A9845C0AF6F70421DF036C0A8E8BFE9689745C022C3C82715F036C0AF7A1ABB5A9745C08103515A72F036C0805AD6212C9745C0A04BBB9F39F036C03FFE0258109745C0E861C12D4AF036C0FD2EA4E8CC9645C08103515A72F036C03F62B834969645C0A9913A22AFF036C0C96B208E639645C0875AB5CC30F136C02DFC02077A9645C03E01065281F136C0BD3A35D49B9645C04CFB74214EF136C04048B7CBD99645C0F0F4ABBE6EF136C0ABD7DAF91F9745C0521060C417F236C083C8D321229745C0BC1081D776F236C009643E7BF99645C083E4C80ECAF236C0D16BCFB3BF9645C0EFBC652AD8F236C084595B73599645C07CA67AEF3AF336C0B1592EAC6B9645C0A3A74E6AB4F336C03DAE50A9189645C0D653696356F436C02127B0EE3C9645C070D22BCB62F536C034760E48739645C0B9F4FBDC84F536C06CEAA05AAD9645C049A9FD439CF536C05F50930A799745C0B707094838F636C0E87201390A9845C073BEF5F5B5F636C047CEF70F499845C08B67D19D49F636C06DA128929D9845C03DE8AF4604F636C08C60DFA8C29845C0A38B4DC61DF636C0")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should parse code" do
|
45
|
+
@zone.name.should eql("Botafogo")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should parse geom" do
|
49
|
+
@zone.geom.should be_kind_of(GeoRuby::SimpleFeatures::MultiPolygon)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should have 1 geometry polygon with n points" do
|
53
|
+
@zone.geom.geometries[0][0].should have(38).points
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Copacabana\t2\t0106000020E6100000010000000103000020E6100000010000001B000000DE024322029645C0E3263B4536F736C06A78FF7D099745C05F4C17BC3AF836C016ECF835959745C0A6303C5AF6F836C031D79B0DEE9745C02A86A360EDF936C0BBC7A929259845C054515A9559FB36C0050527EF109845C02AD15A3969FC36C0A5705221BD9745C031151F7ACBFC36C0A96DC310049845C0055C26CBE0FC36C0C0FA3CDA6E9845C02424EED2F6FC36C08D80123FF49845C03C190018D7FB36C02E4C5C15199945C0A11ABD694CFB36C00D94B215269945C0F04B5E66CAFA36C03440A3EA169945C029ADE30D51FA36C082988494F89845C06DF6F65FD3F936C0E1CC3ABED39845C00B593959CFF836C0C0ED50117D9845C045937E53F2F736C03440A3EA169945C0CDFE644A93F636C0BA204AE9E29845C0C2EF96F233F636C08C60DFA8C29845C0A38B4DC61DF636C06DA128929D9845C03DE8AF4604F636C047CEF70F499845C08B67D19D49F636C0E87201390A9845C073BEF5F5B5F636C05F50930A799745C0B707094838F636C06CEAA05AAD9645C049A9FD439CF536C034760E48739645C0B9F4FBDC84F536C0F2A307AC159645C0CCEA3108E3F636C0DE024322029645C0E3263B4536F736C0
|
60
|
+
# Urca\t3\t0106000020E6100000010000000103000020E6100000010000001B0000002127B0EE3C9645C070D22BCB62F536C03DAE50A9189645C0D653696356F436C0B1592EAC6B9645C0A3A74E6AB4F336C084595B73599645C07CA67AEF3AF336C0E83F2850F59545C055D7AD3C9FF336C0DC146FFBDC9545C05C1D2A82ACF336C0D1AB3413C99545C05A5BAB15A8F336C01A57D1575A9545C091A56AC0D9F236C0C4ABD57A139545C0B6F9F5385CF236C0F455FDDCE09445C049FA5FF698F236C0C7552AA4CE9445C0A5A45A9178F236C06BAB2F09EF9445C061A3A4F0F2F136C041000765BA9445C0974CCB1059F136C03455C0E6919445C0A8A166B83CF136C051025D60269445C077C0834475F136C073CD3C4DED9345C0ADBF9312F6F036C0D74FB1CC5D9345C0980DE0176DF036C042ED293B4A9345C0620ED049ECF036C0B3A5A698B29345C0024AB15844F136C01A85C978D69345C00965B547C0F136C00ECD44B4AD9345C0A124EB3987F236C08E7D184B389345C04FF77B54ECF236C007B240C5319345C0C0AFF8B154F336C062F6BACCE69445C0CDE500904CF436C005FD244EEC9445C0DF38B3A39CF436C0E9BC9FD8169545C01F0AEC70AAF436C02127B0EE3C9645C070D22BCB62F536C0
|
61
|
+
# Botafogo\t4\t0106000020E6100000010000000103000020E610000001000000260000008C60DFA8C29845C0A38B4DC61DF636C0D68132D5E79845C090FADA554EF536C069D119B12A9945C0D857001102F436C0298D2075189945C0BFEDCBEBA8F336C049DBDD0FFA9845C0EEE2E7537BF336C0D68132D5E79845C0C2DCE6FB5FF336C0A761EE3BB99845C0FD7DA07637F336C048D58ABADF9845C061341567FBF136C0D5CD0D24649845C01D4DDC69AEF136C0106FC79E3B9845C058EE95E485F136C0739E6AE14F9845C043737CCFE3F036C0C10619C0459845C0466297DF9AF036C0BD63D9FE0A9845C0AF6F70421DF036C0A8E8BFE9689745C022C3C82715F036C0AF7A1ABB5A9745C08103515A72F036C0805AD6212C9745C0A04BBB9F39F036C03FFE0258109745C0E861C12D4AF036C0FD2EA4E8CC9645C08103515A72F036C03F62B834969645C0A9913A22AFF036C0C96B208E639645C0875AB5CC30F136C02DFC02077A9645C03E01065281F136C0BD3A35D49B9645C04CFB74214EF136C04048B7CBD99645C0F0F4ABBE6EF136C0ABD7DAF91F9745C0521060C417F236C083C8D321229745C0BC1081D776F236C009643E7BF99645C083E4C80ECAF236C0D16BCFB3BF9645C0EFBC652AD8F236C084595B73599645C07CA67AEF3AF336C0B1592EAC6B9645C0A3A74E6AB4F336C03DAE50A9189645C0D653696356F436C02127B0EE3C9645C070D22BCB62F536C034760E48739645C0B9F4FBDC84F536C06CEAA05AAD9645C049A9FD439CF536C05F50930A799745C0B707094838F636C0E87201390A9845C073BEF5F5B5F636C047CEF70F499845C08B67D19D49F636C06DA128929D9845C03DE8AF4604F636C08C60DFA8C29845C0A38B4DC61DF636C0
|
62
|
+
# Flamengo\t5\t0106000020E6100000010000000103000020E6100000010000001B0000003FFE0258109745C0E861C12D4AF036C0505F06F0EC9645C061922586A4EE36C0E340E3A0AF9645C0A4624A4E9AEE36C0E340E3A0AF9645C0732E602406EE36C0DF4D6D4F899645C069BD2F5CF7EC36C03CA0B8582D9645C069BD2F5CF7EC36C05115EC3A1D9645C080D8EC67A1EC36C0D4740B5B169645C09080E9BD7CEC36C028793995099645C00E3B47AB1BEC36C0E89B8A1E3A9645C0BB9E4A9D8CEB36C02486C343E39545C064A7A61173EB36C0920C18BF849545C0A21C245CDEEB36C0E1B59E7BED9545C08855DFE729EE36C0B8FE5B2C049645C0B95A3CEB64EF36C041A95EF9EE9545C00EE55931B3EF36C053FE6393C49545C03C68BEE2A2EF36C08F187850C19545C075C47C11D7EF36C038AF2FC38E9545C0FC8F5497DDEF36C038AF2FC38E9545C023970D2C3CF036C0EA3F166CBC9545C00D84B2039EF036C04DD4C1CA2A9645C0D1F66EC79DF136C0B261DB56579645C0B01C4273A9F136C02DFC02077A9645C03E01065281F136C0C96B208E639645C0875AB5CC30F136C03F62B834969645C0A9913A22AFF036C0FD2EA4E8CC9645C08103515A72F036C03FFE0258109745C0E861C12D4AF036C0
|
data/spec/geonames_local_spec.rb
CHANGED
@@ -1,87 +1,10 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
3
|
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
before do
|
8
|
-
@spot = Geonames::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")
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should parse geoid integer" do
|
12
|
-
@spot.geoname_id.should eql(6319037)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should parse name" do
|
16
|
-
@spot.name.should eql("Maxaranguape")
|
17
|
-
@spot.ascii.should eql("Maxaranguape")
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should parse geostuff" do
|
21
|
-
@spot.lat.should be_close(-5.4687, 0.001)
|
22
|
-
@spot.y.should be_close(-5.4687, 0.001)
|
23
|
-
@spot.lon.should be_close(-35.3565, 0.001)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should parse spot kind" do
|
27
|
-
@spot.kind.should eql(:city)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should parse spot country" do
|
31
|
-
@spot.country.should eql("BR")
|
32
|
-
end
|
33
|
-
|
34
|
-
it "shuold parse timezone" do
|
35
|
-
@spot.tz.should eql("America/Recife")
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should parse updated_at" do
|
39
|
-
@spot.updated_at.should be_instance_of(Time)
|
40
|
-
@spot.updated_at.day.should eql(17)
|
41
|
-
end
|
4
|
+
describe Geonames do
|
5
|
+
it "should have a cache" do
|
6
|
+
Cache.should be_instance_of(Hash)
|
42
7
|
end
|
43
8
|
|
44
|
-
describe "More Parseing" do
|
45
|
-
before do
|
46
|
-
@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")
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should parse geoid integer" do
|
50
|
-
@spot.geoname_id.should eql(3384862)
|
51
|
-
end
|
52
9
|
|
53
|
-
it "should parse name" do
|
54
|
-
@spot.name.should eql("Riacho Zuza")
|
55
|
-
@spot.ascii.should eql("Riacho Zuza")
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should parse geostuff" do
|
59
|
-
@spot.lat.should be_close(-9.4333333, 0.001)
|
60
|
-
@spot.lon.should be_close(-37.6666667, 0.001)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should parse spot kind" do
|
64
|
-
@spot.kind.should eql(:other)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should parse spot country" do
|
68
|
-
@spot.country.should eql("BR")
|
69
|
-
end
|
70
|
-
|
71
|
-
it "shuold parse timezone" do
|
72
|
-
@spot.tz.should eql("America/Maceio")
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should parse updated_at" do
|
76
|
-
@spot.updated_at.should be_instance_of(Time)
|
77
|
-
@spot.updated_at.day.should eql(17)
|
78
|
-
end
|
79
|
-
end
|
80
10
|
end
|
81
|
-
|
82
|
-
# 6319037 Maxaranguape Maxaranguape -5.46874226086957 -35.3565714695652 A ADM2 BR 22 2407500 6593 12 America/Recife 2006-12-17
|
83
|
-
# 6319038 Mossoró Mossoro -5.13813983076923 -37.2784795923077 A ADM2 BR 22 2408003 205822 33 America/Fortaleza 2006-12-17
|
84
|
-
# 6319039 Nísia Floresta Nisia Floresta -6.06240228440367 -35.1690981651376 A ADM2 BR 22 2408201 15817 15 America/Recife 2006-12-17
|
85
|
-
|
86
|
-
# 6319040 Paraú Parau -5.73215878787879 -37.1366413030303 A ADM2 BR
|
87
|
-
# 22 2408706 4093 94 America/Fortaleza 2006-12-17
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geonames_local
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcos Piccinini
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-29 00:00:00 -02:00
|
13
13
|
default_executable: geonames
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -49,24 +49,36 @@ files:
|
|
49
49
|
- Rakefile
|
50
50
|
- VERSION
|
51
51
|
- bin/geonames
|
52
|
+
- geonames.yml
|
53
|
+
- geonames_local.gemspec
|
52
54
|
- lib/config/codes.yml
|
53
55
|
- lib/config/geonames.yml
|
56
|
+
- lib/data/cache.rb
|
54
57
|
- lib/data/geoquery.rb
|
55
58
|
- lib/data/postgres.rb
|
59
|
+
- lib/data/shp.rb
|
56
60
|
- lib/data/tokyo.rb
|
57
61
|
- lib/features/city.rb
|
58
62
|
- lib/features/country.rb
|
59
63
|
- lib/features/province.rb
|
60
64
|
- lib/features/road.rb
|
61
65
|
- lib/features/spot.rb
|
66
|
+
- lib/features/zone.rb
|
62
67
|
- lib/geonames_local.rb
|
63
68
|
- lib/work/cli.rb
|
64
69
|
- lib/work/dump.rb
|
65
70
|
- lib/work/export.rb
|
71
|
+
- spec/data/cache_spec.rb
|
72
|
+
- spec/data/postgres_spec.rb
|
73
|
+
- spec/data/shp_spec.rb
|
66
74
|
- spec/data/tokyo_spec.rb
|
75
|
+
- spec/features/road_spec.rb
|
76
|
+
- spec/features/spot_spec.rb
|
77
|
+
- spec/features/zone_spec.rb
|
67
78
|
- spec/geonames_local_spec.rb
|
68
79
|
- spec/spec.opts
|
69
80
|
- spec/spec_helper.rb
|
81
|
+
- spec/work/cli_spec.rb
|
70
82
|
- task/benchmark.rb
|
71
83
|
- task/benchmark_cabinet.rb
|
72
84
|
has_rdoc: true
|
@@ -98,6 +110,13 @@ signing_key:
|
|
98
110
|
specification_version: 3
|
99
111
|
summary: Dump and feed a tokyo local geonames db
|
100
112
|
test_files:
|
113
|
+
- spec/data/cache_spec.rb
|
114
|
+
- spec/data/postgres_spec.rb
|
115
|
+
- spec/data/shp_spec.rb
|
101
116
|
- spec/data/tokyo_spec.rb
|
117
|
+
- spec/features/road_spec.rb
|
118
|
+
- spec/features/spot_spec.rb
|
119
|
+
- spec/features/zone_spec.rb
|
102
120
|
- spec/geonames_local_spec.rb
|
103
121
|
- spec/spec_helper.rb
|
122
|
+
- spec/work/cli_spec.rb
|