TaiGeotrans
TaiGeotrans 是一個台灣地址與座標轉換工具,支援:
- WGS84(EPSG:4326)與 TWD97(EPSG:3826)雙向轉換
- 透過 TGOS 將台灣地址轉成座標
- 批量處理、pandas DataFrame 與 GeoJSON
- 命令列操作
安裝
只使用座標轉換時:
python -m pip install taigeotrans
需要地址定位、DataFrame 或 CLI 時,再安裝對應功能:
python -m pip install "taigeotrans[geocoding]"
python -m pip install "taigeotrans[dataframe]"
python -m pip install "taigeotrans[cli]"
也可以一次安裝全部功能:
python -m pip install "taigeotrans[all]"
Python API
from taigeotrans import TaiGeotrans
tg = TaiGeotrans()
# WGS84 -> TWD97
result = tg.transform_lonlat(121.5654, 25.0330)
print(result.twd97_x, result.twd97_y)
# TWD97 -> WGS84
result = tg.transform_twd97(303891.54, 2773226.67)
print(result.wgs84_lon, result.wgs84_lat)
地址定位
地址定位使用 TGOS,需要 AppID 與 APIKey。請先在 TGOS 申請這兩項資料, 再透過環境變數提供:
export TGOS_APP_ID="your-app-id"
export TGOS_API_KEY="your-api-key"
或直接傳給 TaiGeotrans:
tg = TaiGeotrans(
tgos_app_id="your-app-id",
tgos_api_key="your-api-key",
)
result = tg.geocode("臺北市中山區松江路469巷4號")
print(result.matched_address, result.twd97_x, result.twd97_y)
Python API 不會自動讀取 .env。CLI 會讀取目前工作目錄的 .env,可以複製
.env.example 作為範本;實際 key 不要提交到 Git。
批量處理
addresses = ["嘉義縣民雄鄉中樂路55號", "臺北市信義區市府路1號"]
coords = [(120.4278, 23.5521), (121.5654, 25.0330)]
address_results = tg.batch_geocode(addresses, show_progress=False)
coordinate_results = tg.batch_transform_lonlat(coords, show_progress=False)
df = tg.batch_transform_lonlat_to_dataframe(coords, show_progress=False)
DataFrame 方法需要 taigeotrans[dataframe]。進度列使用 tqdm;沒有安裝時,
批量方法仍可執行,只是不顯示進度列。
CLI
python -m pip install "taigeotrans[cli]"
taigeotrans transform 121.5654 25.0330
taigeotrans transform 121.5654 25.0330 --format json
taigeotrans geocode "臺北市信義區市府路1號"
taigeotrans batch-geocode addresses.txt -o results.csv
taigeotrans batch-transform coords.csv -o results.csv
addresses.txt 每行一個地址;coords.csv 需要包含 lon,lat 欄位。執行
taigeotrans --help 查看完整指令。
結果
每個操作都回傳 GeocodeResult,包含輸入值、WGS84/TWD97 座標、來源與狀態。
狀態可能是 success、out_of_bounds、invalid 或 failed。
開發
python -m pip install -e ".[dev,all]"
python -m pytest
python -m ruff check src tests
python -m ruff format --check src tests
python -m mypy src
python -m build
python -m twine check dist/*
CI 會測試 Python 3.11–3.13。推送 vMAJOR.MINOR.PATCH tag 後,release workflow
會建置套件、發佈到 PyPI,並建立 GitHub Release。
授權
MIT License,請參考 LICENSE。
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file taigeotrans-0.1.0.tar.gz.
File metadata
- Download URL: taigeotrans-0.1.0.tar.gz
- Upload date:
- Size: 18.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d614863e5baf17f0b0a17cd2576c55dd9c86ccd3b789a044677b9692096a96c2
|
|
| MD5 |
50d4011ee62e09c4384ad1489fe701d0
|
|
| BLAKE2b-256 |
52d4508cb1ee8f4516085a515fb8d91bbeb9490621cfff23b30e6fbe09b34227
|
Provenance
The following attestation bundles were made for taigeotrans-0.1.0.tar.gz:
Publisher:
release.yml on KageRyo/TaiGeotrans
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
taigeotrans-0.1.0.tar.gz -
Subject digest:
d614863e5baf17f0b0a17cd2576c55dd9c86ccd3b789a044677b9692096a96c2 - Sigstore transparency entry: 2367821801
- Sigstore integration time:
-
Permalink:
KageRyo/TaiGeotrans@3a6a03dacd629285931192dd6f8cc26c4f5ecf9b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/KageRyo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3a6a03dacd629285931192dd6f8cc26c4f5ecf9b -
Trigger Event:
push
-
Statement type:
File details
Details for the file taigeotrans-0.1.0-py3-none-any.whl.
File metadata
- Download URL: taigeotrans-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b52bc2a9c20050e749cf7b14cbdd5c8ad6e42d28d657f238c76242773a0881b
|
|
| MD5 |
249a8817f82cc4df75854302ac94e248
|
|
| BLAKE2b-256 |
f32cf749eb479d2d1aa08870a86892621f08953fc7092a92e15250ea3cf51699
|
Provenance
The following attestation bundles were made for taigeotrans-0.1.0-py3-none-any.whl:
Publisher:
release.yml on KageRyo/TaiGeotrans
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
taigeotrans-0.1.0-py3-none-any.whl -
Subject digest:
1b52bc2a9c20050e749cf7b14cbdd5c8ad6e42d28d657f238c76242773a0881b - Sigstore transparency entry: 2367821877
- Sigstore integration time:
-
Permalink:
KageRyo/TaiGeotrans@3a6a03dacd629285931192dd6f8cc26c4f5ecf9b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/KageRyo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3a6a03dacd629285931192dd6f8cc26c4f5ecf9b -
Trigger Event:
push
-
Statement type: