Class: GeoNames
- Inherits:
-
Object
- Object
- GeoNames
- Defined in:
- lib/geonames.rb
Defined Under Namespace
Classes: APIError
Constant Summary collapse
- OPTIONS =
{ host: 'api.geonames.org', time_format: '%Y-%m-%d %T %z', timezone: 'UTC', username: nil, }
- QUERY =
{}
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#uris ⇒ Object
readonly
Returns the value of attribute uris.
Instance Method Summary collapse
-
#astergdem(parameters = {}) ⇒ Object
Elevation - Aster Global Digital Elevation Model.
-
#children(parameters = {}) ⇒ Object
Returns the children for a given geonameId.
-
#cities(parameters = {}) ⇒ Object
Cities and Placenames.
-
#country_code(parameters = {}) ⇒ Object
The ISO country code of any given point.
-
#country_info(parameters = {}) ⇒ Object
Parameters : country (default = all countries) lang: ISO-639-1 language code (en,de,fr,it,es,…) (default = english).
-
#country_subdivision(parameters = {}) ⇒ Object
Country Subdivision / reverse geocoding The ISO country code and the administrative subdivision (state, province, …) of any given point.
-
#earthquakes(parameters = {}) ⇒ Object
Returns a list of recent earthquakes, ordered by magnitude.
-
#extended_find_nearby(parameters = {}) ⇒ Object
Returns the most detailed information available for the lat/lng query.
-
#find_near_by_weather(parameters = {}) ⇒ Object
Weather Station with most recent weather observation / reverse geocoding needs username.
-
#find_nearby(parameters = {}) ⇒ Object
Find nearby toponym.
-
#find_nearby_place_name(parameters = {}) ⇒ Object
Find nearby populated place / reverse geocoding Returns the closest populated place for the lat/lng query.
-
#find_nearby_postal_codes(parameters = {}) ⇒ Object
List of nearby postalcodes and places for the lat/lng query.
-
#find_nearby_streets(latitude, longitude) ⇒ Array
Returns the nearest street segments for the given latitude/longitude, this service is only available for the US.
-
#find_nearby_streets_osm(latitude, longitude) ⇒ Object
Find nearby street segments on OpenStreetMap for the given latitude/longitude.
-
#find_nearby_wikipedia(parameters = {}) ⇒ Object
Find nearby Wikipedia Entries / reverse geocoding.
-
#find_nearest_address(parameters = {}) ⇒ Object
Find nearest Address.
-
#find_nearest_intersection(parameters = {}) ⇒ Object
Find nearest Intersection.
-
#find_nearest_intersection_osm(parameters = {}) ⇒ Object
Find nearest street and crossing for a given latitude/longitude pair on OpenStreetMap.
-
#fix_datetime(hash) ⇒ Object
Utility method for some queries that return times, we convert them to real Time instances with proper UTC timezone.
-
#get(parameters) ⇒ Object
Returns the attribute of the geoNames feature with the given geonameId.
-
#gtopo30(parameters = {}) ⇒ Object
GTOPO30 is a global digital elevation model (DEM) with a horizontal grid spacing of 30 arc seconds (approximately 1 kilometer).
-
#hierarchy(parameters = {}) ⇒ Object
Returns all GeoNames higher up in the hierarchy of a place name.
-
#initialize(options = {}) ⇒ GeoNames
constructor
A new instance of GeoNames.
-
#neighbourhood(parameters = {}) ⇒ Object
Neighbourhood / reverse geocoding The neighbourhood for US cities.
-
#neighbours(parameters = {}) ⇒ Object
Returns all neighbours for a place name (currently only available for countries).
-
#ocean(parameters = {}) ⇒ Object
Ocean / reverse geocoding Returns the name of the ocean or sea for the given latitude/longitude.
-
#postal_code_country_info(parameters = {}) ⇒ Array
Postal code country info.
-
#postal_code_lookup(parameters = {}) ⇒ Array
Placename lookup with postalcode.
-
#postal_code_search(parameters = {}) ⇒ Object
Postal Code Search Returns a list of postal codes and places for the placename/postalcode query.
-
#query(name, parameters) ⇒ Object
Execute query for given
namewithparameterstranslated via URI template expansion. -
#search(parameters = {}) ⇒ Object
Returns the names found for the searchterm as xml, json, or rdf document, the search is using the AND operator.
-
#siblings(parameters = {}) ⇒ Object
Returns all siblings of a GeoNames toponym.
-
#srtm3(parameters = {}) ⇒ Object
Elevation - SRTM3.
-
#timezone(parameters = {}) ⇒ Object
The timezone at the lat/lng with gmt offset (1. January) and dst offset (1. July).
-
#weather(parameters = {}) ⇒ Object
Weather Stations with most recent Weather Observation.
-
#weather_icao(parameters = {}) ⇒ Object
Returns the weather station and the most recent weather observation for the ICAO code.
-
#wikipedia_bounding_box(parameters = {}) ⇒ Array
Wikipedia articles within a bounding box.
-
#wikipedia_search(parameters = {}) ⇒ Array
Wikipedia Fulltext Search.
Constructor Details
#initialize(options = {}) ⇒ GeoNames
Returns a new instance of GeoNames.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/geonames.rb', line 19 def initialize( = {}) @options = OPTIONS.merge() @uris = Hash[QUERY.map{|name, args| if args.empty? template = Addressable::Template.new( "http://{host}/#{name}JSON" ) else joined = (%w{ username } + args.flatten).uniq.sort.join(',') template = Addressable::Template.new( "http://{host}/#{name}JSON{?#{joined}}" ) end [name, template] }] end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/geonames.rb', line 17 def @options end |
#uris ⇒ Object (readonly)
Returns the value of attribute uris.
17 18 19 |
# File 'lib/geonames.rb', line 17 def uris @uris end |
Instance Method Details
#astergdem(parameters = {}) ⇒ Object
Elevation - Aster Global Digital Elevation Model
Parameters: lat,lng
Sample area: ca 30m x 30m, between 83N and 65S latitude. Result: a single number giving the elevation in meters according to aster gdem, ocean areas have been masked as “no data” and have been assigned a value of -9999.
Example:
api.astergdem(lat: 50.01, lng: 10.2)
112 113 114 |
# File 'lib/geonames.rb', line 112 def astergdem(parameters = {}) query(:astergdem, parameters) end |
#children(parameters = {}) ⇒ Object
Returns the children for a given geonameId. The children are the administrative divisions within an other administrative division. Like the counties (ADM2) in a state (ADM1) or also the countries in a continent.
Parameters: geonameId: the geonameId of the parent maxRows: number of rows returned, default is 200
Result: returns a list of GeoName records
Example:
api.children(geonameId: 3175395, maxRows: 5)
148 149 150 |
# File 'lib/geonames.rb', line 148 def children(parameters = {}) query(:children, parameters) end |
#cities(parameters = {}) ⇒ Object
Cities and Placenames
Returns a list of cities and placenames in the bounding box, ordered by relevancy (capital/population). Placenames close together are filterered out and only the larger name is included in the resulting list.
Parameters: north,south,east,west: coordinates of bounding box callback: name of javascript function (optional parameter) lang: language of placenames and wikipedia urls (default = en) maxRows: maximal number of rows returned (default = 10)
Example:
api.cities(north: 44.1, south: -9.9, east: -22.4, west: 55.2, lang: 'de')
218 219 220 |
# File 'lib/geonames.rb', line 218 def cities(parameters = {}) query(:cities, parameters)['geonames'] end |
#country_code(parameters = {}) ⇒ Object
The ISO country code of any given point.
Parameters: lat, lng, type, lang, and radius (buffer in km for closest country in coastal areas)
With the parameter type=xml this service returns an xml document with iso country code and country name. The optional parameter lang can be used to specify the language the country name should be in. JSON output is produced with type=JSON, which is the default for this library and will be parsed automatically.
Example:
api.country_code(lat: 47.03, lng: 10.2)
285 286 287 288 289 290 291 |
# File 'lib/geonames.rb', line 285 def country_code(parameters = {}) if parameters[:type].to_s =~ /^xml$/i query(:countryCode, parameters){|content| return content } else query(:countryCode, {type: 'JSON'}.merge(parameters)) end end |
#country_info(parameters = {}) ⇒ Object
Parameters : country (default = all countries) lang: ISO-639-1 language code (en,de,fr,it,es,…) (default = english)
Example:
api.country_info(lang: 'it', country: 'DE')
266 267 268 |
# File 'lib/geonames.rb', line 266 def country_info(parameters = {}) query(:countryInfo, parameters)["geonames"] end |
#country_subdivision(parameters = {}) ⇒ Object
Country Subdivision / reverse geocoding The ISO country code and the administrative subdivision (state, province, …) of any given point.
Parameters: lat, lng, lang, radius
If lang is not given, will return the name in the local language. The radius is measured in km and acts as buffer for closest country in costal areas.
Example:
api.country_subdivision(lat: 47.03, lng: 10.2)
# With the parameters 'radius' and 'maxRows' you get the closest
# subdivisions ordered by distance:
api.country_subdivision(lat: 47.03, lng: 10.2, maxRows: 10, radius: 40)
310 311 312 |
# File 'lib/geonames.rb', line 310 def country_subdivision(parameters = {}) query(:countrySubdivision, parameters) end |
#earthquakes(parameters = {}) ⇒ Object
Returns a list of recent earthquakes, ordered by magnitude
north, south, east, west: coordinates of bounding box callback: name of javascript function (optional parameter) date: date of earthquakes ‘yyyy-MM-dd’, optional parameter minMagnitude: minimal magnitude, optional parameter maxRows: maximal number of rows returned (default = 10)
Example:
api.earthquakes(north: 44.1, south: -9.9, east: -22.4, west: 55.2)
92 93 94 95 |
# File 'lib/geonames.rb', line 92 def earthquakes(parameters = {}) quakes = query(:earthquakes, parameters)['earthquakes'] quakes.map{|quake| fix_datetime(quake) } end |
#extended_find_nearby(parameters = {}) ⇒ Object
Returns the most detailed information available for the lat/lng query. It is a combination of several services. Example: In the US it returns the address information. In other countries it returns the hierarchy service: ws.geonames.org/extendedFindNearby?lat=47.3&lng=9 On oceans it returns the ocean name.
Parameters : lat,lng
Example:
api.extended_find_nearby(lat: 47.3, lng: 9)
409 410 411 412 |
# File 'lib/geonames.rb', line 409 def extended_find_nearby(parameters = {}) raise(NotImplementedError, "XML queries haven't been implemented.") query(:extendedFindNearby, parameters) end |
#find_near_by_weather(parameters = {}) ⇒ Object
Weather Station with most recent weather observation / reverse geocoding needs username
Webservice Type : REST Url : ws.geonames.org/findNearByWeatherJSON? Parameters : lat,lng : the service will return the station closest to this given point (reverse geocoding) callback : name of javascript function (optional parameter)
Result : returns a weather station with the most recent weather observation
519 520 521 |
# File 'lib/geonames.rb', line 519 def find_near_by_weather(parameters = {}) query(:findNearByWeather, parameters) end |
#find_nearby(parameters = {}) ⇒ Object
Find nearby toponym
Parameters: lat, lng, featureClass, featureCode, radius: radius in km (optional) maxRows: max number of rows (default 10) style: SHORT, MEDIUM, LONG, FULL (default = MEDIUM), verbosity result.
Example:
api.find_nearby(lat: 47.3, lng: 9)
391 392 393 |
# File 'lib/geonames.rb', line 391 def find_nearby(parameters = {}) query(:findNearby, parameters)["geonames"] end |
#find_nearby_place_name(parameters = {}) ⇒ Object
Find nearby populated place / reverse geocoding Returns the closest populated place for the lat/lng query. The unit of the distance element is ‘km’.
Parameters: lat, lng, radius: radius in km (optional), maxRows: max number of rows (default 10), style: SHORT, MEDIUM, LONG, FULL (default = MEDIUM), verbosity of result
Example:
api.find_nearby_place_name(lat: 47.3, lng: 9)
428 429 430 |
# File 'lib/geonames.rb', line 428 def find_nearby_place_name(parameters = {}) query(:findNearbyPlaceName, parameters)["geonames"] end |
#find_nearby_postal_codes(parameters = {}) ⇒ Object
List of nearby postalcodes and places for the lat/lng query. The result is sorted by distance.
This service comes in two flavors. You can either pass the lat/long or a postalcode/placename.
Parameters:
lat, lng, radius (in km), maxRows (default = 5), style (verbosity : SHORT,MEDIUM,LONG,FULL), country (default = all countries), localCountry (restrict search to local country in border areas)
or
postalcode, country, radius (in Km), maxRows (default = 5)
Example:
api.find_nearby_postal_codes(lat: 47, lng: 9)
api.find_nearby_postal_codes(postalcode: 8775, country: 'CH', radius: 10)
455 456 457 |
# File 'lib/geonames.rb', line 455 def find_nearby_postal_codes(parameters = {}) query(:findNearbyPostalCodes, parameters)["postalCodes"] end |
#find_nearby_streets(latitude, longitude) ⇒ Array
Returns the nearest street segments for the given latitude/longitude, this service is only available for the US.
A street segment has following keys: “adminCode1”: Identifier of state. “adminCode2”: Area code. “adminName1”: Name of state. “adminName2”: Name of province. “countryCode”: Name of country (usually “US”) “distance”: Distance of street to given coordinates in km. “fraddl”: From address left. “fraddr”: From address right. “line”: A string with lng/lat points, comma separated. “mtfcc”: MAF/TIGER Feature class code. “name:” Name of the street. “postalcode”: Postal code of the address. “toaddl”: To address left. “toaddr”: To address right.
488 489 490 |
# File 'lib/geonames.rb', line 488 def find_nearby_streets(latitude, longitude) [*query(:findNearbyStreets, lat: latitude, lng: longitude)['streetSegment']] end |
#find_nearby_streets_osm(latitude, longitude) ⇒ Object
Find nearby street segments on OpenStreetMap for the given latitude/longitude.
502 503 504 |
# File 'lib/geonames.rb', line 502 def find_nearby_streets_osm(latitude, longitude) query(:findNearbyStreetsOSM, lat: latitude, lng: longitude) end |
#find_nearby_wikipedia(parameters = {}) ⇒ Object
Find nearby Wikipedia Entries / reverse geocoding
This service comes in two flavors. You can either pass the lat/long or a postalcode/placename. Webservice Type : XML,JSON or RSS Url : ws.geonames.org/findNearbyWikipedia? ws.geonames.org/findNearbyWikipediaJSON? ws.geonames.org/findNearbyWikipediaRSS? Parameters : lang : language code (around 240 languages) (default = en) lat,lng, radius (in km), maxRows (default = 5),country (default = all countries) or postalcode,country, radius (in Km), maxRows (default = 5) Result : returns a list of wikipedia entries as xml document Example: ws.geonames.org/findNearbyWikipedia?lat=47&lng=9 or ws.geonames.org/findNearbyWikipedia?postalcode=8775&country=CH&radius=10
541 542 543 |
# File 'lib/geonames.rb', line 541 def find_nearby_wikipedia(parameters = {}) query(:findNearbyWikipedia, parameters) end |
#find_nearest_address(parameters = {}) ⇒ Object
Find nearest Address
Finds the nearest street and address for a given lat/lng pair. Url : ws.geonames.org/findNearestAddress? Parameters : lat,lng; Restriction : this webservice is only available for the US. Result : returns the nearest address for the given latitude/longitude, the street number is an ‘educated guess’ using an interpolation of street number at the end of a street segment. Example ws.geonames.org/findNearestAddress?lat=37.451&lng=-122.18
This service is also available in JSON format : ws.geonames.org/findNearestAddressJSON?lat=37.451&lng=-122.18
559 560 561 |
# File 'lib/geonames.rb', line 559 def find_nearest_address(parameters = {}) query(:findNearestAddress, parameters) end |
#find_nearest_intersection(parameters = {}) ⇒ Object
Find nearest Intersection
Finds the nearest street and the next crossing street for a given lat/lng pair. Url : ws.geonames.org/findNearestIntersection? Parameters : lat,lng; Restriction : this webservice is only available for the US. Result : returns the nearest intersection for the given latitude/longitude Example ws.geonames.org/findNearestIntersection?lat=37.451&lng=-122.18
This service is also available in JSON format : ws.geonames.org/findNearestIntersectionJSON?lat=37.451&lng=-122.18
575 576 577 |
# File 'lib/geonames.rb', line 575 def find_nearest_intersection(parameters = {}) query(:findNearestIntersection, parameters) end |
#find_nearest_intersection_osm(parameters = {}) ⇒ Object
Find nearest street and crossing for a given latitude/longitude pair on OpenStreetMap.
588 589 590 |
# File 'lib/geonames.rb', line 588 def find_nearest_intersection_osm(parameters = {}) query(:findNearestIntersectionOSM, parameters) end |
#fix_datetime(hash) ⇒ Object
Utility method for some queries that return times, we convert them to real Time instances with proper UTC timezone.
60 61 62 63 64 65 66 67 |
# File 'lib/geonames.rb', line 60 def fix_datetime(hash) if time = hash['datetime'] zone, format = .values_at(:timezone, :time_format) hash['datetime'] = Time.strptime("#{time} #{zone}", format) end hash end |
#get(parameters) ⇒ Object
Returns the attribute of the geoNames feature with the given geonameId
Parameters: geonameId
Example:
api.get(geonameId: 2643743)
76 77 78 |
# File 'lib/geonames.rb', line 76 def get(parameters) query(:get, parameters) end |
#gtopo30(parameters = {}) ⇒ Object
GTOPO30 is a global digital elevation model (DEM) with a horizontal grid spacing of 30 arc seconds (approximately 1 kilometer). GTOPO30 was derived from several raster and vector sources of topographic information.
Parameters: lat,lng
Sample area: ca 1km x 1km Result : a single number giving the elevation in meters according to gtopo30, ocean areas have been masked as “no data” and have been assigned a value of -9999.
Example:
api.gtopo30(lat: 50.01, lng: 10.2)
130 131 132 |
# File 'lib/geonames.rb', line 130 def gtopo30(parameters = {}) query(:gtopo30, parameters) end |
#hierarchy(parameters = {}) ⇒ Object
Returns all GeoNames higher up in the hierarchy of a place name.
Parameters: geonameId: the geonameId for the hierarchy
Result: returns a list of GeoName records, ordered by hierarchy level. The top hierarchy (continent) is the first element in the list
Example:
api.hierarchy(geonameId: 2657896)
164 165 166 |
# File 'lib/geonames.rb', line 164 def hierarchy(parameters = {}) query(:hierarchy, parameters) end |
#neighbourhood(parameters = {}) ⇒ Object
Neighbourhood / reverse geocoding The neighbourhood for US cities. Data provided by Zillow under cc-by-sa license.
Parameters: lat,lng
Example:
api.neighbourhood(lat: 40.78343, lng: -73.96625)
337 338 339 |
# File 'lib/geonames.rb', line 337 def neighbourhood(parameters = {}) query(:neighbourhood, parameters)["neighbourhood"] end |
#neighbours(parameters = {}) ⇒ Object
Returns all neighbours for a place name (currently only available for countries).
Parameters: geonameId: the geonameId for the neighbours
Result: returns the neighbours of a toponym, currently only implemented for countries
Example:
api.neighbours(geonameId: 2658434)
181 182 183 |
# File 'lib/geonames.rb', line 181 def neighbours(parameters = {}) query(:neighbours, parameters) end |
#ocean(parameters = {}) ⇒ Object
Ocean / reverse geocoding Returns the name of the ocean or sea for the given latitude/longitude.
Parameters : lat,lng
Example:
api.ocean(lat: 40.78343, lng: -43.96625)
323 324 325 |
# File 'lib/geonames.rb', line 323 def ocean(parameters = {}) query(:ocean, parameters)["ocean"] end |
#postal_code_country_info(parameters = {}) ⇒ Array
Postal code country info
599 600 601 |
# File 'lib/geonames.rb', line 599 def postal_code_country_info(parameters = {}) query(:postalCodeCountryInfo, {})['geonames'] end |
#postal_code_lookup(parameters = {}) ⇒ Array
Placename lookup with postalcode
618 619 620 |
# File 'lib/geonames.rb', line 618 def postal_code_lookup(parameters = {}) query(:postalCodeLookup, parameters) end |
#postal_code_search(parameters = {}) ⇒ Object
Postal Code Search Returns a list of postal codes and places for the placename/postalcode query.
For the US the first returned zip code is determined using zip code area shapes, the following zip codes are based on the centroid. For all other supported countries all returned postal codes are based on centroids.
Parameter Value Description postalcode string (postalcode or placename required) postal code postalcode_startsWith string the first characters or letters of a postal code placename string (postalcode or placename required) all fields : placename,postal code, country, admin name (Important:urlencoded utf8) placename_startsWith string the first characters of a place name country string : country code, ISO-3166 (optional) Default is all countries. countryBias string records from the countryBias are listed first maxRows integer (optional) the maximal number of rows in the document returned by the service. Default is 10 style string SHORT,MEDIUM,LONG,FULL (optional) verbosity of returned xml document, default = MEDIUM operator string AND,OR (optional) the operator ‘AND’ searches for all terms in the placename parameter, the operator ‘OR’ searches for any term, default = AND charset string (optional) default is ‘UTF8’, defines the encoding used for the document returned by the web service. isReduced true or false (optional) default is ‘false’, when set to ‘true’ only the UK outer codes are returned. Attention: the default value on the commercial servers is currently set to ‘true’. It will be changed later to ‘false’.
645 646 647 |
# File 'lib/geonames.rb', line 645 def postal_code_search(parameters = {}) query(:postalCodeSearch, parameters) end |
#query(name, parameters) ⇒ Object
Execute query for given name with parameters translated via URI template expansion.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/geonames.rb', line 38 def query(name, parameters) default = {host: [:host]} default[:username] = [:username] if [:username] uri = uris[name].(default.merge(parameters)) result = if block_given? open(uri.to_s){|io| yield(io.read) } else open(uri.to_s){|io| JSON.parse(io.read) } end if status = result["status"] raise APIError, status.inspect else result end end |
#search(parameters = {}) ⇒ Object
Returns the names found for the searchterm as xml, json, or rdf document, the search is using the AND operator.
With the parameter ‘type: ’rdf’‘ the search service returns the result in RDF format defined by the GeoNames Semantic Web Ontology.
Tags GeoNames is using a simple tagging system. Every user can tag places. In contrast to the feature codes and feature classes which are one-dimensional (a place name can only have one feature code) several tags can be used for each place name. It is an additional categorization mechanism where the simple classification with feature codes is not sufficient.
I have tagged a place with the tag ‘skiresort’. You can search for tags with the search: ‘api.search(q: ’skiresort’)‘ If you only want to search for a tag and not for other occurences of the term (in case you tag something with ’spain’ for example), then you add the attribute ‘tags:’ to the search term: ‘api.search(q: ’tags:skiresort’)‘
And if you want to search for tags of a particular user (or your own) then you append ‘@username’ to the tag. Like this: ‘api.search(q: ’tags:skiresort@marc’)
737 738 739 |
# File 'lib/geonames.rb', line 737 def search(parameters = {}) query(:search, parameters)['geonames'] end |
#siblings(parameters = {}) ⇒ Object
Returns all siblings of a GeoNames toponym.
Parameters: geonameId: the geonameId for the siblings
Result: returns a list of GeoNames records that have the same administrative level and the same father
Example:
api.siblings(geonameId: 3017382)
197 198 199 |
# File 'lib/geonames.rb', line 197 def siblings(parameters = {}) query(:siblings, parameters)['geonames'] end |
#srtm3(parameters = {}) ⇒ Object
Elevation - SRTM3
Shuttle Radar Topography Mission (SRTM) elevation data. SRTM consisted of a specially modified radar system that flew onboard the Space Shuttle Endeavour during an 11-day mission in February of 2000. The dataset covers land areas between 60 degrees north and 56 degrees south. This web service is using SRTM3 data with data points located every 3-arc-second (approximately 90 meters) on a latitude/longitude grid.
Parameters : lat,lng; sample area: ca 90m x 90m Result : a single number giving the elevation in meters according to srtm3, ocean areas have been masked as “no data” and have been assigned a value of -32768.
Example:
api.srtm3(lat: 50.01, lng: 10.2)
359 360 361 |
# File 'lib/geonames.rb', line 359 def srtm3(parameters = {}) query(:srtm3, parameters) end |
#timezone(parameters = {}) ⇒ Object
The timezone at the lat/lng with gmt offset (1. January) and dst offset (1. July)
Parameters: lat, lng, radius (buffer in km for closest timezone in coastal areas) needs username
If you want to work with the returned time, I recommend the tzinfo library, which can handle the timezoneId. In order to keep dependencies low and the code flexible and fast, we won’t do any further handling here.
Example:
api.timezone(lat: 47.01, lng: 10.2)
376 377 378 |
# File 'lib/geonames.rb', line 376 def timezone(parameters = {}) query(:timezone, parameters) end |
#weather(parameters = {}) ⇒ Object
Weather Stations with most recent Weather Observation
Returns a list of weather stations with the most recent weather observation.
Parameters: north,south,east,west: coordinates of bounding box callback: name of javascript function (optional parameter) maxRows: maximal number of rows returned (default = 10)
Example:
api.weather(north: 44.1, south: -9.9, east: -22.4, west: 55.2)
235 236 237 238 |
# File 'lib/geonames.rb', line 235 def weather(parameters = {}) observations = query(:weather, parameters)['weatherObservations'] observations.map{|observation| fix_datetime(observation) } end |
#weather_icao(parameters = {}) ⇒ Object
Returns the weather station and the most recent weather observation for the ICAO code.
Parameters: ICAO: International Civil Aviation Organization (ICAO) code callback: name of javascript function (optional parameter)
Example:
api.weather_icao(ICAO: 'LSZH')
251 252 253 254 |
# File 'lib/geonames.rb', line 251 def weather_icao(parameters = {}) weather = query(:weatherIcao, parameters)['weatherObservation'] fix_datetime(weather) end |
#wikipedia_bounding_box(parameters = {}) ⇒ Array
Wikipedia articles within a bounding box
760 761 762 |
# File 'lib/geonames.rb', line 760 def wikipedia_bounding_box(parameters = {}) [*query(:wikipediaBoundingBox, parameters)['geonames']] end |
#wikipedia_search(parameters = {}) ⇒ Array
Wikipedia Fulltext Search
782 783 784 785 786 |
# File 'lib/geonames.rb', line 782 def wikipedia_search(parameters = {}) params = parameters.dup params[:title] = '' if params[:title] # weird? [*query(:wikipediaSearch, params)['geonames']] end |