Skip to content
项目

关于

JSON files for Thailand's geography data, including provinces, districts, subdistricts, and postal codes, adhering to best practices for optimal performance, ease of maintenance, and comprehensibility.

学习与教育

这些数字如何统计

实测星标增长

24小时
0
7天
+1
15天
+1
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文
Thailand Geography JSON

Thailand Geography JSON

A user-friendly collection of well-structured JSON files containing geographical data of Thailand, including provinces, districts, subdistricts, and postal codes.

License: MIT version Help Wanted


Contents

Important Files Overview

Discover the main JSON files with geographical data in the src/ directory:

  • geography.json - All-in-one data for provinces, districts, and subdistricts, including postal codes.
  • provinces.json - The 77 Thai provinces with their codes and names in English and Thai.
  • districts.json - The 928 Thai districts with codes, names in English and Thai, and related province codes.
  • subdistricts.json - The 7,436 Thai subdistricts with codes, names in English and Thai, and corresponding district and province codes.
  • multi-postal-codes.json - Audit list of the 86 subdistricts served by more than one postal code, with the original Thailand Post poster lines they were derived from.
  • regions.json - The official 6-region geographic division of the 77 provinces (North, Central, Northeast, East, West, South) with Thai names and member province codes.
  • Source document: official Thailand Post poster "รหัสไปรษณีย์ทั่วประเทศ จำแนกตามท้องที่" (status May 2018).

Installation

This project doesn't require any specific installation steps, as it consists of static JSON files. To use the data in your project, simply download the JSON files or clone the repository using the following command:

git clone https://github.com/thailand-geography-data/thailand-geography-json.git

Usage

You can directly import the JSON files into your project and use the data as needed. Below are some examples of how to import and use the JSON data in different programming languages:

JavaScript

import geography from "./src/geography.json";
import provinces from "./src/provinces.json";
import districts from "./src/districts.json";
import subdistricts from "./src/subdistricts.json";

// Utilize the geography data as needed, for example:
// - Display data in a table
// - Render data on a map
// - Perform data analysis and visualization

Python

import json

with open('./src/geography.json', 'r') as f:
    geography = json.load(f)

with open('./src/provinces.json', 'r') as f:
    provinces = json.load(f)

with open('./src/districts.json', 'r') as f:
    districts = json.load(f)

with open('./src/subdistricts.json', 'r') as f:
    subdistricts = json.load(f)

# Utilize the geography data as needed, for example:
# - Display data in a table
# - Render data on a map
# - Perform data analysis and visualization

JSON Keys

Get to know the keys used in the JSON files:

  • provinceCode - Province code (2-digit number).
  • provinceNameEn - Province name in English (string).
  • provinceNameTh - Province name in Thai (string).
  • districtCode - District code (4-digit number).
  • districtNameEn - District name in English (string).
  • districtNameTh - District name in Thai (string).
  • subdistrictCode - Subdistrict code (6-digit number).
  • subdistrictNameEn - Subdistrict name in English (string).
  • subdistrictNameTh - Subdistrict name in Thai (string).
  • postalCode - The primary postal code, i.e. the code that applies to most of the subdistrict (5-digit number).
  • postalCodes - List of every postal code of the subdistrict, so it can be rendered directly as a select dropdown. The primary code is always the first element. Every record has this key; subdistricts served by a single code have a one-element list. Based on the official Thailand Post poster "รหัสไปรษณีย์ทั่วประเทศ จำแนกตามท้องที่" (May 2018). Each entry:
    • postalCode - Postal code used in a specific part of the subdistrict (5-digit number).
    • isPrimary - true for the primary (majority-area) code, false otherwise (boolean).
    • detailTh - Thai description of the area using this code — the whole subdistrict, village (หมู่ที่) numbers, village names, or specific house/soi ranges (string).
    • detailEn - English description of the same area (string).
  • regionCode - Region code (number 1–6, unique per region).
  • regionNameEn - Region name in English (string).
  • regionNameTh - Region name in Thai (string).
  • provinceCodes - List of the provinceCode values of every province in the region (numbers); each of the 77 provinces belongs to exactly one region.

Sample Data

Check out sample data from each JSON file:

provinces.json

{
  "id": 1,
  "provinceCode": 10,
  "provinceNameEn": "Bangkok",
  "provinceNameTh": "กรุงเทพมหานคร"
}

districts.json

{
  "id": 1,
  "provinceCode": 10,
  "districtCode": 1001,
  "districtNameEn": "Phra Nakhon",
  "districtNameTh": "พระนคร",
  "postalCode": 10200
}

subdistricts.json

{
  "id": 1,
  "provinceCode": 10,
  "districtCode": 1001,
  "subdistrictCode": 100101,
  "subdistrictNameEn": "Phra Borom Maha Ratchawang",
  "subdistrictNameTh": "พระบรมมหาราชวัง",
  "postalCode": 10200,
  "postalCodes": [
    {
      "postalCode": 10200,
      "isPrimary": true,
      "detailTh": "ทั้งตำบล",
      "detailEn": "Whole subdistrict"
    }
  ]
}

A subdistrict served by more than one postal code lists all of them in postalCodes, e.g. Ao Nang in Krabi where Moo 7-8 use a different code than the rest of the subdistrict:

{
  "id": 6530,
  "provinceCode": 81,
  "districtCode": 8101,
  "subdistrictCode": 810116,
  "subdistrictNameEn": "Ao Nang",
  "subdistrictNameTh": "อ่าวนาง",
  "postalCode": 81180,
  "postalCodes": [
    {
      "postalCode": 81180,
      "isPrimary": true,
      "detailTh": "ม.1 - 6",
      "detailEn": "Moo 1 - 6 (majority area)"
    },
    {
      "postalCode": 81210,
      "isPrimary": false,
      "detailTh": "ม.7 - 8",
      "detailEn": "Moo 7 - 8"
    }
  ]
}

geography.json

{
  "id": 1,
  "provinceCode": 10,
  "provinceNameEn": "Bangkok",
  "provinceNameTh": "กรุงเทพมหานคร",
  "districtCode": 1001,
  "districtNameEn": "Phra Nakhon",
  "districtNameTh": "พระนคร",
  "subdistrictCode": 100101,
  "subdistrictNameEn": "Phra Borom Maha Ratchawang",
  "subdistrictNameTh": "พระบรมมหาราชวัง",
  "postalCode": 10200,
  "postalCodes": [
    {
      "postalCode": 10200,
      "isPrimary": true,
      "detailTh": "ทั้งตำบล",
      "detailEn": "Whole subdistrict"
    }
  ]
}

regions.json

{
  "regionCode": 1,
  "regionNameEn": "North",
  "regionNameTh": "เหนือ",
  "provinceCodes": [57, 55, 56, 50, 58, 54, 52, 51, 53]
}

provinceCodes holds the provinceCode values of the region's provinces (the North has 9); the file is ordered by regionCode from 1 (North) to 6 (South). The division follows the official six-region geographic classification of Thailand (Royal Institute, per the National Geographical Committee 1977).

Data validation

Run the repository validation before submitting data changes:

python3 -m unittest discover -s tests -v
python3 scripts/validate_data.py

The validator uses only the Python standard library. It parses package.json and every JSON file under src/, rejects invalid UTF-8 and duplicate object keys, verifies dataset roots and required fields, validates identifier widths and referential integrity, checks exact geography/subdistrict coverage, postal-code invariants, the multi-postal-code audit, and 6-region coverage of the provinces.

How to Contribute

To learn how to contribute to the project, please read the CONTRIBUTING.md file.

License

Copyright (c) 2023-Present Joe Takara. This project is licensed under the MIT License. See the LICENSE file for details.

Changelog

For information on the changes made in each version, please refer to the CHANGELOG.md file.

探索相关项目

加载中…