Package: jageocoder
jageocoder - A Python Japanese geocoder日本語版は README_ja.md をお読みください。This is a Python port of the Japanese-address geocoder used in CSIS at the University of Tokyo's"Address Matching Service"andGSI Maps.Getting StartedThis package provides address-geocoding functionality for Python programs. The basic usage is to specify a dictionary withinit()then callsearch()to get geocoding results.python>>>importjageocoder>>>jageocoder.init()>>>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 installPrerequisitesRequires Python 3.7.x or later.All other required packages will be installed automatically.Install instructionsInstall the package withpip install jageocoderDownload an address database file compatible with that version fromhereInstall the dictionary withinstall-dictionarycommandpipinstalljageocoder
wgethttps://www.info-proto.com/static/jageocoder/latest/v2/jukyo_all_v20.zip
jageocoderinstall-dictionaryjukyo_all_v20.zipThe dictionary database will be installed under{sys.prefix}/jageocoder/db2/by default,
however if the user doesn't have write permission there,{site.USER_DATA}/jageocoder/db2/instead.If you need to know the location of the dictionary directory,
performget-db-dircommand as follows. (Or calljageocoder.get_db_dir()in your script)jageocoderget-db-dirIf you prefer to create it in another location, set the environment
variableJAGEOCODER_DB2_DIRbefore executinginstall_dictionary()to specify the directory.exportJAGEOCODER_DB2_DIR='/usr/local/share/jageocoder/db2'install-dictionary<db-file>Uninstall instructionsRemove the directory containing the database, or performuninstall-dictionarycommand as follows.jageocoderuninstall-dictionaryThen, uninstall the package withpipcommand.pipuninstalljageocoderHow to useUse from the command lineWe assume that jageocoder will be embedded in applications
as a library and used by calling the API, but for testing purposes,
you can check the geocoding results with the following command.jageocodersearch新宿区西新宿２－８－１You can check the list of available commands with--help.jageocoder--helpUsing APIFirst, import jageocoder and initialize it withinit().>>> import jageocoder
>>> jageocoder.init()Search for latitude and longitude by addressUsesearch()to search for the address you want to check the longitude and latitude of.Thesearch()function returns a dict withmatchedas
the matched string andcandidatesas the list of search results.
(The results are formatted for better viewing)Each element ofcandidatescontains the information of an address node (AddressNode).>>> jageocoder.search('新宿区西新宿２－８－１')
{
  'matched': '新宿区西新宿２－８－',
  'candidates': [{
    'id': 12299846, 'name': '8番',
    'x': 139.691778, 'y': 35.689627, 'level': 7, 'note': None,
    'fullname': ['東京都', '新宿区', '西新宿', '二丁目', '8番']
  }]
}The meaning of the items is as followsid: ID in the databasename: Address notationx: longitudey: latitudelevel: 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 codesfullname: List of address notations from the prefecture level to this nodeSearch for addresses by longitude and latitudeNote: This method is not available in v2 series.Explore the attribute information of an addressUsesearchNode()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('新宿区西新宿２－８－１')
>>> len(results)
1
>>> results[0].matched
'新宿区西新宿２－８－'
>>> type(results[0].node)
<class 'jageocoder.node.AddressNode'>
>>> node = results[0].node
>>> node.get_fullname()
['東京都', '新宿区', '西新宿', '二丁目', '8番']Get GeoJSON representationYou can use theas_geojson()method of the Result and AddressNode
objects 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': '新宿区西新宿２－８－'}}
>>> 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 codesThere 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 mapsGenerate 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 nodeA "parent node" is a node that represents a level above the address.
Get the node by attributeparent.Now thenodepoints 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 nodesA "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 through
with an iterator or cast to a list.Now theparentpoints to '二丁目', so the child node will be
the block number (○番) contained therein.>>> parent.children
<sqlalchemy.orm.dynamic.AppenderQuery object at 0x7fbc08404b38>
>>> [child.name for child in parent.children]
['10番', '11番', '1番', '2番', '3番', '4番', '5番', '6番', '7番', '8番', '9番']Create your own dictionaryConsider usingjageocoder-converter.ToDosSupporting address changesThe functionality to handle address changes due to municipal consolidation, etc.
has already been implemented in the C++ version, but will be implemented
in this package in the future.ContributingAddress 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.AuthorsTakeshi SAGARA-Info-proto Co.,Ltd.LicenseThis 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.AcknowledgementsWe 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.