モジュールメソッド

jageocoder モジュールのメソッドは、以下の3つのグループに分類できます。

住所辞書データベースのインストールや削除などの管理を行なう

jageocoder.download_dictionary(), jageocoder.install_dictionary(), jageocoder.uninstall_dictionary(), jageocoder.migrate_dictionary(), jageocoder.create_trie_index(), jageocoder.dictionary_version()

モジュールの初期化や状態確認などの管理を行なう

jageocoder.init(), jageocoder.free(), jageocoder.is_initialized(), jageocoder.get_db_dir(), jageocoder.get_module_tree(), jageocoder.version()

検索機能を提供する

jageocoder.set_search_config(), jageocoder.get_search_config(), jageocoder.search(), jageocoder.searchNode(), jageocoder.reverse()

A Python module for Japanese-address geocoding.

注釈

Before using this module, install address-dictionary from the Web as follows:

$ python -m jageocoder install-dictionary

サンプル

You can get the latitude and longitude from a Japanese address by running the following steps.

>>> import jageocoder
>>> jageocoder.init()
>>> jageocoder.searchNode('<Japanese-address>')
jageocoder.create_trie_index() None

Create the TRIE index from the database file.

This function is a shortcut for AddressTree.create_trie_index().

jageocoder.download_dictionary(url: str) None

Download address-dictionary from the specified url into the current directory.

パラメータ:

url (str) -- The URL where the zipped address-dictionary file is available.

jageocoder.free()

Frees all objects created by 'init()'.

jageocoder.get_db_dir(mode: str = 'r') PathLike

Get the database directory.

パラメータ:

mode (str, optional(default='r')) -- Specifies the mode for searching the database directory. If 'a' or 'w' is set, search a writable directory. If 'r' is set, search a database file that already exists.

戻り値:

  • The path to the database directory.

  • If no suitable directory is found, raise an AddressTreeException.

メモ

This method searches a directory in the following order of priority. - 'JAGEOCODER_DB_DIR' environment variable - '(sys.prefix)/jageocoder/db/' - '(site.USER_BASE)/jageocoder/db/'

jageocoder.get_module_tree() Optional[AddressTree]

Get the module-level AddressTree singleton object.

戻り値:

The singleton object.

戻り値の型:

AddressTree

jageocoder.get_search_config(keys: Optional[Union[str, List[str]]] = None) dict

Get current configurable search parameters.

パラメータ:

keys (str, List[str], optional) -- If a name of parameter is specified, return its value. Otherwise, a dict of specified key and its value pairs will be returned.

戻り値の型:

Any, or dict.

jageocoder.init(db_dir: Optional[PathLike] = None, mode: Optional[str] = 'r', debug: Optional[bool] = False, **kwargs) None

Initialize the module-level AddressTree object jageocoder.tree ready for use.

パラメータ:
  • db_dir (os.PathLike, optional) -- The database directory. 'address.db' and 'address.trie' are stored in this directory.

  • mode (str, optional(default='r')) --

    Specifies the mode for opening the database.

    • In the case of 'a', if the database already exists, it will be used. If it does not exist, create a new one.

    • In the case of 'w', if the database already exists, delete it first. Then create a new one.

    • In the case of 'r', if the database already exists, it will be used. Otherwise raise a JageocoderError exception.

  • debug (bool, Optional(default=False)) -- Debugging flag.

jageocoder.install_dictionary(path_or_url: PathLike, db_dir: Optional[PathLike] = None) None

Install address-dictionary from the specified path or url.

パラメータ:
  • path_or_url (os.PathLike) -- The file path or url where the zipped address-dictionary file is available.

  • db_dir (os.PathLike, optional) -- The directory where the database files will be installed. If omitted, it will be determined by get_db_dir().

jageocoder.installed_dictionary_version(db_dir: Optional[PathLike] = None) str

Get the installed dictionary version.

パラメータ:

db_dir (os.PathLike, optional) -- The directory where the database files has been installed. If omitted, it will be determined by get_db_dir().

戻り値:

The version string of the installed dicitionary.

戻り値の型:

str

jageocoder.is_initialized() bool

Checks if the module has been initialized with init().

戻り値:

True if the module is initialized, otherwise False.

戻り値の型:

bool

jageocoder.migrate_dictionary(db_dir: Optional[PathLike] = None) None

Migrate address-dictionary.

パラメータ:

db_dir (os.PathLike, optional) -- The directory where the database files has been installed. If omitted, it will be determined by get_db_dir().

jageocoder.reverse(x: float, y: float, level: Optional[int] = None) dict

Reverse geocoding.

jageocoder.search(query: str) dict

Search node from the tree by the query.

パラメータ:

query (str) -- An address notation to be searched.

戻り値:

  • A dict containing the following elements.

  • matched (str) -- The matching substring.

  • candidates (list of dict) -- List of dict representation of nodes with the longest match to the query string.

jageocoder.searchNode(query: str) List[Result]

Searches for address nodes corresponding to an address notation and returns the matching substring and a list of nodes.

パラメータ:

query (str) -- An address notation to be searched.

戻り値:

A list of AddressNode and matched substring pairs.

戻り値の型:

list

注釈

The search_by_trie function returns the standardized string as the match string. In contrast, the searchNode function returns the de-starndized string.

サンプル

>>> import jageocoder
>>> jageocoder.init()
>>> jageocoder.searchNode('多摩市落合1-15-2')
[[[11460207:東京都(139.69178,35.68963)1(lasdec:130001/jisx0401:13)]>[12063502:多摩市(139.446366,35.636959)3(jisx0402:13224)]>[12065383:落合(139.427097,35.624877)5(None)]>[12065384:一丁目(139.427097,35.624877)6(None)]>[12065390:15番地(139.428969,35.625779)7(None)], '多摩市落合1-15-']]
jageocoder.set_search_config(**kwargs)

Set configurable search parameters.

注釈

The possible keywords and their meanings are as follows.

  • best_only: bool (default = True)

    If set to False, returns all search result candidates whose prefix matches.

  • aza_skip: bool, None (default = False)

    Specifies how to skip aza-names while searching nodes. - If None, make the decision automatically - If False, do not skip - If True, always skip

  • require_coordinates: bool (default = True)

    If set to False, nodes without coordinates are also included in the search.

  • target_area: List[str] (Default = [])

    Specify the areas to be searched. The area can be specified by the list of name of the node (such as prefecture name or city name), or JIS code.

jageocoder.uninstall_dictionary(db_dir: Optional[PathLike] = None) None

Uninstall address-dictionary.

パラメータ:

db_dir (os.PathLike, optional) -- The directory where the database files has been installed. If omitted, it will be determined by get_db_dir().