Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Japanese address geocoder that works both offline and online.

License

NotificationsYou must be signed in to change notification settings

t-sagara/jageocoder

Repository files navigation

日本語版は README_ja.md をお読みください。

This is a Python port of the Japanese-address geocoderDAMS used in CSIS at the University of Tokyo's"Address Matching Service" andGSI Maps.

Getting Started

This package provides address-geocoding and reverse-geocoding functionality for Python programs. The basic usage is to specify a dictionary withinit() then callsearch() to get geocoding results.

>>>importjageocoder>>>jageocoder.init(url='https://jageocoder.info-proto.com/jsonrpc')>>>jageocoder.search('新宿区西新宿2-8-1'){'matched':'新宿区西新宿2-8-','candidates': [{'id':5961406,'name':'8番','x':139.691778,'y':35.689627,'level':7,'note':None,'fullname': ['東京都','新宿区','西新宿','二丁目','8番']}]}

How to install

Prerequisites

Requires Python 3.9 or later and 3.12 or earlier.

All other required packages will be installed automatically.

Install instructions

  • Install the package withpip install jageocoder

To use Jageocoder, you need to install the "Dictionary Database" on the same machine or connect to the RPC service provided byjageocoder-server .

Install Dictionary Database

When a dictionary database is installed, large amounts of data can be processed at high speed. A database covering addresses in Japan requires 25 GB or more of storage.

  • Download an address database file compatible with that version fromhere

    jageocoder download-dictionary https://www.info-proto.com/static/jageocoder/latest/v2/jukyo_all_v21.zip
  • Install the dictionary withinstall-dictionary command

    jageocoder install-dictionary jukyo_all_v21.zip

If you need to know the location of the dictionary directory,performget-db-dir command as follows. (Or calljageocoder.get_db_dir() in your script)

jageocoder get-db-dir

If you prefer to create the database in another location, set the environment variableJAGEOCODER_DB2_DIR before executinginstall_dictionary() to specify the directory.

export JAGEOCODER_DB2_DIR='/usr/local/share/jageocoder/db2'install-dictionary<db-file>

Connect to the Jageocoder server

Since dictionary databases are large in size, installing them on multiple machines consumes storage and requires time and effort to update them.Instead of installing a dictionary database on each machine, you can connect to a Jageocoder server to perform the search process.

If you want to use a server, specify the server endpoint in the environment variableJAGEOCODER_SERVER_URL. For a public demonstration server, use the following

export JAGEOCODER_SERVER_URL=https://jageocoder.info-proto.com/jsonrpc

However, the server for public demonstrations cannot withstand the load when accesses are concentrated, so it is limited to one request per second.If you want to process a large number of requests, please refer tohere to set up your own Jageocoder server. The endpoint is '/jsonrpc' on the server.

Uninstall instructions

Remove the directory containing the database, or performuninstall-dictionary command as follows.

jageocoder uninstall-dictionary

Then, uninstall the package withpip command.

pip uninstall jageocoder

How to use

Use from the command line

Jageocoder is intended to be embedded in applications as a library and used by calling the API, but a simple command line interface is also provided.

For example, to geocode an address, execute the following command.

jageocoder search 新宿区西新宿2-8-1

You can check the list of available commands with--help.

jageocoder --help

Using API

First, import jageocoder and initialize it withinit().

>>>importjageocoder>>>jageocoder.init()

The parameterdb_dir ofinit() can be used to specify the directory where the address database is installed. Alternatively, you can specify the endpoint URL of the Jageocoder server withurl. If it is omitted, the value of the environment variable is used.

Search for latitude and longitude by address

Usesearch() to search for the address you want to check the longitude and latitude of.

Thesearch() function returns a dict withmatched asthe matched string andcandidates as the list of search results.(The results are formatted for better viewing)

Each element ofcandidates contains the information of an address node (AddressNode).

>>>jageocoder.search('新宿区西新宿2-8-1'){'matched':'新宿区西新宿2-8-','candidates': [{'id':12299846,'name':'8番','x':139.691778,'y':35.689627,'level':7,'note':None,'fullname': ['東京都','新宿区','西新宿','二丁目','8番']  }]}

The meaning of the items is as follows

  • id: ID in the database
  • name: Address notation
  • x: longitude
  • y: latitude
  • level: Address level (1:Prefecture, 2:County, 3:City and 23 district,4:Ward, 5:Oaza, 6:Aza and Chome, 7:Block, 8:Building)
  • note: Notes such as city codes
  • fullname: List of address notations from the prefecture level to this node

Search for addresses by longitude and latitude

You can specify the latitude and longitude of a point and look up the address of that point (so-called reverse geocoding).

When you pass the longitude and latitude of the point you wish to look up toreverse(), you can retrieve up to three address nodes surrounding the specified point.

>>>importjageocoder>>>jageocoder.init()>>>triangle=jageocoder.reverse(139.6917,35.6896,level=7)>>>iflen(triangle)>0:...print(triangle[0]['candidate']['fullname'])...['東京都','新宿区','西新宿','二丁目','8番']

In the example above, thelevel optional parameter is set to 7 to search down to the block (街区・地番) level.

Note

Indexes for reverse geocoding are automatically created the first time you perform reverse geocoding. Note that this process can take a long time.

Explore the attribute information of an address

UsesearchNode() to retrieve information about an address.

This function returns a list of typejageocoder.result.Result .You can access the address node from node element of the Result object.

>>>results=jageocoder.searchNode('新宿区西新宿2-8-1')>>>len(results)1>>>results[0].matched'新宿区西新宿2-8-'>>> type(results[0].node)<class'jageocoder.node.AddressNode'>>>>node=results[0].node>>>node.get_fullname()['東京都','新宿区','西新宿','二丁目','8番']

Get GeoJSON representation

You can use theas_geojson() method of the Result and AddressNodeobjects to obtain the GeoJSON representation.

>>>results[0].as_geojson(){'type':'Feature','geometry': {'type':'Point','coordinates': [139.691778,35.689627]},'properties': {'id':12299851,'name':'8番','level':7,'note':None,'fullname': ['東京都','新宿区','西新宿','二丁目','8番'],'matched':'新宿区西新宿2-8-'}}>>>results[0].node.as_geojson(){'type':'Feature','geometry': {'type':'Point','coordinates': [139.691778,35.689627]},'properties': {'id':12299851,'name':'8番','level':7,'note':None,'fullname': ['東京都','新宿区','西新宿','二丁目','8番']}}

Get the local government codes

There are two types of local government codes: JISX0402 (5-digit) and Local Government Code (6-digit).

You can also obtain the prefecture code JISX0401 (2 digits).

>>>node.get_city_jiscode()# 5-digit code'13104'>>>node.get_city_local_authority_code()# 6-digit code'131041'>>>node.get_pref_jiscode()# prefecture code'13'

Get link URLs to maps

Generate URLs to link to GSI and Google maps.

>>>node.get_gsimap_link()'https://maps.gsi.go.jp/#16/35.689627/139.691778/'>>>node.get_googlemap_link()'https://maps.google.com/maps?q=35.689627,139.691778&z=16'

Traverse the parent node

A "parent node" is a node that represents a level above the address.Get the node by attributeparent.

Now thenode points to '8番', so the parent node will be '二丁目'.

>>>parent=node.parent>>>parent.get_fullname()['東京都','新宿区','西新宿','二丁目']>>>parent.x,parent.y(139.691774,35.68945)

Traverse the child nodes

A "child node" is a node that represents a level below the address.Get the node by attributechildren.

There is one parent node, but there are multiple child nodes.The actual return is a SQL query object, but it can be looped throughwith an iterator or cast to a list.

Now theparent points to '二丁目', so the child node will bethe block number (○番) contained therein.

>>>parent.children<sqlalchemy.orm.dynamic.AppenderQueryobjectat0x7fbc08404b38>>>> [child.nameforchildinparent.children]['10番','11番','1番','2番','3番','4番','5番','6番','7番','8番','9番']

For developers

Documentation

Tutorials and references arehere.

Create your own dictionary

Consider usingjageocoder-converter.

Contributing

Address notation varies. So suggestions for logic improvements are welcome.Please submit an issue with examples of address notations in use and how they should be parsed.

Authors

License

This project is licensed underthe MIT License.

This is not the scope of the dictionary data license. Please follow the license of the respective dictionary data.

Acknowledgements

We would like to thank CSIS for allowing us to provide address matching services on their institutional website for over 20 years.

We would also like to thank Professor Asanobu Kitamoto of NII for providing us with a large sample of areas using the older address system and for his many help in confirming the results of our analysis.

About

Japanese address geocoder that works both offline and online.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp