geonames 0.2.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/Gemfile +7 -0
- data/README.markdown +82 -0
- data/Rakefile +13 -0
- data/init.rb +1 -0
- data/lib/geonames.rb +38 -22
- data/lib/geonames/bounding_box.rb +12 -0
- data/lib/{country_subdivision.rb → geonames/config.rb} +26 -13
- data/lib/geonames/country_info.rb +18 -0
- data/lib/{Rakefile.rb → geonames/country_subdivision.rb} +11 -6
- data/lib/geonames/intersection.rb +28 -0
- data/lib/{toponym_search_result.rb → geonames/postal_code.rb} +10 -16
- data/lib/geonames/postal_code_search_criteria.rb +50 -0
- data/lib/{timezone.rb → geonames/timezone.rb} +10 -11
- data/lib/geonames/toponym.rb +29 -0
- data/lib/geonames/toponym_search_criteria.rb +34 -0
- data/lib/{address.rb → geonames/toponym_search_result.rb} +10 -7
- data/lib/geonames/version.rb +3 -0
- data/lib/geonames/web_service.rb +467 -0
- data/lib/{wikipedia_article.rb → geonames/wikipedia_article.rb} +5 -20
- data/ruby-geonames.gemspec +24 -0
- data/spec/fixtures/country_info/thailand.xml.http +29 -0
- data/spec/fixtures/country_subdivision/ontario.xml.http +20 -0
- data/spec/fixtures/countrycode/canada.xml.http +16 -0
- data/spec/fixtures/find_nearby/marchtrenk.xml.http +37 -0
- data/spec/fixtures/find_nearby/wilkinson.xml.http +23 -0
- data/spec/fixtures/find_nearby_place_name/oshawa.xml.http +23 -0
- data/spec/fixtures/find_nearby_postal_codes/oshawa.xml.http +81 -0
- data/spec/fixtures/find_nearby_wikipedia/general_motors_centre.xml.http +81 -0
- data/spec/fixtures/find_nearest_intersection/park_ave_and_e_51st_st.xml.http +24 -0
- data/spec/fixtures/hierarchy/zurich.xml.http +87 -0
- data/spec/fixtures/postal_code_search/lat_lng.xml.http +81 -0
- data/spec/fixtures/postal_code_search/oshawa.xml.http +77 -0
- data/spec/fixtures/search/austria.xml.http +146 -0
- data/spec/fixtures/search/marchtrenk.xml.http +93 -0
- data/spec/fixtures/search/upper_austria.xml.http +48 -0
- data/spec/fixtures/timezone/america_toronto.xml.http +24 -0
- data/spec/fixtures/wikipedia_bounding_box/wyoming.xml.http +154 -0
- data/spec/geonames/postal_code_search_criteria_spec.rb +31 -0
- data/spec/geonames/web_service/country_code_spec.rb +24 -0
- data/spec/geonames/web_service/country_info_spec.rb +42 -0
- data/spec/geonames/web_service/country_subdivision_spec.rb +24 -0
- data/spec/geonames/web_service/find_bounding_box_wikipedia_spec.rb +28 -0
- data/spec/geonames/web_service/find_nearby_place_name_spec.rb +24 -0
- data/spec/geonames/web_service/find_nearby_postal_codes_spec.rb +29 -0
- data/spec/geonames/web_service/find_nearby_spec.rb +41 -0
- data/spec/geonames/web_service/find_nearby_wikipedia_spec.rb +26 -0
- data/spec/geonames/web_service/find_nearest_intersection_spec.rb +18 -0
- data/spec/geonames/web_service/hierarchy_spec.rb +23 -0
- data/spec/geonames/web_service/postal_code_search_spec.rb +49 -0
- data/spec/geonames/web_service/search_spec.rb +54 -0
- data/spec/geonames/web_service/timezone_spec.rb +22 -0
- data/spec/geonames/web_service_spec.rb +13 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/support/fakeweb.rb +9 -0
- metadata +152 -61
- data/README +0 -0
- data/geonames-0.2.2.gem +0 -0
- data/geonames.gemspec +0 -18
- data/lib/intersection.rb +0 -42
- data/lib/main.rb +0 -63
- data/lib/postal_code.rb +0 -40
- data/lib/postal_code_search_criteria.rb +0 -84
- data/lib/toponym.rb +0 -45
- data/lib/toponym_search_criteria.rb +0 -44
- data/lib/web_service.rb +0 -493
- data/nbproject/private/private.properties +0 -0
- data/nbproject/private/private.xml +0 -4
- data/nbproject/project.properties +0 -3
- data/nbproject/project.xml +0 -15
data/lib/intersection.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
#=============================================================================
|
2
|
-
#
|
3
|
-
# Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
6
|
-
# use this file except in compliance with the License. You may obtain a copy of
|
7
|
-
# the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
13
|
-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
14
|
-
# License for the specific language governing permissions and limitations under
|
15
|
-
# the License.
|
16
|
-
#
|
17
|
-
#=============================================================================
|
18
|
-
|
19
|
-
module Geonames
|
20
|
-
class Intersection
|
21
|
-
attr :street_1
|
22
|
-
attr :street_2
|
23
|
-
attr :latitude
|
24
|
-
attr :longitude
|
25
|
-
attr :distance
|
26
|
-
attr :postal_code
|
27
|
-
attr :place_name
|
28
|
-
attr :country_code
|
29
|
-
attr :admin_code_1
|
30
|
-
attr :admin_name_2
|
31
|
-
attr :admin_code_2
|
32
|
-
attr :admin_name_1
|
33
|
-
|
34
|
-
attr_writer :street_1, :street_2
|
35
|
-
attr_writer :postal_code, :place_name, :country_code
|
36
|
-
attr_writer :latitude, :longitude, :admin_name_1
|
37
|
-
attr_writer :admin_code_1, :admin_name_2, :admin_code_2
|
38
|
-
attr_writer :distance
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
|
data/lib/main.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
#=============================================================================
|
2
|
-
#
|
3
|
-
# Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
|
4
|
-
# Contributions by Andrew Turner, High Earth Orbit
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
7
|
-
# use this file except in compliance with the License. You may obtain a copy of
|
8
|
-
# the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
14
|
-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
15
|
-
# License for the specific language governing permissions and limitations under
|
16
|
-
# the License.
|
17
|
-
#
|
18
|
-
#=============================================================================
|
19
|
-
|
20
|
-
require 'geonames'
|
21
|
-
require 'pp'
|
22
|
-
|
23
|
-
# get the nearest intersection
|
24
|
-
intersection = Geonames::WebService.find_nearest_intersection 40.7574053333333, -73.9734773333333
|
25
|
-
puts intersection.street_1 #=> Park Ave
|
26
|
-
puts intersection.street_2 #=> E 51st St
|
27
|
-
|
28
|
-
# get wikipedia articles by lat / long
|
29
|
-
articles_nearby = Geonames::WebService.find_nearby_wikipedia :lat => 43.900120387, :long => -78.882869834
|
30
|
-
p articles_nearby
|
31
|
-
|
32
|
-
# get wikipedia articles by bounding box
|
33
|
-
articles_nearby = Geonames::WebService.find_bounding_box_wikipedia :north => 43.900120387, :east => -78.882869834, :south => 43.82, :west => 79.0
|
34
|
-
p articles_nearby
|
35
|
-
|
36
|
-
# get list of places near by longitude/longitude location
|
37
|
-
places_nearby = Geonames::WebService.find_nearby_place_name 43.900120387, -78.882869834
|
38
|
-
p places_nearby
|
39
|
-
|
40
|
-
# get timezone for longitude/longitude location
|
41
|
-
timezone = Geonames::WebService.timezone 43.900120387, -78.882869834
|
42
|
-
p timezone
|
43
|
-
|
44
|
-
# get country code for longitude/longitude location
|
45
|
-
country_code = Geonames::WebService.country_code 43.900120387, -78.882869834
|
46
|
-
p country_code
|
47
|
-
|
48
|
-
# get country sub-division info for longitude/longitude location
|
49
|
-
country_subdivision = Geonames::WebService.country_subdivision 43.900120387, -78.882869834
|
50
|
-
p country_subdivision
|
51
|
-
|
52
|
-
# get postal codes for a given location
|
53
|
-
postal_code_sc = Geonames::PostalCodeSearchCriteria.new
|
54
|
-
postal_code_sc.place_name = "Oshawa"
|
55
|
-
postal_codes = Geonames::WebService.postal_code_search postal_code_sc
|
56
|
-
p postal_codes
|
57
|
-
|
58
|
-
# get nearby postal codes for a place name
|
59
|
-
postal_code_sc = Geonames::PostalCodeSearchCriteria.new
|
60
|
-
postal_code_sc.place_name = "Oshawa"
|
61
|
-
postal_codes_nearby = Geonames::WebService.find_nearby_postal_codes postal_code_sc
|
62
|
-
p postal_codes_nearby
|
63
|
-
|
data/lib/postal_code.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
#=============================================================================
|
2
|
-
#
|
3
|
-
# Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
6
|
-
# use this file except in compliance with the License. You may obtain a copy of
|
7
|
-
# the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
13
|
-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
14
|
-
# License for the specific language governing permissions and limitations under
|
15
|
-
# the License.
|
16
|
-
#
|
17
|
-
#=============================================================================
|
18
|
-
|
19
|
-
module Geonames
|
20
|
-
class PostalCode
|
21
|
-
attr :postal_code
|
22
|
-
attr :place_name
|
23
|
-
attr :country_code
|
24
|
-
attr :latitude
|
25
|
-
attr :longitude
|
26
|
-
attr :admin_name_1
|
27
|
-
attr :admin_code_1
|
28
|
-
attr :admin_name_2
|
29
|
-
attr :admin_code_2
|
30
|
-
attr :distance
|
31
|
-
|
32
|
-
attr_writer :postal_code, :place_name, :country_code
|
33
|
-
attr_writer :latitude, :longitude, :admin_name_1
|
34
|
-
attr_writer :admin_code_1, :admin_name_2, :admin_code_2
|
35
|
-
attr_writer :distance
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
|
@@ -1,84 +0,0 @@
|
|
1
|
-
#=============================================================================
|
2
|
-
#
|
3
|
-
# Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
6
|
-
# use this file except in compliance with the License. You may obtain a copy of
|
7
|
-
# the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
13
|
-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
14
|
-
# License for the specific language governing permissions and limitations under
|
15
|
-
# the License.
|
16
|
-
#
|
17
|
-
#=============================================================================
|
18
|
-
|
19
|
-
module Geonames
|
20
|
-
class PostalCodeSearchCriteria
|
21
|
-
|
22
|
-
attr :postal_code
|
23
|
-
attr :place_name
|
24
|
-
attr :country_code
|
25
|
-
attr :latitude
|
26
|
-
attr :longitude
|
27
|
-
attr :style
|
28
|
-
attr :max_rows
|
29
|
-
attr :is_or_operator
|
30
|
-
attr :radius
|
31
|
-
|
32
|
-
attr_writer :postal_code, :place_name, :country_code
|
33
|
-
attr_writer :latitude, :longitude, :style
|
34
|
-
attr_writer :max_rows, :is_or_operator, :radius
|
35
|
-
|
36
|
-
def initialize
|
37
|
-
@is_or_operator = false
|
38
|
-
end
|
39
|
-
|
40
|
-
def to_query_params_string
|
41
|
-
url = ''
|
42
|
-
|
43
|
-
if !@postal_code.nil?
|
44
|
-
url = url + "&postalcode=" + CGI::escape( @postal_code )
|
45
|
-
end
|
46
|
-
|
47
|
-
if !@place_name.nil?
|
48
|
-
url = url + "&placename=" + CGI::escape( @place_name )
|
49
|
-
end
|
50
|
-
|
51
|
-
if !@latitude.nil?
|
52
|
-
url = url + "&lat" + CGI::escape( @latitude )
|
53
|
-
end
|
54
|
-
|
55
|
-
if !@longitude.nil?
|
56
|
-
url = url + "&lng" + CGI::escape( @longitude )
|
57
|
-
end
|
58
|
-
|
59
|
-
if !@style.nil?
|
60
|
-
url = url + "&style" + CGI::escape( @style )
|
61
|
-
end
|
62
|
-
|
63
|
-
if !@country_code.nil?
|
64
|
-
url = url + "&country=" + CGI::escape( @country_code )
|
65
|
-
end
|
66
|
-
|
67
|
-
if !@max_rows.nil?
|
68
|
-
url = url + "&maxRows=" + CGI::escape( @max_rows )
|
69
|
-
end
|
70
|
-
|
71
|
-
if !@radius.nil?
|
72
|
-
url = url + "&radius=" + CGI::escape( @radius.to_s )
|
73
|
-
end
|
74
|
-
|
75
|
-
if @is_or_operator
|
76
|
-
url = url + "&operator=OR"
|
77
|
-
end
|
78
|
-
|
79
|
-
url
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
|
data/lib/toponym.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
#=============================================================================
|
2
|
-
#
|
3
|
-
# Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
6
|
-
# use this file except in compliance with the License. You may obtain a copy of
|
7
|
-
# the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
13
|
-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
14
|
-
# License for the specific language governing permissions and limitations under
|
15
|
-
# the License.
|
16
|
-
#
|
17
|
-
#=============================================================================
|
18
|
-
|
19
|
-
module Geonames
|
20
|
-
class Toponym
|
21
|
-
|
22
|
-
attr :geoname_id
|
23
|
-
attr :name
|
24
|
-
attr :alternate_names
|
25
|
-
attr :country_code
|
26
|
-
attr :country_name
|
27
|
-
attr :population
|
28
|
-
attr :elevation
|
29
|
-
attr :feature_class
|
30
|
-
attr :feature_class_name
|
31
|
-
attr :feature_code
|
32
|
-
attr :feature_code_name
|
33
|
-
attr :latitude
|
34
|
-
attr :longitude
|
35
|
-
attr :distance
|
36
|
-
|
37
|
-
attr_writer :geoname_id, :name, :alternate_names, :country_code
|
38
|
-
attr_writer :country_name, :population, :elevation, :feature_class
|
39
|
-
attr_writer :feature_class_name, :feature_code,:feature_code_name
|
40
|
-
attr_writer :latitude, :longitude, :distance
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
|
@@ -1,44 +0,0 @@
|
|
1
|
-
#=============================================================================
|
2
|
-
#
|
3
|
-
# Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
6
|
-
# use this file except in compliance with the License. You may obtain a copy of
|
7
|
-
# the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
13
|
-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
14
|
-
# License for the specific language governing permissions and limitations under
|
15
|
-
# the License.
|
16
|
-
#
|
17
|
-
#=============================================================================
|
18
|
-
|
19
|
-
module Geonames
|
20
|
-
class ToponymSearchCriteria
|
21
|
-
|
22
|
-
attr :q
|
23
|
-
attr :country_code
|
24
|
-
attr :name
|
25
|
-
attr :name_equals
|
26
|
-
attr :name_starts_with
|
27
|
-
attr :tag
|
28
|
-
attr :language
|
29
|
-
attr :style
|
30
|
-
attr :feature_class
|
31
|
-
attr :feature_codes
|
32
|
-
attr :admin_code_1
|
33
|
-
attr :max_rows
|
34
|
-
attr :start_row
|
35
|
-
|
36
|
-
attr_writer :q, :country_code, :name, :name_equals
|
37
|
-
attr_writer :name_starts_with, :tag, :language, :style
|
38
|
-
attr_writer :feature_class, :feature_codes, :admin_code_1
|
39
|
-
attr_writer :max_rows, :start_row
|
40
|
-
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
|
data/lib/web_service.rb
DELETED
@@ -1,493 +0,0 @@
|
|
1
|
-
#=============================================================================
|
2
|
-
#
|
3
|
-
# Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
|
4
|
-
# Contributions by Andrew Turner, High Earth Orbit
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
7
|
-
# use this file except in compliance with the License. You may obtain a copy of
|
8
|
-
# the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
14
|
-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
15
|
-
# License for the specific language governing permissions and limitations under
|
16
|
-
# the License.
|
17
|
-
#
|
18
|
-
#=============================================================================
|
19
|
-
|
20
|
-
module Geonames
|
21
|
-
class WebService
|
22
|
-
def WebService.get_element_child_text( element, child )
|
23
|
-
if !element.elements[child].nil?
|
24
|
-
element.elements[child][0].to_s
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def WebService.get_element_child_float( element, child )
|
29
|
-
if !element.elements[child].nil?
|
30
|
-
element.elements[child][0].to_s.to_f
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def WebService.get_element_child_int( element, child )
|
35
|
-
if !element.elements[child].nil?
|
36
|
-
element.elements[child][0].to_s.to_i
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def WebService.element_to_postal_code ( element )
|
41
|
-
postal_code = PostalCode.new
|
42
|
-
|
43
|
-
postal_code.admin_code_1 = WebService::get_element_child_text( element, 'adminCode1' )
|
44
|
-
postal_code.admin_code_2 = WebService::get_element_child_text( element, 'adminCode2' )
|
45
|
-
postal_code.admin_name_1 = WebService::get_element_child_text( element, 'adminName1' )
|
46
|
-
postal_code.admin_name_2 = WebService::get_element_child_text( element, 'adminName2' )
|
47
|
-
postal_code.country_code = WebService::get_element_child_text( element, 'countryCode' )
|
48
|
-
postal_code.distance = WebService::get_element_child_float( element, 'distance' )
|
49
|
-
postal_code.longitude = WebService::get_element_child_float( element, 'lat' )
|
50
|
-
postal_code.latitude = WebService::get_element_child_float( element, 'lng' )
|
51
|
-
postal_code.place_name = WebService::get_element_child_text( element, 'name' )
|
52
|
-
postal_code.postal_code = WebService::get_element_child_text( element, 'postalcode' )
|
53
|
-
|
54
|
-
return postal_code
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
def WebService.element_to_wikipedia_article ( element )
|
59
|
-
article = WikipediaArticle.new
|
60
|
-
|
61
|
-
article.language = WebService::get_element_child_text( element, 'lang' )
|
62
|
-
article.title = WebService::get_element_child_text( element, 'title' )
|
63
|
-
article.summary = WebService::get_element_child_text( element, 'summary' )
|
64
|
-
article.wikipedia_url = WebService::get_element_child_text( element, 'wikipediaUrl' )
|
65
|
-
article.feature = WebService::get_element_child_text( element, 'feature' )
|
66
|
-
article.population = WebService::get_element_child_text( element, 'population' )
|
67
|
-
article.elevation = WebService::get_element_child_text( element, 'elevation' )
|
68
|
-
article.latitude = WebService::get_element_child_float( element, 'lat' )
|
69
|
-
article.longitude = WebService::get_element_child_float( element, 'lng' )
|
70
|
-
article.thumbnail_img = WebService::get_element_child_text( element, 'thumbnailImg' )
|
71
|
-
article.distance = WebService::get_element_child_float( element, 'distance' )
|
72
|
-
|
73
|
-
return article
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
def WebService.element_to_toponym ( element )
|
78
|
-
toponym = Toponym.new
|
79
|
-
|
80
|
-
toponym.name = WebService::get_element_child_text( element, 'name' )
|
81
|
-
toponym.alternate_names = WebService::get_element_child_text( element, 'alternateNames' )
|
82
|
-
toponym.latitude = WebService::get_element_child_float( element, 'lat' )
|
83
|
-
toponym.longitude = WebService::get_element_child_float( element, 'lng' )
|
84
|
-
toponym.geoname_id = WebService::get_element_child_text( element, 'geonameId' )
|
85
|
-
toponym.country_code = WebService::get_element_child_text( element, 'countryCode' )
|
86
|
-
toponym.country_name = WebService::get_element_child_text( element, 'countryName' )
|
87
|
-
toponym.feature_class = WebService::get_element_child_text( element, 'fcl' )
|
88
|
-
toponym.feature_code = WebService::get_element_child_text( element, 'fcode' )
|
89
|
-
toponym.feature_class_name = WebService::get_element_child_text( element, 'fclName' )
|
90
|
-
toponym.feature_code_name = WebService::get_element_child_text( element, 'fCodeName' )
|
91
|
-
toponym.population = WebService::get_element_child_int( element, 'population' )
|
92
|
-
toponym.elevation = WebService::get_element_child_text( element, 'elevation' )
|
93
|
-
toponym.distance = WebService::get_element_child_float( element, 'distance' )
|
94
|
-
|
95
|
-
return toponym
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
def WebService.element_to_intersection ( element )
|
100
|
-
intersection = Intersection.new
|
101
|
-
|
102
|
-
intersection.street_1 = WebService::get_element_child_text( element, 'street1' )
|
103
|
-
intersection.street_2 = WebService::get_element_child_text( element, 'street2' )
|
104
|
-
intersection.admin_code_1 = WebService::get_element_child_text( element, 'adminCode1' )
|
105
|
-
intersection.admin_code_1 = WebService::get_element_child_text( element, 'adminCode1' )
|
106
|
-
intersection.admin_code_2 = WebService::get_element_child_text( element, 'adminCode2' )
|
107
|
-
intersection.admin_name_1 = WebService::get_element_child_text( element, 'adminName1' )
|
108
|
-
intersection.admin_name_2 = WebService::get_element_child_text( element, 'adminName2' )
|
109
|
-
intersection.country_code = WebService::get_element_child_text( element, 'countryCode' )
|
110
|
-
intersection.distance = WebService::get_element_child_float( element, 'distance' )
|
111
|
-
intersection.longitude = WebService::get_element_child_float( element, 'lat' )
|
112
|
-
intersection.latitude = WebService::get_element_child_float( element, 'lng' )
|
113
|
-
intersection.place_name = WebService::get_element_child_text( element, 'name' )
|
114
|
-
intersection.postal_code = WebService::get_element_child_text( element, 'postalcode' )
|
115
|
-
|
116
|
-
return intersection
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
def WebService.postal_code_search( postal_code, place_name, country_code )
|
121
|
-
postal_code_sc = PostalCodeSearchCriteria.new
|
122
|
-
postal_code_sc.postal_code = postal_code
|
123
|
-
postal_code_sc.place_name = place_name
|
124
|
-
postal_code_sc.coutry_code = country_code
|
125
|
-
|
126
|
-
WebService.postal_code_search postal_code_sc
|
127
|
-
end
|
128
|
-
|
129
|
-
def WebService.postal_code_search( search_criteria )
|
130
|
-
# postal codes to reutrn
|
131
|
-
postal_codes = Array.new
|
132
|
-
|
133
|
-
url = Geonames::GEONAMES_SERVER + "/postalCodeSearch?a=a"
|
134
|
-
url = url + search_criteria.to_query_params_string
|
135
|
-
|
136
|
-
uri = URI.parse(url)
|
137
|
-
|
138
|
-
req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
|
139
|
-
|
140
|
-
res = Net::HTTP.start( uri.host, uri.port ) { |http|
|
141
|
-
http.request( req )
|
142
|
-
}
|
143
|
-
|
144
|
-
doc = REXML::Document.new res.body
|
145
|
-
|
146
|
-
doc.elements.each("geonames/code") do |element|
|
147
|
-
postal_codes << WebService::element_to_postal_code( element )
|
148
|
-
end
|
149
|
-
|
150
|
-
postal_codes
|
151
|
-
|
152
|
-
end
|
153
|
-
|
154
|
-
def WebService.find_nearby_postal_codes( search_criteria )
|
155
|
-
# postal codes to reutrn
|
156
|
-
postal_codes = Array.new
|
157
|
-
|
158
|
-
url = Geonames::GEONAMES_SERVER + "/findNearbyPostalCodes?a=a"
|
159
|
-
url = url + search_criteria.to_query_params_string
|
160
|
-
|
161
|
-
uri = URI.parse(url)
|
162
|
-
|
163
|
-
req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
|
164
|
-
|
165
|
-
res = Net::HTTP.start( uri.host, uri.port ) { |http|
|
166
|
-
http.request( req )
|
167
|
-
}
|
168
|
-
|
169
|
-
doc = REXML::Document.new res.body
|
170
|
-
|
171
|
-
doc.elements.each("geonames/code") do |element|
|
172
|
-
postal_codes << WebService::element_to_postal_code( element )
|
173
|
-
end
|
174
|
-
|
175
|
-
postal_codes
|
176
|
-
|
177
|
-
end
|
178
|
-
|
179
|
-
def WebService.find_nearby_place_name( lat, long )
|
180
|
-
places = Array.new
|
181
|
-
|
182
|
-
url = Geonames::GEONAMES_SERVER + "/findNearbyPlaceName?a=a"
|
183
|
-
|
184
|
-
url = url + "&lat=" + lat.to_s
|
185
|
-
url = url + "&lng=" + long.to_s
|
186
|
-
|
187
|
-
uri = URI.parse(url)
|
188
|
-
|
189
|
-
req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
|
190
|
-
|
191
|
-
res = Net::HTTP.start( uri.host, uri.port ) { |http|
|
192
|
-
http.request( req )
|
193
|
-
}
|
194
|
-
|
195
|
-
doc = REXML::Document.new res.body
|
196
|
-
|
197
|
-
doc.elements.each("geonames/geoname") do |element|
|
198
|
-
|
199
|
-
places << WebService::element_to_toponym( element )
|
200
|
-
|
201
|
-
end
|
202
|
-
|
203
|
-
return places
|
204
|
-
|
205
|
-
end
|
206
|
-
|
207
|
-
def WebService.find_nearest_intersection( lat, long )
|
208
|
-
|
209
|
-
url = Geonames::GEONAMES_SERVER + "/findNearestIntersection?a=a"
|
210
|
-
|
211
|
-
url = url + "&lat=" + lat.to_s
|
212
|
-
url = url + "&lng=" + long.to_s
|
213
|
-
|
214
|
-
uri = URI.parse(url)
|
215
|
-
|
216
|
-
req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
|
217
|
-
|
218
|
-
res = Net::HTTP.start( uri.host, uri.port ) { |http|
|
219
|
-
http.request( req )
|
220
|
-
}
|
221
|
-
|
222
|
-
doc = REXML::Document.new res.body
|
223
|
-
|
224
|
-
intersection = []
|
225
|
-
doc.elements.each("geonames/intersection") do |element|
|
226
|
-
|
227
|
-
intersection = WebService::element_to_intersection( element )
|
228
|
-
|
229
|
-
end
|
230
|
-
|
231
|
-
return intersection
|
232
|
-
|
233
|
-
end
|
234
|
-
|
235
|
-
def WebService.timezone( lat, long )
|
236
|
-
timezone = Timezone.new
|
237
|
-
|
238
|
-
url = Geonames::GEONAMES_SERVER + "/timezone?a=a"
|
239
|
-
|
240
|
-
url = url + "&lat=" + lat.to_s
|
241
|
-
url = url + "&lng=" + long.to_s
|
242
|
-
|
243
|
-
uri = URI.parse(url)
|
244
|
-
|
245
|
-
req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
|
246
|
-
|
247
|
-
res = Net::HTTP.start( uri.host, uri.port ) { |http|
|
248
|
-
http.request( req )
|
249
|
-
}
|
250
|
-
|
251
|
-
doc = REXML::Document.new res.body
|
252
|
-
|
253
|
-
doc.elements.each("geonames/timezone") do |element|
|
254
|
-
timezone.timezone_id = WebService::get_element_child_text( element, 'timezoneId' )
|
255
|
-
timezone.gmt_offset = WebService::get_element_child_float( element, 'gmtOffset' )
|
256
|
-
timezone.dst_offset = WebService::get_element_child_float( element, 'dstOffset' )
|
257
|
-
end
|
258
|
-
|
259
|
-
return timezone
|
260
|
-
|
261
|
-
end
|
262
|
-
|
263
|
-
def WebService.findNearbyWikipedia( hashes )
|
264
|
-
# here for backwards compatibility
|
265
|
-
WebService.find_nearby_wikipedia( hashes )
|
266
|
-
end
|
267
|
-
|
268
|
-
def WebService.find_nearby_wikipedia( hashes )
|
269
|
-
articles = Array.new
|
270
|
-
|
271
|
-
lat = hashes[:lat]
|
272
|
-
long = hashes[:long]
|
273
|
-
lang = hashes[:lang]
|
274
|
-
radius = hashes[:radius]
|
275
|
-
max_rows = hashes[:max_rows]
|
276
|
-
country = hashes[:country]
|
277
|
-
postalcode = hashes[:postalcode]
|
278
|
-
q = hashes[:q]
|
279
|
-
|
280
|
-
url = Geonames::GEONAMES_SERVER + "/findNearbyWikipedia?a=a"
|
281
|
-
|
282
|
-
if !lat.nil? && !long.nil?
|
283
|
-
url = url + "&lat=" + lat.to_s
|
284
|
-
url = url + "&lng=" + long.to_s
|
285
|
-
url = url + "&radius=" + radius.to_s unless radius.nil?
|
286
|
-
url = url + "&max_rows=" + max_rows.to_s unless max_rows.nil?
|
287
|
-
|
288
|
-
elsif !q.nil?
|
289
|
-
url = url + "&q=" + q
|
290
|
-
url = url + "&radius=" + radius.to_s unless radius.nil?
|
291
|
-
url = url + "&max_rows=" + max_rows.to_s unless max_rows.nil?
|
292
|
-
end
|
293
|
-
|
294
|
-
uri = URI.parse(url)
|
295
|
-
|
296
|
-
req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
|
297
|
-
|
298
|
-
res = Net::HTTP.start( uri.host, uri.port ) { |http|
|
299
|
-
http.request( req )
|
300
|
-
}
|
301
|
-
|
302
|
-
doc = REXML::Document.new res.body
|
303
|
-
|
304
|
-
doc.elements.each("geonames/entry") do |element|
|
305
|
-
articles << WebService::element_to_wikipedia_article( element )
|
306
|
-
end
|
307
|
-
|
308
|
-
return articles
|
309
|
-
|
310
|
-
end
|
311
|
-
|
312
|
-
def WebService.findBoundingBoxWikipedia( hashes )
|
313
|
-
# here for backwards compatibility
|
314
|
-
WebService.find_bounding_box_wikipedia( hashes )
|
315
|
-
end
|
316
|
-
|
317
|
-
def WebService.find_bounding_box_wikipedia( hashes )
|
318
|
-
articles = Array.new
|
319
|
-
|
320
|
-
north = hashes[:north]
|
321
|
-
east = hashes[:east]
|
322
|
-
south = hashes[:south]
|
323
|
-
west = hashes[:west]
|
324
|
-
lang = hashes[:lang]
|
325
|
-
radius = hashes[:radius]
|
326
|
-
max_rows = hashes[:max_rows]
|
327
|
-
country = hashes[:country]
|
328
|
-
postalcode = hashes[:postalcode]
|
329
|
-
q = hashes[:q]
|
330
|
-
|
331
|
-
url = Geonames::GEONAMES_SERVER + "/wikipediaBoundingBox?a=a"
|
332
|
-
|
333
|
-
url = url + "&north=" + north.to_s
|
334
|
-
url = url + "&east=" + east.to_s
|
335
|
-
url = url + "&south=" + south.to_s
|
336
|
-
url = url + "&west=" + west.to_s
|
337
|
-
url = url + "&radius=" + radius.to_s unless radius.nil?
|
338
|
-
url = url + "&max_rows=" + max_rows.to_s unless max_rows.nil?
|
339
|
-
|
340
|
-
uri = URI.parse(url)
|
341
|
-
|
342
|
-
req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
|
343
|
-
|
344
|
-
res = Net::HTTP.start( uri.host, uri.port ) { |http|
|
345
|
-
http.request( req )
|
346
|
-
}
|
347
|
-
|
348
|
-
doc = REXML::Document.new res.body
|
349
|
-
|
350
|
-
doc.elements.each("geonames/entry") do |element|
|
351
|
-
articles << WebService::element_to_wikipedia_article( element )
|
352
|
-
end
|
353
|
-
|
354
|
-
return articles
|
355
|
-
|
356
|
-
end
|
357
|
-
|
358
|
-
def WebService.country_subdivision ( lat, long )
|
359
|
-
country_subdivision = CountrySubdivision.new
|
360
|
-
|
361
|
-
url = Geonames::GEONAMES_SERVER + "/countrySubdivision?a=a"
|
362
|
-
|
363
|
-
url = url + "&lat=" + lat.to_s
|
364
|
-
url = url + "&lng=" + long.to_s
|
365
|
-
|
366
|
-
uri = URI.parse(url)
|
367
|
-
|
368
|
-
req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
|
369
|
-
|
370
|
-
res = Net::HTTP.start( uri.host, uri.port ) { |http|
|
371
|
-
http.request( req )
|
372
|
-
}
|
373
|
-
|
374
|
-
doc = REXML::Document.new res.body
|
375
|
-
|
376
|
-
doc.elements.each("geonames/countrySubdivision") do |element|
|
377
|
-
country_subdivision.country_code = WebService::get_element_child_text( element, 'countryCode' )
|
378
|
-
country_subdivision.country_name = WebService::get_element_child_text( element, 'countryName' )
|
379
|
-
country_subdivision.admin_code_1 = WebService::get_element_child_text( element, 'adminCode1' )
|
380
|
-
country_subdivision.admin_name_1 = WebService::get_element_child_text( element, 'adminName1' )
|
381
|
-
end
|
382
|
-
|
383
|
-
return country_subdivision
|
384
|
-
|
385
|
-
end
|
386
|
-
|
387
|
-
def WebService.country_code ( lat, long )
|
388
|
-
|
389
|
-
url = Geonames::GEONAMES_SERVER + "/countrycode?a=a"
|
390
|
-
|
391
|
-
url = url + "&lat=" + lat.to_s
|
392
|
-
url = url + "&lng=" + long.to_s
|
393
|
-
|
394
|
-
uri = URI.parse(url)
|
395
|
-
|
396
|
-
req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
|
397
|
-
|
398
|
-
res = Net::HTTP.start( uri.host, uri.port ) { |http|
|
399
|
-
http.request( req )
|
400
|
-
}
|
401
|
-
|
402
|
-
doc = REXML::Document.new res.body
|
403
|
-
|
404
|
-
return res.body.strip
|
405
|
-
|
406
|
-
end
|
407
|
-
|
408
|
-
def WebService.search( search_criteria )
|
409
|
-
#toponym search results to return
|
410
|
-
toponym_sr = ToponymSearchResult.new
|
411
|
-
|
412
|
-
url = Geonames::GEONAMES_SERVER + "/search?a=a"
|
413
|
-
|
414
|
-
if !search_criteria.q.nil?
|
415
|
-
url = url + "&q=" + CGI::escape( search_criteria.q )
|
416
|
-
end
|
417
|
-
|
418
|
-
if !search_criteria.name_equals.nil?
|
419
|
-
url = url + "&name_equals=" + CGI::escape( search_criteria.name_equals )
|
420
|
-
end
|
421
|
-
|
422
|
-
if !search_criteria.name_starts_with.nil?
|
423
|
-
url = url + "&name_startsWith=" + CGI::escape( search_criteria.name_starts_with )
|
424
|
-
end
|
425
|
-
|
426
|
-
if !search_criteria.name.nil?
|
427
|
-
url = url + "&name=" + CGI::escape( search_criteria.name )
|
428
|
-
end
|
429
|
-
|
430
|
-
if !search_criteria.tag.nil?
|
431
|
-
url = url + "&tag=" + CGI::escape( search_criteria.tag )
|
432
|
-
end
|
433
|
-
|
434
|
-
if !search_criteria.country_code.nil?
|
435
|
-
url = url + "&country=" + CGI::escape( search_criteria.country_code )
|
436
|
-
end
|
437
|
-
|
438
|
-
if !search_criteria.admin_code_1.nil?
|
439
|
-
url = url + "&adminCode1=" + CGI::escape( search_criteria.admin_code_1 )
|
440
|
-
end
|
441
|
-
|
442
|
-
if !search_criteria.language.nil?
|
443
|
-
url = url + "&lang=" + CGI::escape( search_criteria.language )
|
444
|
-
end
|
445
|
-
|
446
|
-
if !search_criteria.feature_class.nil?
|
447
|
-
url = url + "&featureClass=" + CGI::escape( search_criteria.feature_class )
|
448
|
-
end
|
449
|
-
|
450
|
-
if !search_criteria.feature_codes.nil?
|
451
|
-
for feature_code in search_criteria.feature_codes
|
452
|
-
url = url + "&fcode=" + CGI::escape( feature_code )
|
453
|
-
end
|
454
|
-
end
|
455
|
-
|
456
|
-
if !search_criteria.max_rows.nil?
|
457
|
-
url = url + "&maxRows=" + CGI::escape( search_criteria.max_rows )
|
458
|
-
end
|
459
|
-
|
460
|
-
if !search_criteria.start_row.nil?
|
461
|
-
url = url + "&startRow=" + CGI::escape( search_criteria.start_row )
|
462
|
-
end
|
463
|
-
|
464
|
-
if !search_criteria.style.nil?
|
465
|
-
url = url + "&style=" + CGI::escape( search_criteria.style )
|
466
|
-
end
|
467
|
-
|
468
|
-
uri = URI.parse(url)
|
469
|
-
|
470
|
-
req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
|
471
|
-
|
472
|
-
res = Net::HTTP.start( uri.host, uri.port ) { |http|
|
473
|
-
http.request( req )
|
474
|
-
}
|
475
|
-
|
476
|
-
doc = REXML::Document.new res.body
|
477
|
-
|
478
|
-
toponym_sr.total_results_count = doc.elements["geonames/totalResultsCount"].text
|
479
|
-
|
480
|
-
doc.elements.each("geonames/geoname") do |element|
|
481
|
-
|
482
|
-
toponym_sr.toponyms << WebService::element_to_toponym( element )
|
483
|
-
|
484
|
-
end
|
485
|
-
|
486
|
-
return toponym_sr
|
487
|
-
end
|
488
|
-
|
489
|
-
end
|
490
|
-
end
|
491
|
-
|
492
|
-
#alias WebService.find_nearby_wikipedia findNearbyWikipedia
|
493
|
-
#alias find_bounding_box_wikipedia findBoundingBoxWikipedia
|