Obtain location information (latitude and longitude) from the address. Geocode in Python ~ Geocoder and pydams ~

Use Google Colaboratory

Geocoder https://qiita.com/yoshi_yast/items/bb75d8fceb712f1f49d1 See

pydams Details below https://github.com/hottolink/pydams http://newspat.csis.u-tokyo.ac.jp/geocode/modules/dams/index.php?content_id=2 https://www.hottolink.co.jp/blog/20180823_98734/

Preparation

!wget http://newspat.csis.u-tokyo.ac.jp/download/dams-4.3.4.tgz
!tar -xzvf dams-4.3.4.tgz
!git clone https://github.com/hottolink/pydams.git
!patch -d ./dams-4.3.4 -p1 < ./pydams/patch/dams-4.3.4.diff
%cd dams-4.3.4
!./configure; make
!make install
!ldconfig
!ldconfig -v | grep dams
!ldconfig -v | grep dams
!make dic
!make install-dic
%cd ../
![ ! -d 'pydams' ] && git clone https://github.com/hottolink/pydams.git
%cd pydams
!make all
!make install
!pip freeze | grep pydams
#Execution result
#pydams==1.0.4
from pydams import DAMS
from pydams.helpers import pretty_print

DAMS.init_dams()
address = u"4-2-8 Shibakoen, Minato-ku, Tokyo"

# geocode() method
geocoded = DAMS.geocode(address)
pretty_print(geocoded)

# geocode_simplify() method
geocoded = DAMS.geocode_simplify(address)
pretty_print(geocoded)

"""Execution result
score: 5
candidates: 1
	candidate: 0, address level: 7
		address:Tokyo, lat:35.68949890136719, long:139.69163513183594
		address:Minato-ku, lat:35.65850067138672, long:139.75155639648438
		address:Shiba Park, lat:35.65782928466797, long:139.75172424316406
		address:4-chome, lat:35.65620422363281, long:139.7484588623047
		address:No. 2, lat:35.658538818359375, long:139.74542236328125
score: 5
candidates: 1
	candidate: 0, address level: 7
		address:4-2 Shibakoen, Minato-ku, Tokyo, lat:35.658538818359375, long:139.74542236328125
"""

A function that takes an address and returns latitude and longitude

def GEOCODE(address):
  DAMS.init_dams()
  # geocode() method
  geocoded = DAMS.geocode_simplify(address)
  res = geocoded['candidates'][0]
  return [res['y'], res['x']]
print(GEOCODE('4-2-8 Shibakoen, Minato-ku, Tokyo'))
#[35.658538818359375, 139.74542236328125]

Recommended Posts

Obtain location information (latitude and longitude) from the address. Geocode in Python ~ Geocoder and pydams ~
Get the address from latitude and longitude
Internal / external judgment with Python: Obtain the city / town / village name from the latitude / longitude information of any point
Find the distance from latitude and longitude (considering the roundness of the earth).
Find the waypoint from latitude and longitude (considering the roundness of the earth).
Fill the string with zeros in python and count some characters from the string
Use the LibreOffice app in Python (2) Manipulate calc (from macros and externals)
Visualize accelerometer information from the microcomputer board in real time with mbed + Python
Pulling songwriting, composition and arrangement information from the Tower Records site with Python
Location information data display in Python --Try plotting with the map display library (folium)-
In Python, I made a LINE Bot that sends pollen information from location information.
About the difference between "==" and "is" in python
Load and execute command from yml in python
Download Geographical Survey tiles from latitude and longitude
I compared the speed of the reference of the python in list and the reference of the dictionary comprehension made from the in list.
Give latitude and longitude point sequence data and try to identify the road from OpenStreetMap data
The simplest Python memo in Japan (classes and objects)
Basic information Write the 2018 fall algorithm problem in Python
Receive the form in Python and do various things
Output the time from the time the program was started in python
Carefully understand the exponential distribution and draw in Python
Plot and understand the multivariate normal distribution in Python
Find the part that is 575 from Wikipedia in Python
Carefully understand the Poisson distribution and draw in Python
Find the Hermitian matrix and its eigenvalues in Python
Get your current location and user agent in Python
Approximately 200 latitude and longitude data for hospitals in Tokyo
YOLP: Extract latitude and longitude with Yahoo! Geocoder API.
Extract each Location from Stargazers in the Github repository
Put Ubuntu in Raspi, put Docker on it, and control GPIO with python from the container