5
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

住所から位置情報(緯度経度)を求める.PythonでGeocode 〜Geocoderとpydams〜

Posted at

Google Colaboratory使用

#Geocoder
https://qiita.com/yoshi_yast/items/bb75d8fceb712f1f49d1
を参照

#pydams
詳細は以下
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/

##準備

!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
#実行結果
#pydams==1.0.4
from pydams import DAMS
from pydams.helpers import pretty_print

DAMS.init_dams()
address = u"東京都港区芝公園4丁目2−8"

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

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

"""実行結果
score: 5
candidates: 1
	candidate: 0, address level: 7
		address:東京都, lat:35.68949890136719, long:139.69163513183594
		address:港区, lat:35.65850067138672, long:139.75155639648438
		address:芝公園, lat:35.65782928466797, long:139.75172424316406
		address:四丁目, lat:35.65620422363281, long:139.7484588623047
		address:2番, lat:35.658538818359375, long:139.74542236328125
score: 5
candidates: 1
	candidate: 0, address level: 7
		address:東京都港区芝公園四丁目2番, lat:35.658538818359375, long:139.74542236328125
"""

##住所を入力とし,緯度経度を返す関数

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'))
#[35.658538818359375, 139.74542236328125]
5
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?