marco-ruby-geonames 0.2.7

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MGU3Y2I0NGQzNjZjM2ZkMzI2MGJmNTZkYjM2ODMxNTc3YjhkMDQ2Mw==
5
+ data.tar.gz: !binary |-
6
+ ZmJkZDA5MGI3ZTdjY2RlNTAzNjFlZmJkMGY2YzM2ZGE5YjEzZTFjNA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ Yjk5NGM2NzY1ZGI3MmU0YWVhMWM2NDRmZGU0NjhlMzJkY2M4MTUwOGMxMDIy
10
+ MGYzNDQ4NWEwODUzMWExYWJkOTUwYjIwOGQxZGViYjYwZWFlNThkZTJhMTcx
11
+ MGRiMTRmZTYwMDA3MTlmODc0Yjk0Mzk4ZWQ5Nzk0ZjM5NDUwYjY=
12
+ data.tar.gz: !binary |-
13
+ MGNmYTNkOTEzZTllNTUyOWRlZDk0YTg1YmJkNzlhMzg3ODZmZDNiN2Y2ZTE0
14
+ YzM0OGUzYTEwZDAxYWUwZmJjZTA4ZGY5YzAxYzJmMmNiZjM0MWUzN2IxNDky
15
+ ZGM3NmZiNWU0MGUxY2JiNWFjNTc2YTcwOWUxYTNhOTdhY2ExYzM=
@@ -0,0 +1,82 @@
1
+ # Geonames Ruby API
2
+
3
+ Ruby library for [Geonames Web Services](http://www.geonames.org/export/)
4
+
5
+ Created by [TouchBase Counsulting](http://www.tbcn.ca/geonames) to support GIS processes for [Carpool Connect](http://www.carpoolconnect.com/). Inspired by the Geonames [Java Client API library](http://www.geonames.org/source-code/).
6
+
7
+ ## Installing ruby-geonames
8
+
9
+ Install from the command line:
10
+
11
+ sudo gem install elecnix-ruby-geonames
12
+
13
+ ## Examples
14
+
15
+ The following exercises several of the Geonames web services, [full list of services](http://www.geonames.org/export/).
16
+
17
+ **Load the the geonames API**
18
+
19
+ require 'geonames'
20
+
21
+ **get list of places near by longitude/longitude location**
22
+
23
+ places_nearby = Geonames::WebService.find_nearby_place_name 43.900120387, -78.882869834
24
+ p places_nearby
25
+
26
+ outputs:
27
+
28
+ `[#<Geonames::Toponym:0x6c8c98 @population=nil, @geoname_id='6094578', @longitude=-78.849568878, @feature_class_name=nil, @country_name='Canada', @latitude=43.900120387, @feature_class='P', @country_code='CA', @name='Oshawa', @feature_code_name=nil, @elevation=nil, @distance=2.6679930307932, @alternate_names=nil, @feature_code='PPL'>]`
29
+
30
+ **get timezone for longitude/longitude location**
31
+
32
+ timezone = Geonames::WebService.timezone 43.900120387, -78.882869834
33
+ p timezone
34
+
35
+ **get country code for longitude/longitude location**
36
+
37
+ country_code = Geonames::WebService.country_code 43.900120387, -78.882869834
38
+ p country_code
39
+
40
+ **get country sub-division info for longitude/longitude location**
41
+
42
+ country_subdivision = Geonames::WebService.country_subdivision 43.900120387, -78.882869834
43
+ p country_subdivision
44
+
45
+ **get postal codes for a given location**
46
+
47
+ postal_code_sc = Geonames::PostalCodeSearchCriteria.new
48
+ postal_code_sc.place_name = "Oshawa"
49
+ postal_codes = Geonames::WebService.postal_code_search postal_code_sc
50
+ p postal_codes
51
+
52
+ **get nearby postal codes for a place name**
53
+
54
+ postal_code_sc = Geonames::PostalCodeSearchCriteria.new
55
+ postal_code_sc.place_name = "Oshawa"
56
+ postal_codes_nearby = Geonames::WebService.find_nearby_postal_codes postal_code_sc
57
+ p postal_codes_nearby
58
+
59
+ ## Language Support
60
+
61
+ Geonames uses 'en' as the default locale. You can change the requested language like this:
62
+
63
+ Geonames.lang = 'de'
64
+
65
+ In a Rails application, you could set the language from the I18n.locale:
66
+
67
+ Geonames.lang = I18n.locale
68
+
69
+ ## Commercial Service Support
70
+
71
+ If you use the commercial service, you should put something like this in your configuration:
72
+
73
+ Geonames.username = 'username'
74
+ Geonames.base_url = 'http://ws.geonames.net'
75
+
76
+ In a Rails application, this could go into `config/initializers/geonames.rb`.
77
+
78
+ # Contributors
79
+
80
+ 1. Adam Wisniewski
81
+ 2. Nicolas Marchildon (elecnix)
82
+
@@ -0,0 +1,25 @@
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 Address
21
+
22
+ end
23
+ end
24
+
25
+
@@ -0,0 +1,18 @@
1
+ module Geonames
2
+ class BoundingBox
3
+ attr_reader :north_point, :south_point, :east_point, :west_point
4
+ attr_writer :north_point, :south_point, :east_point, :west_point
5
+
6
+ def initialize(north=0.0, south=0.0, east=0.0, west=0.0)
7
+ self.north_point = north
8
+ self.south_point = south
9
+ self.east_point = east
10
+ self.west_point = west
11
+ end
12
+
13
+ def contains?(point)
14
+ #todo implement me
15
+ return false
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,36 @@
1
+ module Geonames
2
+ class CountryInfo
3
+ attr_reader :country_code, :country_name, :iso_numeric, :iso_alpha_3
4
+ attr_reader :fips_code, :continent, :capital, :area_sq_km, :population
5
+ attr_reader :currency_code, :geoname_id
6
+
7
+ attr_writer :country_code, :country_name, :iso_numeric, :iso_alpha_3
8
+ attr_writer :fips_code, :continent, :capital, :area_sq_km, :population
9
+ attr_writer :currency_code, :geoname_id
10
+
11
+ def initialize
12
+ @langs = []
13
+ @bounding_box = BoundingBox.new()
14
+ end
15
+
16
+ def bounding_box
17
+ return @bounding_box
18
+ end
19
+
20
+ def bounding_box=(new_bb)
21
+ @bounding_box = new_bb
22
+ end
23
+
24
+ def set_bounding_box(north, south, east, west)
25
+ @bounding_box = BoundingBox.new(north, south, east, west)
26
+ end
27
+
28
+ def languages
29
+ return @langs
30
+ end
31
+
32
+ def languages=(new_langs)
33
+ @langs = new_langs
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,35 @@
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 CountrySubdivision
21
+ attr :country_code
22
+ attr :country_name
23
+ attr :admin_code_1
24
+ attr :admin_name_1
25
+ attr :code_fips
26
+ attr :code_iso
27
+
28
+ attr_writer :country_code, :country_name
29
+ attr_writer :admin_name_1, :admin_code_1
30
+ attr_writer :code_fips, :code_iso
31
+
32
+ end
33
+ end
34
+
35
+
@@ -0,0 +1,61 @@
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
+ require 'cgi'
20
+ require 'net/http'
21
+ require 'rexml/document'
22
+
23
+ require 'web_service'
24
+ require 'toponym'
25
+ require 'toponym_search_result'
26
+ require 'toponym_search_criteria'
27
+ require 'postal_code'
28
+ require 'postal_code_search_criteria'
29
+ require 'timezone'
30
+ require 'country_subdivision'
31
+ require 'wikipedia_article'
32
+ require 'intersection'
33
+
34
+ module Geonames
35
+ autoload :Config, 'geonames/config'
36
+
37
+ GEONAMES_SERVER = "http://ws.geonames.org"
38
+ USER_AGENT = "geonames ruby webservice client 0.1"
39
+
40
+ class << self
41
+
42
+ def config
43
+ Thread.current[:geonames_config] ||= Geonames::Config.new
44
+ end
45
+
46
+ %w(lang username base_url).each do |method|
47
+ module_eval <<-DELEGATORS, __FILE__, __LINE__ + 1
48
+ def #{method}
49
+ config.#{method}
50
+ end
51
+
52
+ def #{method}=(value)
53
+ config.#{method} = (value)
54
+ end
55
+ DELEGATORS
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+
@@ -0,0 +1,42 @@
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
+
@@ -0,0 +1,63 @@
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
+
@@ -0,0 +1,40 @@
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
+
@@ -0,0 +1,84 @@
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.to_s )
53
+ end
54
+
55
+ if !@longitude.nil?
56
+ url = url + "&lng=" + CGI::escape( @longitude.to_s )
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.to_s )
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
+