geonames 0.2.0 → 0.2.1
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/geonames-0.2.0.gem +0 -0
- data/geonames.gemspec +1 -1
- data/lib/geonames.rb +1 -0
- data/lib/intersection.rb +18 -1
- data/lib/main.rb +9 -4
- data/lib/web_service.rb +69 -10
- metadata +2 -2
data/geonames-0.2.0.gem
CHANGED
Binary file
|
data/geonames.gemspec
CHANGED
data/lib/geonames.rb
CHANGED
data/lib/intersection.rb
CHANGED
@@ -18,7 +18,24 @@
|
|
18
18
|
|
19
19
|
module Geonames
|
20
20
|
class Intersection
|
21
|
-
|
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
|
22
39
|
end
|
23
40
|
end
|
24
41
|
|
data/lib/main.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#=============================================================================
|
2
2
|
#
|
3
3
|
# Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
|
4
|
+
# Contributions by Andrew Turner, High Earth Orbit
|
4
5
|
#
|
5
6
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
6
7
|
# use this file except in compliance with the License. You may obtain a copy of
|
@@ -19,15 +20,19 @@
|
|
19
20
|
require 'geonames'
|
20
21
|
require 'pp'
|
21
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
|
+
|
22
28
|
# get wikipedia articles by lat / long
|
23
|
-
|
24
|
-
|
29
|
+
articles_nearby = Geonames::WebService.find_nearby_wikipedia :lat => 43.900120387, :long => -78.882869834
|
30
|
+
p articles_nearby
|
25
31
|
|
26
32
|
# get wikipedia articles by bounding box
|
27
|
-
articles_nearby = Geonames::WebService.
|
33
|
+
articles_nearby = Geonames::WebService.find_bounding_box_wikipedia :north => 43.900120387, :east => -78.882869834, :south => 43.82, :west => 79.0
|
28
34
|
p articles_nearby
|
29
35
|
|
30
|
-
Process.exit
|
31
36
|
# get list of places near by longitude/longitude location
|
32
37
|
places_nearby = Geonames::WebService.find_nearby_place_name 43.900120387, -78.882869834
|
33
38
|
p places_nearby
|
data/lib/web_service.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#=============================================================================
|
2
2
|
#
|
3
3
|
# Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
|
4
|
+
# Contributions by Andrew Turner, High Earth Orbit
|
4
5
|
#
|
5
6
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
6
7
|
# use this file except in compliance with the License. You may obtain a copy of
|
@@ -16,7 +17,6 @@
|
|
16
17
|
#
|
17
18
|
#=============================================================================
|
18
19
|
|
19
|
-
|
20
20
|
module Geonames
|
21
21
|
class WebService
|
22
22
|
def WebService.get_element_child_text( element, child )
|
@@ -69,11 +69,11 @@ module Geonames
|
|
69
69
|
article.longitude = WebService::get_element_child_float( element, 'lng' )
|
70
70
|
article.thumbnail_img = WebService::get_element_child_text( element, 'thumbnailImg' )
|
71
71
|
article.distance = WebService::get_element_child_float( element, 'distance' )
|
72
|
-
|
72
|
+
|
73
73
|
return article
|
74
74
|
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
def WebService.element_to_toponym ( element )
|
78
78
|
toponym = Toponym.new
|
79
79
|
|
@@ -96,6 +96,27 @@ module Geonames
|
|
96
96
|
|
97
97
|
end
|
98
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
|
+
|
99
120
|
def WebService.postal_code_search( postal_code, place_name, country_code )
|
100
121
|
postal_code_sc = PostalCodeSearchCriteria.new
|
101
122
|
postal_code_sc.postal_code = postal_code
|
@@ -183,6 +204,34 @@ module Geonames
|
|
183
204
|
|
184
205
|
end
|
185
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
|
+
|
186
235
|
def WebService.timezone( lat, long )
|
187
236
|
timezone = Timezone.new
|
188
237
|
|
@@ -212,8 +261,13 @@ module Geonames
|
|
212
261
|
end
|
213
262
|
|
214
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 )
|
215
269
|
articles = Array.new
|
216
|
-
|
270
|
+
|
217
271
|
lat = hashes[:lat]
|
218
272
|
long = hashes[:long]
|
219
273
|
lang = hashes[:lang]
|
@@ -254,10 +308,15 @@ module Geonames
|
|
254
308
|
return articles
|
255
309
|
|
256
310
|
end
|
257
|
-
|
311
|
+
|
258
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 )
|
259
318
|
articles = Array.new
|
260
|
-
|
319
|
+
|
261
320
|
north = hashes[:north]
|
262
321
|
east = hashes[:east]
|
263
322
|
south = hashes[:south]
|
@@ -294,7 +353,7 @@ module Geonames
|
|
294
353
|
|
295
354
|
return articles
|
296
355
|
|
297
|
-
end
|
356
|
+
end
|
298
357
|
|
299
358
|
def WebService.country_subdivision ( lat, long )
|
300
359
|
country_subdivision = CountrySubdivision.new
|
@@ -426,9 +485,9 @@ module Geonames
|
|
426
485
|
|
427
486
|
return toponym_sr
|
428
487
|
end
|
429
|
-
|
430
|
-
|
488
|
+
|
431
489
|
end
|
432
490
|
end
|
433
491
|
|
434
|
-
|
492
|
+
#alias WebService.find_nearby_wikipedia findNearbyWikipedia
|
493
|
+
#alias find_bounding_box_wikipedia findBoundingBoxWikipedia
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: geonames
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2007-04-
|
6
|
+
version: 0.2.1
|
7
|
+
date: 2007-04-02 00:00:00 -04:00
|
8
8
|
summary: Ruby library for Geonames Web Services (http://www.geonames.org/export/)
|
9
9
|
require_paths:
|
10
10
|
- lib
|