# Introduction

I have the opportunity to work with big data whose location is provided in the regional mesh code, and I've created a function that converts it to a latitude / longitude form that is easy to handle in the program, so I'll share it.

# Referenced site

This article corresponds to the conversion code up to the 3rd mesh published in this blog up to 1/8 area mesh.

# What is a regional mesh code?

According to an article in Wikipedia

``````The area mesh (chiiki mesh) is a mesh that divides the area into meshes of almost the same size based on latitude and longitude for use in statistics. The code for identifying the mesh is called the regional mesh code.

In the production and provision of maps, paper maps are prepared for each regional mesh, or digital map data files are prepared.
``````

It is standardized by JIS X 0410. It is organized in an easy-to-understand manner on the Esri Japan site.

# Function to convert from mesh code to latitude / longitude

``````def get_latlon(meshCode):

#Convert to string
meshCode = str(meshCode)

#Calculation for primary mesh
code_first_two = meshCode[0:2]
code_last_two = meshCode[2:4]
code_first_two = int(code_first_two)
code_last_two = int(code_last_two)
lat  = code_first_two * 2 / 3
lon = code_last_two + 100

if len(meshCode) > 4:
#Calculation for secondary mesh
if len(meshCode) >= 6:
code_fifth = meshCode[4:5]
code_sixth = meshCode[5:6]
code_fifth = int(code_fifth)
code_sixth = int(code_sixth)
lat += code_fifth * 2 / 3 / 8
lon += code_sixth / 8

#Calculation for 3rd mesh
if len(meshCode) >= 8:
code_seventh = meshCode[6:7]
code_eighth = meshCode[7:8]
code_seventh = int(code_seventh)
code_eighth = int(code_eighth)
lat += code_seventh * 2 / 3 / 8 / 10
lon += code_eighth / 8 / 10

# 1/Calculation for 2 mesh
if len(meshCode) >= 9:
code_nineth = meshCode[8:9]
code_nineth = int(code_nineth)
if code_nineth % 2 == 0:
lon += 0.00138888
if code_nineth > 2:
lat += 0.00416666

# 1/Calculation for 4 mesh
if len(meshCode) >= 10:
code_tenth = meshCode[9:10]
code_tenth = int(code_tenth)
if code_tenth % 2 == 0:
lon += 0.00138888 / 2
if code_tenth > 2:
lat += 0.00416666 / 2

# 1/Calculation for 8 mesh
if len(meshCode) >= 11:
code_eleventh = meshCode[10:11]
code_eleventh = int(code_eleventh)
if code_eleventh % 2 == 0:
lon += 0.00138888 / 2 / 2
if code_eleventh > 2:
lat += 0.00416666 / 2 / 2

return lat, lon
``````

## How to use the function

If you are familiar with Python, you can see it,

``````lat,lon =  get_latlon(60413212422)
``````

If you do, the latitude will be assigned to `lat` and the longitude will be assigned to` lon`.