Commit c7144a46 authored by 2xe's avatar 2xe
Browse files

First commit for Geonames API

parent 7900f980
$id$
Geonames API Documentation, by Erlend Eide erlend (|) edesign.no
Defining new services: Service Definitions (Service Modules)
--------------------------------------------------------------------------------
The geonames_MODULENAME_geoconfig function must return configuration data.
The configuration is an array with the following set of properties defined
in an associative array (see below the list for explanations):
- service_name string name to refer to in code
- service_full_name string Human Readable Name
- description string Human Readable Description
- service_path string Geonames Service Location (path)
- credit_cost int Commercial Services Credit Price
- result_cache_prefix string Unique cache prefix (end with :)
- data_cache_prefix string Unique cache prefix (end with :)
- allowed_parameters associative array see below
- array_parameters array of strings optional, see below
- required_parameters array of strings optional, see below
or array of array
- required_parameters_type string mandatory if required_parameters
- query_defaults associative array optional, see below
- columns array of strings mandatory if no style is set
- pager boolean optional, see below
- detect_style boolean optional, see below
Parameter: allowed_parameters (associative array)
This array defines which parameters are allowed in queries, all other parameters
will be omitted from the query. The array must be associative, where the key is
"our" parameter name (Drupal style, lowercase) and the value is GeoNames style
(mixedCase).
All services that support the style parameter (short/medium/full/long) should
have the parameter detect_style set to TRUE, unless the query default value
for style allways is to be used.
This structure allows the GeoNames API to use other parameter names than the
actual GeoNames Service -- for instance GeoNames' "q" parameter should allways
be named "query" when we refer to it in Drupal. This will prevent Drupal's
q=node/x parameter to be added to the array if the query is passed by URL.
Parameter: array_parameters (array of strings)
Any parameter specified here will allow the parameter to be an array. Some of
the GeoNames Services allow several equally named parameters to be sent -- for
instance the Fulltext Search service. You may for instance specify several
Countries to restrict your query to. The result is several equally named
parameters in the query URL passed to Geonames (i.e. &country=NO&country=SE)
Parameter: required_parameters (array of strings OR array with arrays of strings)
Some services have several sets of requirements, therefore we may specify this
parameter as an array with arrays of strings.
Each subset (or just the single set) will be used to verify if the query
contains the required parameters. In this way, we prevent requests to GeoNames
that will just return error messages.
Parameter: required_parameters_type (string)
The string may be either 'single' or 'all'. This parameter is required if the
parameter "required_parameters" is set.
Single: One of the parameters in required_parameters is mandatory
All: All of the parameters defined in required_parameters are mandatory
Parameter: query_defaults (associative array)
This associative array is optional. When set, the key/value pairs will be added
as default query parameters to a request. The values may be overridden by the
user-specified query (if $columns is passed in the geonames_query).
Parameter: columns (array of strings)
This parameter is mandatory if the query parameter 'style' is not available, or
set, in the required_parameters. If style is set, columns is optional. The field
names specified here will be added to your results (and all others will be
ignored). The parameter may be overridden by the user-specified query (if
$columns is passed in the geonames_query)
Parameter: detect_style (boolean)
This optional parameter may be set to TRUE if the service supports the
short/medium/long/full styles. The API will (based on the $columns passed in the
geonames_query) automatically detect the style that should be requested. The
purpose of the detection is to minimize the amount of data requested from the
GeoNames server.
Parameter: pager (boolean)
This optional parameter may be set to TRUE if you want/need to calculate pager
data for the results. The result object will get an extra property $result->pager
which contains everything you need to set up a set of pages.
; $id$
name = Geonames API
description = The Geonames API provides the programming framework for the Geonames services. You must install this module before you install any of the services.
package = Geonames
version = "$Name$"
\ No newline at end of file
This diff is collapsed.
; $id$
name = children
description = Place Hierarchy - Find the children for a given location by latitude and longitude. The children are the administrative divisions within an other administrative division.
package = Geonames
dependencies = geonames
version = "$Name$"
\ No newline at end of file
<?php
// $Id$
/**
* @file
* Geonames Place Hierarchy Children / by Erlend Eide, erlend(|)edesign.no
*
* http://www.geonames.org/export/place-hierarchy.html
*/
/**
* Service configuration
*/
function geonames_children_geoconfig($item = FALSE, $local = FALSE) {
$config = array(
'service_name' => 'children',
'service_full_name' => 'Place Hierarchy: Children',
'description' => t('Find the children of a given geonameId.'),
'service_path' => 'children',
'credit_cost' => 1,
'result_cache_prefix' => 'hcres:',
'data_cache_prefix' => 'hcdat:',
'allowed_parameters' => array(
// our style // geonames style
'geonameid' => 'geonameId',
'style' => 'style',
'lang' => 'lang',
),
'required_parameters' => array(
'geonameid',
),
'required_parameters_type' => 'single',
'detect_style' => TRUE,
);
return ($item ? ($local ? $config[$item] : array($config['service_name'] => $config[$item])) : array($config['service_name'] => $config));
}
; $id$
name = countrycode
description = Finds the countrycode for a given latitude and longitude
dependencies = geonames
package = Geonames
version = "$Name$"
\ No newline at end of file
<?php
// $Id$
/**
* @file
* Geonames countrycode / by Erlend Eide, erlend(|)edesign.no
*/
/**
* Service configuration
*/
function geonames_countrycode_geoconfig($item = FALSE, $local = FALSE) {
$config = array(
'service_name' => 'countrycode',
'service_full_name' => 'Country Code (reverse geocoding)',
'description' => t('Find Country Code from latitude and longitude'),
'service_path' => 'countrycode',
'credit_cost' => 1,
'result_cache_prefix' => 'ccres:',
'data_cache_prefix' => 'ccdat:',
'allowed_parameters' => array(
//our style geonames style
'lat' => 'lat',
'lng' => 'lng',
'lang' => 'lang',
'type' => 'type',
),
'required_parameters' => array( // If you have set query_defaults you should not include the parameter here
'lat',
'lng'
),
'required_parameters_type' => 'all',
'query_defaults' => array(
'type' => 'xml'
),
'columns' => array('countrycode', 'countryname'),
);
return ($item ? ($local ? $config[$item] : array($config['service_name'] => $config[$item])) : array($config['service_name'] => $config));
}
; $id$
name = countryinfo
description = Finds information about all Countries - currency, area, population, languages etc...
dependencies = geonames
package = Geonames
version = "$Name$"
\ No newline at end of file
<?php
// $Id$
/**
* @file
* Geonames countryinfo / by Erlend Eide, erlend(|)edesign.no
*
* IMPORTANT NOTE: http://forum.geonames.org/gforum/posts/list/119.page
* - Countries AE,CS,UM,VA, TL are missing in the XML Service
* - All countries are available from here: http://ws.geonames.org/countryInfoCSV?
*/
/**
* Service configuration
*/
function geonames_countryinfo_geoconfig($item = FALSE, $local = FALSE) {
$config = array(
'service_name' => 'countryinfo',
'service_full_name' => 'Country Info (Bounding Box, Capital, Area in square km, Population)',
'description' => 'Find countries for which postal code geocoding is available.',
'service_path' => 'countryInfo',
'credit_cost' => 1,
'result_cache_prefix' => 'couires:',
'data_cache_prefix' => 'couidat:',
'allowed_parameters' => array(
//our style geonames style
'country' => 'country',
'lang' => 'lang',
),
'columns' => array(
'countrycode',
'countryname',
'isonumeric',
'isoalpha3',
'fipscode',
'continent',
'capital',
'areainsqkm',
'population',
'currencycode',
'languages',
'geonameid',
'bboxwest',
'bboxnorth',
'bboxsouth',
'bboxeast',
),
);
return ($item ? ($local ? $config[$item] : array($config['service_name'] => $config[$item])) : array($config['service_name'] => $config));
}
; $id$
name = countrysubdivision
description = Finds the iso Country Code and the Administrative Subdivision of any given location by latittude and longitude.
dependencies = geonames
package = Geonames
version = "$Name$"
\ No newline at end of file
<?php
// $Id$
/**
* @file
* Geonames countrycode / by Erlend Eide, erlend(|)edesign.no
*/
/**
* Service configuration
*/
function geonames_countrysubdivision_geoconfig($item = FALSE, $local = FALSE) {
$config = array(
'service_name' => 'countrysubdivision',
'service_full_name' => 'Country Subdivision (reverse geocoding)',
'description' => t('Find Country Code from latitude and longitude'),
'service_path' => 'countrySubdivision',
'credit_cost' => 1,
'result_cache_prefix' => 'csres:',
'data_cache_prefix' => 'csdat:',
'allowed_parameters' => array(
//our style geonames style
'lat' => 'lat',
'lng' => 'lng',
'lang' => 'lang',
),
'required_parameters' => array( // If you have set query_defaults you should not include the parameter here
'lat',
'lng'
),
'required_parameters_type' => 'all',
'columns' => array('countrycode', 'countryname', 'admincode1', 'adminname1'),
);
return ($item ? ($local ? $config[$item] : array($config['service_name'] => $config[$item])) : array($config['service_name'] => $config));
}
; $id$
name = gtopo30
description = GEONAMES XML ERROR - Finds elevation for a single point on earth specified by latitude and longitude. The dataset is global, vector based with datapoints every kilometer.
dependencies = geonames
package = Geonames
version = "$Name$"
\ No newline at end of file
<?php
// $Id$
/**
* @file
* Geonames gtopo30 / by Erlend Eide, erlend(|)edesign.no
*/
/**
* Service configuration
*/
function geonames_gtopo30_geoconfig($item = FALSE, $local = FALSE) {
$config = array(
'service_name' => 'gtopo30',
'service_full_name' => 'Elevation - GTOPO30',
'description' => t('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.'),
'service_path' => 'gtopo30',
'credit_cost' => 0,
'result_cache_prefix' => 'gtpres:',
'data_cache_prefix' => 'gtpdat:',
'allowed_parameters' => array(
//our style geonames style
'lat' => 'lat',
'lng' => 'lng',
'type' => 'type',
),
'required_parameters' => array( // If you have set query_defaults you should not include the parameter here
'lat',
'lng'
),
'required_parameters_type' => 'all',
'query_defaults' => array(
'type' => 'xml'
),
);
return ($item ? ($local ? $config[$item] : array($config['service_name'] => $config[$item])) : array($config['service_name'] => $config));
}
; $id$
name = hierarchy
description = Place Hierarchy: Find all Geonames higher up in the hierarchy of a place name.
package = Geonames
dependencies = geonames
version = "$Name$"
\ No newline at end of file
<?php
// $Id$
/**
* @file
* Geonames Place Hierarchy Children / by Erlend Eide, erlend(|)edesign.no
*
* http://www.geonames.org/export/place-hierarchy.html
*/
/**
* Service configuration
*/
function geonames_hierarchy_geoconfig($item = FALSE, $local = FALSE) {
$config = array(
'service_name' => 'hierarchy',
'service_full_name' => 'Place Hierarchy: Hierarchy',
'description' => t('Find all Geonames higher up in the hierarchy of a place name.'),
'service_path' => 'hierarchy',
'credit_cost' => 1,
'result_cache_prefix' => 'hires:',
'data_cache_prefix' => 'hidat:',
'allowed_parameters' => array(
// our style // geonames style
'geonameid' => 'geonameId',
'style' => 'style',
'lang' => 'lang',
),
'required_parameters' => array(
'geonameid',
),
'required_parameters_type' => 'single',
'detect_style' => TRUE,
);
return ($item ? ($local ? $config[$item] : array($config['service_name'] => $config[$item])) : array($config['service_name'] => $config));
}
; $id$
name = nearbyplace
description = Finds Nearby Places to a single point by latitude and longitude
dependencies = geonames
package = Geonames
version = "$Name$"
\ No newline at end of file
<?php
// $Id$
/**
* @file
* Geonames nearbyplace API / by Erlend Eide, erlend(|)edesign.no
*/
/**
* Service configuration
*/
function geonames_nearbyplace_geoconfig($item = FALSE, $local = FALSE) {
$config = array(
'service_name' => 'nearbyplace',
'service_full_name' => 'Find nearby Place Name (reverse geocoding)',
'description' => t('Find nearby place name (reverse geocoding)'),
'service_path' => 'findNearbyPlaceName',
'credit_cost' => 4,
'result_cache_prefix' => 'neares:',
'data_cache_prefix' => 'neadat:',
'allowed_parameters' => array(
//our style geonames style
'lat' => 'lat',
'lng' => 'lng',
'radius' => 'radius',
'maxrows' => 'maxRows',
'style' => 'style', // Default = MEDIUM
),
'query_defaults' => array(
'radius' => 20
),
'required_parameters' => array( // If you have set query_defaults you should not include the parameter here
'lat',
'lng'
),
'required_parameters_type' => 'all',
);
return ($item ? ($local ? $config[$item] : array($config['service_name'] => $config[$item])) : array($config['service_name'] => $config));
}
; $id$
name = nearbypostalcodes
description = Geonames nearbypostalcodes API - findNearbyPostalcodes - finds psotalcodes based on latitude/longitude or postalcode/country in a given radius
dependencies = geonames
package = Geonames
version = "$Name$"
\ No newline at end of file
; $id$
name = nearbypostalcodes
description = Finds Nearby Postal Codes based on Latitude/Longitude or Postalcode/Country within in a given Radius.
dependencies = geonames
package = Geonames
version = "$Name$"
\ No newline at end of file
<?php
// $Id$
/**
* @file
* Geonames nearbypostalcodes API / by Erlend Eide, erlend(|)edesign.no
*
* http://www.geonames.org/export/
*
* Parameters :
* lat,lng, radius (in km), maxRows (default = 5),style (verbosity : SHORT,MEDIUM,LONG,FULL),
* country (default = all countries)
* or
* postalcode,country, radius (in Km), maxRows (default = 5)
*
* Result : returns a list of postalcodes and places for the lat/lng query as xml document
*
*
* NOTE: Style is allways MEDIUM (supported in formats SHORT/MEDIUM -- but there is so little to
* save by requesting the SHORT format, so we allways use MEDIUM - which also is default)
*/
/**
* Service configuration
*/
function geonames_nearbypostalcodes_geoconfig($item = FALSE, $local = FALSE) {
$config = array(
'service_name' => 'nearbypostalcodes',
'service_full_name' => 'Find nearby Postal Codes (reverse geocoding)',
'description' => 'Find nearby Postal Codes (reverse geocoding)',
'service_path' => 'findNearbyPostalCodes',
'credit_cost' => 2,
'result_cache_prefix' => 'nbpres:',
'data_cache_prefix' => 'nbpdat:',
'allowed_parameters' => array(
//our style geonames style
'lat' => 'lat',
'lng' => 'lng',
'radius' => 'radius',
'postalcode' => 'postalcode',
'maxrows' => 'maxRows', // Geonames default = 5
'country' => 'country', // Geonames default = ALL
'style' => 'style',
),
'required_parameters' => array( // If you have set query_defaults you should not include the parameter here
array('lat', 'lng'),
array('postalcode', 'country')
),
'required_parameters_type' => 'all',
'query_defaults' => array(
'maxrows' => 15,
'radius' => 10,
'style' => 'medium',
),
'columns' => array(
'postalcode',
'name',
'countrycode',
'lat',
'lng',
'distance',
'admincode1',
'admincode2',
'admincode3',
'adminname1',
'adminname2',
'adminname3',
),
);
return ($item ? ($local ? $config[$item] : array($config['service_name'] => $config[$item])) : array($config['service_name'] => $config));
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment