6
5

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 5 years have passed since last update.

緯度経度からメッシュコードに変換するPython script

Last updated at Posted at 2017-01-07

10進数表記の緯度経度からメッシュコードに変換するPython scriptです.
(たまには,communityに貢献しようかと...)

Coordinate2MeshCode.py
def Coordinate2MeshCode( dLat, dLng ):
    # cf: http://white-bear.info/archives/1400
    # Make sure the input values are decimal 
    iMeshCode_1stMesh_Part_p = dLat *60 // 40;
    iMeshCode_1stMesh_Part_u = ( dLng - 100 ) // 1;
    iMeshCode_2ndMesh_Part_q = dLat *60 % 40 // 5;
    iMeshCode_2ndMesh_Part_v = ( ( dLng - 100 ) % 1 ) * 60 // 7.5;
    iMeshCode_3rdMesh_Part_r = dLat *60 % 40 % 5 * 60 // 30;
    iMeshCode_3rdMesh_Part_w = ( ( dLng - 100 ) % 1 ) * 60 % 7.5 * 60 // 45;
    iMeshCode = iMeshCode_1stMesh_Part_p * 1000000 + iMeshCode_1stMesh_Part_u * 10000 + iMeshCode_2ndMesh_Part_q * 1000 + iMeshCode_2ndMesh_Part_v * 100 + iMeshCode_3rdMesh_Part_r * 10 + iMeshCode_3rdMesh_Part_w;
    return iMeshCode;

Kobitoからのuploadテストも兼ねました.

更新履歴

Jan7,2017: 致命的な問題をひとまず修正 (@shiracamusさん、ご指摘どうもありがとうございます)

  1. 演算順序のミス
  2. 恥ずかしい英語のミス
    Pythonというか、プログラマとしてのコードの綺麗な書き方を学んだ方がいいですね、私。。。
    演算結果を確認して、続いて修正します
6
5
4

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
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?