org.opengts.geocoder.geonames
Class GeoNames

java.lang.Object
  extended by org.opengts.geocoder.ReverseGeocodeProviderAdapter
      extended by org.opengts.geocoder.geonames.GeoNames
All Implemented Interfaces:
GeocodeProvider, ReverseGeocodeProvider, SubdivisionProvider

public class GeoNames
extends ReverseGeocodeProviderAdapter
implements ReverseGeocodeProvider, SubdivisionProvider, GeocodeProvider


Field Summary
protected static java.lang.String ATTR_message
           
protected static java.lang.String ENCODING_UTF8
           
protected static java.lang.String HOST_FAILOVER
           
protected static java.lang.String HOST_PRIMARY
           
protected static java.lang.String HOST_PRIMARY2
           
protected static double MAX_ADDRESS_DISTANCE_KM
           
protected static java.lang.String PROP_addressFailover
           
protected static java.lang.String PROP_failoverHostName
           
protected static java.lang.String PROP_hostName
           
protected static java.lang.String PROP_placeFailover
           
protected static java.lang.String PROP_postalFailover
           
protected static java.lang.String PROP_primaryService
           
protected static java.lang.String PROP_radiusKM
           
protected static java.lang.String PROP_service_
           
protected static java.lang.String PROP_streetFailover
           
protected static java.lang.String PROP_token
           
protected static java.lang.String PROP_username
           
protected static java.lang.String SERVICE_countrySubdivision
           
protected static java.lang.String SERVICE_findNearbyPlaceName
           
protected static java.lang.String SERVICE_findNearbyPostalCodes
           
protected static java.lang.String SERVICE_findNearbyStreetsOSM
           
protected static java.lang.String SERVICE_findNearestAddress
           
protected static java.lang.String TAG_address
           
protected static java.lang.String TAG_adminCode1
           
protected static java.lang.String TAG_adminName1
           
protected static java.lang.String TAG_adminName2
           
protected static java.lang.String TAG_cityName
           
protected static java.lang.String TAG_code
           
protected static java.lang.String TAG_countryCode
           
protected static java.lang.String TAG_countryName
           
protected static java.lang.String TAG_countrySubdivision
           
protected static java.lang.String TAG_distance
           
protected static java.lang.String TAG_geoname
           
protected static java.lang.String TAG_geonames
           
protected static java.lang.String TAG_isTollRoad
           
protected static java.lang.String TAG_lat
           
protected static java.lang.String TAG_lng
           
protected static java.lang.String TAG_name
           
protected static java.lang.String TAG_placename
           
protected static java.lang.String TAG_postalcode
           
protected static java.lang.String TAG_postalCode
           
protected static java.lang.String TAG_speedCategory
           
protected static java.lang.String TAG_speedRestriction
           
protected static java.lang.String TAG_status
           
protected static java.lang.String TAG_street
           
protected static java.lang.String TAG_streetNumber
           
protected static java.lang.String TAG_streetSegment
           
protected static int TIMEOUT_Geocode
           
protected static int TIMEOUT_ReverseGeocode
           
 
Fields inherited from class org.opengts.geocoder.ReverseGeocodeProviderAdapter
_PROP_isEnabled, DEFAULT_MAX_FAILOVER_SECONDS, MIN_FAILOVER_SECONDS, PROP_alwaysFast, PROP_maxFailoverSeconds, PROP_ReverseGeocodeProvider_
 
Constructor Summary
GeoNames(java.lang.String name, java.lang.String key, RTProperties rtProps)
          Constructor
 
Method Summary
 ReverseGeocode getAddressReverseGeocode(GeoPoint gp, java.lang.String localeStr)
          Returns a ReverseGeocode instance containing address information
static java.lang.String getCityLocation_xml(java.lang.String city, java.lang.String state, java.lang.String country, int timeoutMS)
           
static GeoPoint getCityLocation(java.lang.String address, java.lang.String state, java.lang.String country, int timeoutMS)
           
protected static java.util.Map<java.lang.String,java.lang.String> GetElementValueMap(org.w3c.dom.Element elem)
           
 GeoPoint getGeocode(java.lang.String address, java.lang.String country)
          Returns GeoPoint of specified address
protected  int getGeocodeTimeout()
          Returns the Geocode timeout
protected  java.lang.StringBuffer getGeonamesURL(boolean primary, java.lang.String service, GeoPoint gp)
          Returns the URL for the specified Geonames service
protected  java.lang.String getHostname(boolean primary)
          Gets the hostname
protected  double getMaximumSearchRadius()
          Returns the maximum search radius, in kilometers
 ReverseGeocode getNearbyStreetNameReverseGeocode(GeoPoint gp)
           
protected static java.lang.String GetNodeText(org.w3c.dom.Node root)
           
 ReverseGeocode getPlaceNameReverseGeocode(GeoPoint gp)
          Returns a PlaceName ReverseGeocode instance
static java.lang.String getPostalCodeLocation_xml(java.lang.String postalCode, java.lang.String country, int timeoutMS)
           
static GeoPoint getPostalCodeLocation(java.lang.String postalCode, java.lang.String country, int timeoutMS)
           
 ReverseGeocode getPostalReverseGeocode(GeoPoint gp)
           
 ReverseGeocode getReverseGeocode(GeoPoint gp, java.lang.String localeStr, boolean cache)
          Returns a ReverseGeocode instance for the specified GeoPoint
protected  int getReverseGeocodeTimeout()
          Returns the ReverseGeocode timeout
 java.lang.String getSubdivision(GeoPoint gp)
          Return the subdivision of the specified point (in the US, this is "US/" as in "US/CA")
protected static org.w3c.dom.Document GetXMLDocument(java.lang.String url, int timeoutMS)
          Reads the XML response from the specified URL location, returning an XML Document
 boolean hasUsername()
          Returns true if a username has been defined
protected  void init_countrySubdivision()
          Initializes the 'countrySubdivision' XML document generator.
protected  void init_findNearbyPlaceName()
          Initializes the 'findNearbyPlaceName' XML document generator.
protected  void init_findNearbyPostalCodes()
          Initializes the 'findNearbyPostalCodes' XML document generator.
protected  void init_findNearbyStreetsOSM()
          Initializes the 'findNearbyStreetsOSM' XML document generator.
protected  void init_findNearestAddress()
          Initializes the 'findNearestAddress' XML document generator.
 boolean isFastOperation()
          Returns true if locally resolved, false otherwise.
static void main(java.lang.String[] argv)
          Main entery point for debugging/testing
 
Methods inherited from class org.opengts.geocoder.ReverseGeocodeProviderAdapter
_getUserPass, _main, getAuthorization, getFailoverReverseGeocodeProvider, getFailoverReverseGeocodeProviderName, getMaximumFailoverElapsedSec, getName, getPassword, getProperties, getUsername, hasFailoverReverseGeocodeProvider, isEnabled, isReverseGeocodeFailoverMode, setAuthorization, setFailoverReverseGeocodeProvider, setName, setProperties, startReverseGeocodeFailoverMode, startReverseGeocodeFailoverMode, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.opengts.geocoder.ReverseGeocodeProvider
getFailoverReverseGeocodeProvider, getName, isEnabled, setFailoverReverseGeocodeProvider
 
Methods inherited from interface org.opengts.geocoder.GeocodeProvider
getName, isEnabled
 

Field Detail

TAG_geonames

protected static final java.lang.String TAG_geonames
See Also:
Constant Field Values

TAG_geoname

protected static final java.lang.String TAG_geoname
See Also:
Constant Field Values

TAG_streetSegment

protected static final java.lang.String TAG_streetSegment
See Also:
Constant Field Values

TAG_address

protected static final java.lang.String TAG_address
See Also:
Constant Field Values

TAG_code

protected static final java.lang.String TAG_code
See Also:
Constant Field Values

TAG_countrySubdivision

protected static final java.lang.String TAG_countrySubdivision
See Also:
Constant Field Values

TAG_street

protected static final java.lang.String TAG_street
See Also:
Constant Field Values

TAG_streetNumber

protected static final java.lang.String TAG_streetNumber
See Also:
Constant Field Values

TAG_lat

protected static final java.lang.String TAG_lat
See Also:
Constant Field Values

TAG_lng

protected static final java.lang.String TAG_lng
See Also:
Constant Field Values

TAG_distance

protected static final java.lang.String TAG_distance
See Also:
Constant Field Values

TAG_postalcode

protected static final java.lang.String TAG_postalcode
See Also:
Constant Field Values

TAG_postalCode

protected static final java.lang.String TAG_postalCode
See Also:
Constant Field Values

TAG_name

protected static final java.lang.String TAG_name
See Also:
Constant Field Values

TAG_placename

protected static final java.lang.String TAG_placename
See Also:
Constant Field Values

TAG_cityName

protected static final java.lang.String TAG_cityName
See Also:
Constant Field Values

TAG_adminName2

protected static final java.lang.String TAG_adminName2
See Also:
Constant Field Values

TAG_adminCode1

protected static final java.lang.String TAG_adminCode1
See Also:
Constant Field Values

TAG_adminName1

protected static final java.lang.String TAG_adminName1
See Also:
Constant Field Values

TAG_countryCode

protected static final java.lang.String TAG_countryCode
See Also:
Constant Field Values

TAG_countryName

protected static final java.lang.String TAG_countryName
See Also:
Constant Field Values

TAG_speedCategory

protected static final java.lang.String TAG_speedCategory
See Also:
Constant Field Values

TAG_speedRestriction

protected static final java.lang.String TAG_speedRestriction
See Also:
Constant Field Values

TAG_isTollRoad

protected static final java.lang.String TAG_isTollRoad
See Also:
Constant Field Values

TAG_status

protected static final java.lang.String TAG_status
See Also:
Constant Field Values

ATTR_message

protected static final java.lang.String ATTR_message
See Also:
Constant Field Values

PROP_radiusKM

protected static final java.lang.String PROP_radiusKM
See Also:
Constant Field Values

PROP_hostName

protected static final java.lang.String PROP_hostName
See Also:
Constant Field Values

PROP_failoverHostName

protected static final java.lang.String PROP_failoverHostName
See Also:
Constant Field Values

PROP_primaryService

protected static final java.lang.String PROP_primaryService
See Also:
Constant Field Values

PROP_addressFailover

protected static final java.lang.String PROP_addressFailover
See Also:
Constant Field Values

PROP_postalFailover

protected static final java.lang.String PROP_postalFailover
See Also:
Constant Field Values

PROP_streetFailover

protected static final java.lang.String PROP_streetFailover
See Also:
Constant Field Values

PROP_placeFailover

protected static final java.lang.String PROP_placeFailover
See Also:
Constant Field Values

PROP_username

protected static final java.lang.String PROP_username
See Also:
Constant Field Values

PROP_token

protected static final java.lang.String PROP_token
See Also:
Constant Field Values

PROP_service_

protected static final java.lang.String PROP_service_
See Also:
Constant Field Values

HOST_PRIMARY

protected static java.lang.String HOST_PRIMARY

HOST_PRIMARY2

protected static java.lang.String HOST_PRIMARY2

HOST_FAILOVER

protected static java.lang.String HOST_FAILOVER

SERVICE_findNearestAddress

protected static final java.lang.String SERVICE_findNearestAddress
See Also:
Constant Field Values

SERVICE_findNearbyPlaceName

protected static final java.lang.String SERVICE_findNearbyPlaceName
See Also:
Constant Field Values

SERVICE_countrySubdivision

protected static final java.lang.String SERVICE_countrySubdivision
See Also:
Constant Field Values

SERVICE_findNearbyPostalCodes

protected static final java.lang.String SERVICE_findNearbyPostalCodes
See Also:
Constant Field Values

SERVICE_findNearbyStreetsOSM

protected static final java.lang.String SERVICE_findNearbyStreetsOSM
See Also:
Constant Field Values

TIMEOUT_ReverseGeocode

protected static final int TIMEOUT_ReverseGeocode
See Also:
Constant Field Values

TIMEOUT_Geocode

protected static final int TIMEOUT_Geocode
See Also:
Constant Field Values

MAX_ADDRESS_DISTANCE_KM

protected static final double MAX_ADDRESS_DISTANCE_KM
See Also:
Constant Field Values

ENCODING_UTF8

protected static final java.lang.String ENCODING_UTF8
See Also:
Constant Field Values
Constructor Detail

GeoNames

public GeoNames(java.lang.String name,
                java.lang.String key,
                RTProperties rtProps)
Constructor

Parameters:
name - The name assigned to this ReverseGeocodeProvider
key - The optional authorization key
rtProps - The properties associated with this ReverseGeocodeProvider
Method Detail

getPostalCodeLocation

public static GeoPoint getPostalCodeLocation(java.lang.String postalCode,
                                             java.lang.String country,
                                             int timeoutMS)

getPostalCodeLocation_xml

public static java.lang.String getPostalCodeLocation_xml(java.lang.String postalCode,
                                                         java.lang.String country,
                                                         int timeoutMS)

getCityLocation

public static GeoPoint getCityLocation(java.lang.String address,
                                       java.lang.String state,
                                       java.lang.String country,
                                       int timeoutMS)

getCityLocation_xml

public static java.lang.String getCityLocation_xml(java.lang.String city,
                                                   java.lang.String state,
                                                   java.lang.String country,
                                                   int timeoutMS)

isFastOperation

public boolean isFastOperation()
Returns true if locally resolved, false otherwise. (ie. remote address resolution takes more than 20ms to complete)

Specified by:
isFastOperation in interface GeocodeProvider
Specified by:
isFastOperation in interface ReverseGeocodeProvider
Specified by:
isFastOperation in interface SubdivisionProvider
Overrides:
isFastOperation in class ReverseGeocodeProviderAdapter
Returns:
true if locally resolved, false otherwise.

getGeocodeTimeout

protected int getGeocodeTimeout()
Returns the Geocode timeout


getReverseGeocodeTimeout

protected int getReverseGeocodeTimeout()
Returns the ReverseGeocode timeout


hasUsername

public boolean hasUsername()
Returns true if a username has been defined

Returns:
True if a username has been defined

getReverseGeocode

public ReverseGeocode getReverseGeocode(GeoPoint gp,
                                        java.lang.String localeStr,
                                        boolean cache)
Returns a ReverseGeocode instance for the specified GeoPoint

Specified by:
getReverseGeocode in interface ReverseGeocodeProvider
Specified by:
getReverseGeocode in class ReverseGeocodeProviderAdapter
Parameters:
gp - The GeoPoint
Returns:
The ReverseGeocode instance

getGeocode

public GeoPoint getGeocode(java.lang.String address,
                           java.lang.String country)
Description copied from interface: GeocodeProvider
Returns GeoPoint of specified address

Specified by:
getGeocode in interface GeocodeProvider

getHostname

protected java.lang.String getHostname(boolean primary)
Gets the hostname

Parameters:
primary - True to return the primary host, else failover host
Returns:
The hostname

getGeonamesURL

protected java.lang.StringBuffer getGeonamesURL(boolean primary,
                                                java.lang.String service,
                                                GeoPoint gp)
Returns the URL for the specified Geonames service

Parameters:
primary - True for primary server, false for failover server
service - The Geonames service
Returns:
The Geonames service URL

init_findNearbyPlaceName

protected void init_findNearbyPlaceName()
Initializes the 'findNearbyPlaceName' XML document generator. Must be called from the constructor.


getPlaceNameReverseGeocode

public ReverseGeocode getPlaceNameReverseGeocode(GeoPoint gp)
Returns a PlaceName ReverseGeocode instance

Parameters:
gp - The GeoPoint
Returns:
The ReverseGeocode instance

init_findNearestAddress

protected void init_findNearestAddress()
Initializes the 'findNearestAddress' XML document generator. Must be called from the constructor.


getMaximumSearchRadius

protected double getMaximumSearchRadius()
Returns the maximum search radius, in kilometers

Returns:
The maximum search radius, in kilometers

getAddressReverseGeocode

public ReverseGeocode getAddressReverseGeocode(GeoPoint gp,
                                               java.lang.String localeStr)
Returns a ReverseGeocode instance containing address information

Parameters:
gp - The GeoPoint
Returns:
The ReverseGeocode instance

init_findNearbyStreetsOSM

protected void init_findNearbyStreetsOSM()
Initializes the 'findNearbyStreetsOSM' XML document generator. Must be called from the constructor.


getNearbyStreetNameReverseGeocode

public ReverseGeocode getNearbyStreetNameReverseGeocode(GeoPoint gp)

init_findNearbyPostalCodes

protected void init_findNearbyPostalCodes()
Initializes the 'findNearbyPostalCodes' XML document generator. Must be called from the constructor.


getPostalReverseGeocode

public ReverseGeocode getPostalReverseGeocode(GeoPoint gp)

init_countrySubdivision

protected void init_countrySubdivision()
Initializes the 'countrySubdivision' XML document generator. Must be called from the constructor.


getSubdivision

public java.lang.String getSubdivision(GeoPoint gp)
Description copied from interface: SubdivisionProvider
Return the subdivision of the specified point (in the US, this is "US/" as in "US/CA")

Specified by:
getSubdivision in interface SubdivisionProvider

GetXMLDocument

protected static org.w3c.dom.Document GetXMLDocument(java.lang.String url,
                                                     int timeoutMS)
Reads the XML response from the specified URL location, returning an XML Document

Parameters:
url - The Geonames URL
Returns:
An XML Document, or null if the XML Document could not be read

GetElementValueMap

protected static java.util.Map<java.lang.String,java.lang.String> GetElementValueMap(org.w3c.dom.Element elem)

GetNodeText

protected static java.lang.String GetNodeText(org.w3c.dom.Node root)

main

public static void main(java.lang.String[] argv)
Main entery point for debugging/testing