Files
Aislo/db_management/024_plan_site_fill.py
T
eomsangdonandClaude Opus 5.5 3d7f6d0b70 feat(D01): 예정노선 등록 — 설계속도 지움 · 카카오 지도 기준점 하나 + 주소(VWorld · 출처 표기) · 사업 지역 채움 (PLAN 591-1 · 요구 452 · 453)
- 등록 화면 = 공용 카카오 지도(마우스 설정 따름 · 일반/위성) 누름 · 끌기로 기준점 하나 · 주소 글 + 출처
- 사업 지역 = 주소의 「시군구 읍면」 채움 · 손으로 고친 값은 안 덮음
- 서버 = 기준점 필수(경위도 범위) · 주소는 서버가 VWorld 로 다시 찾아 저장 · 설계속도 칸 안 씀(B05 기본 20)
- 새 길 GET /api/map/address — 지번 먼저(산 번지) · region · 출처 VWorld · B08 한 줄 주소 그대로
- DB 024 = projects 기준점 칸 셋 추가 · PLAN 설계속도 비움 · 옛 PLAN 기준점 = 지점 가운데(024_plan_site_fill.py · 적용 완료)
- 시험 528 = 설계속도 단언을 기준점 단언으로 · 새 지킴 시험 591_1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 09:41:31 +09:00

75 lines
2.6 KiB
Python

"""옛 예정노선 기준점 채움 — 지점 상자 가운데 · 주소 VWorld (PLAN 591-1 · SQL 024 뒤 한 번).
기준점 칸이 빈 PLAN 만 · 지점 = `plan_base_json`(새 꼴 points · 옛 start/end · starts/ends) ·
지점이 없으면 건너뜀(알림 한 줄) · 다시 돌려도 같음(채운 행은 안 건드림).
쓰는 법
./venv/Scripts/python.exe db_management/024_plan_site_fill.py
"""
from __future__ import annotations
import asyncio
import json
import sys
from pathlib import Path
from typing import Any
sys.path.append(str(Path(__file__).resolve().parent.parent))
from dotenv import load_dotenv # noqa: E402
load_dotenv()
import aiomysql # noqa: E402
from B01_Dashboard.B01_Dashboard_Map import reverse_place # noqa: E402
from common_util.common_util_crs import tm_to_lonlat # noqa: E402
from config.config_db import close_db_pool, init_db_pool # noqa: E402
def base_center(base: dict[str, Any] | None) -> tuple[float, float] | None:
"""지점 상자 가운데(TM m) — 꼴 셋을 모두 읽음 · 지점 없음 = None."""
base = base or {}
points = [
*base.get("points", []),
*base.get("starts", []),
*base.get("ends", []),
*(base[k] for k in ("start", "end") if base.get(k)),
]
xs = [float(p["x"]) for p in points if p]
ys = [float(p["y"]) for p in points if p]
if not xs:
return None
return (min(xs) + max(xs)) / 2, (min(ys) + max(ys)) / 2
async def main() -> None:
pool = await init_db_pool()
async with pool.acquire() as connection, connection.cursor(aiomysql.DictCursor) as cursor:
await cursor.execute(
"SELECT id, name, plan_base_json FROM projects"
" WHERE project_kind = 'PLAN' AND site_lon IS NULL"
)
for row in await cursor.fetchall():
raw = row["plan_base_json"]
base = json.loads(raw) if isinstance(raw, str) else raw
center = base_center(base)
if not center or not (base or {}).get("epsg"):
print(f"건너뜀(지점 없음) {row['id']} {row['name']}")
continue
lon, lat = tm_to_lonlat(*center, int(base["epsg"]))
address = (await reverse_place(lon, lat))["address"]
await cursor.execute(
"UPDATE projects SET site_lon = %s, site_lat = %s, site_address = %s"
" WHERE id = %s AND site_lon IS NULL",
(lon, lat, address, row["id"]),
)
print(f"채움 {row['name']} {lon:.6f} {lat:.6f} {address}")
await connection.commit()
await close_db_pool()
if __name__ == "__main__":
asyncio.run(main())