We have released a Python module that generates a regional mesh for Japan

TL;DR

https://github.com/MIERUNE/japan-mesh-tool

--The Python module that generates the Japanese standard region mesh has been released as OSS. --Can generate meshes of commonly used units up to 50m --Including the experimentally created Rust version

What is a standard area mesh?

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. [Regional Mesh-Wikipedia](https://ja.wikipedia.org/wiki/%E5%9C%B0%E5%9F%9F%E3%83%A1%E3%83%83%E3%82%B7% E3% 83% A5)

Reason to publish

――It seems that there is no OSS that can generate a regional mesh up to 50m and can be used easily. ――There are many cases where a regional mesh is needed on various occasions, and it seems that various people are developing it each time.

japan-mesh-tool https://github.com/MIERUNE/japan-mesh-tool It will be distributed under the MIT license.

Execution environment

--Developed with Python 3.8 (I think it will work for 3 series) --Uses only standard modules (no dependencies)

function

(1) Mesh order (2) Output mesh data in geojsonl format from the area (latitude and longitude). geojsonl format: A text file in which geojson is separated by feature, also called GeoJSON Seq.

Corresponding mesh order

Degree Also known as Details Mesh code
1 - 80km mesh 4 digits
2 - 10km mesh 6 digits
3 - 1km mesh 8-digit
4 500 500m mesh 10 digits
5 250 250m mesh 12 digits
6 125 125m mesh 14 digits
7 50 50m mesh 14 digits

How to use (Python)

python python/japanmesh/main.py <meshnum:Mesh order> <-e:Area designation,"Comma-separated latitude and longitude Comma-separated latitude and longitude"Specify in format> <-d:Destination>

Command example

python python/japanmesh/main.py 5 -e 142.2,44.0 142.3,44.5 -d ./

4th mesh and above can be specified by another name

python python/japanmesh/main.py 250 -e 142.2,44.0 142.3,44.5 -d ./

The area and save destination can be omitted. In that case, the primary mesh for the whole country is output to the current directory.

python python/japanmesh/main.py 1

Since the total number of meshes is huge for 3rd order meshes and above, it takes time to process if a large area is specified.

How to use (Rust, experimental)

I wrote the same process in Rust on a trial basis to improve the processing speed. rust / japanmesh is a compiled binary (rust / japanmesh.exe for Windows).

rust/japanmesh <meshnum:Mesh order> <Area specification(Optional)>

Always output the geojsonl file to the current directory.

Command example

macOS(64bit)

rust/japanmesh 5 142.2,44.0 142.3,44.5

Or omit the area

rust/japanmesh 3

As a Python module

--./python/japanmesh itself can be imported as a Python module --In that case, you can only use the get_meshes () function (See ./python/sample.py for usage examples)

Mesh generation rules

Red: 3rd, White: 4th (3rd is divided into 4) 01.png

Blue: 5th order, Black: 7th order (5th order is divided into 25) スクリーンショット 2020-08-18 17.28.12.png

--3 Follow https://www.stat.go.jp/data/mesh/pdf/gaiyo1.pdf until the next --From the 4th onward, add 2 digits to the end of the upper mesh code based on the following rules (as shown in the image above). --Set the lower left to 00 ――If you go up one, it will be 10, if you go two, it will be 20 ... --If you go one to the right, it will be 01, if you go two, it will be 02 ...

Recommended Posts

We have released a Python module that generates a regional mesh for Japan
We have released an extension that allows you to define xarray data like a Python data class.
We have released a trained model of fastText
Publish a Python module that calculates meteorological factors
Let's make a module for Python using SWIG
A python script that generates a sample dataset for checking the operation of a classification tree
I made a VM that runs OpenCV for Python
Create a Python module
The story of making a module that skips mail with python