Skip to content

Commit

Permalink
Fix 1km code-to-bbox for e-Stat (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
ciscorn authored Jun 30, 2024
1 parent 0ac08a1 commit 9573e70
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion japanese_grids/algorithms/utils/gridsquare_to_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ def grid_square_code_to_bbox( # noqa: C901
if length == 6:
return (lng, lat / 1.5, lng + 0.125, (lat + 0.125) / 1.5)

# 1km
lat10 = int(code[6]) * 0.125
lng10 = int(code[7]) * 0.125
if length == 8:
lat1 = lat + lat10 / 10
lng1 = lng + lng10 / 10
lat2 = lat + (lat10 + 0.125) / 10
lng2 = lng + (lng10 + 0.125) / 10
return (lng1, lat1 / 1.5, lng, lat / 1.5)
return (lng1, lat1 / 1.5, lng2, lat2 / 1.5)

# 1/2 (500m)
a = code[8]
if a not in _VALID_QUAD:
return None
Expand All @@ -47,6 +49,7 @@ def grid_square_code_to_bbox( # noqa: C901
lng2 = lng + (lng10 + 0.0625) / 10
return (lng1, lat1 / 1.5, lng2, lat2 / 1.5)

# 1/4 (250m)
a = code[9]
if a not in _VALID_QUAD:
return None
Expand All @@ -61,6 +64,7 @@ def grid_square_code_to_bbox( # noqa: C901
lng2 = lng + (lng10 + 0.03125) / 10
return (lng1, lat1 / 1.5, lng2, lat2 / 1.5)

# 1/8 (125m)
a = code[10]
if a not in _VALID_QUAD:
return None
Expand Down

0 comments on commit 9573e70

Please sign in to comment.