# -*- coding: utf-8 -*- """PRJ 좌표계 판별(common_util_crs) — 실제 원청 PRJ로 확인한다. `0d90595a`가 노린 두 실패 사례를 그대로 태운다. ① COMPD_CS(수직 지오이드 결합) — `CRS.to_epsg()`가 None을 준다. ② EPSG AUTHORITY가 없는 ESRI WKT — 파라미터 지문으로만 가릴 수 있다. """ import io import sys from pathlib import Path import pytest from pyproj import CRS ROOT = Path(__file__).resolve().parents[2] sys.path.insert(0, str(ROOT)) from common_util.common_util_crs import crs_input_from_prj, identify_epsg # noqa: E402 COMPOUND_PRJ = next(ROOT.glob("storage/*/*/*/B03_FileInput/input/prj/result.prj"), None) ESRI_PRJ = next( ROOT.glob("resources/knowledge/original/실무문서/**/*중심선(EPSG5176).prj"), None ) def _read(path: Path) -> str: return io.open(path, encoding="utf-8", errors="replace").read().strip() @pytest.mark.skipif(COMPOUND_PRJ is None, reason="프로젝트 저장소에 PRJ 표본이 없다") def test_수직결합_PRJ는_수평성분_EPSG로_판별된다(): """KGD2002 / East Belt 2010 + KNGeoid24 — to_epsg()는 None이지만 5187로 가려야 한다.""" text = _read(COMPOUND_PRJ) crs = CRS.from_user_input(text) assert crs.to_epsg() is None # 판별 사다리가 필요한 이유 assert identify_epsg(crs, text) == 5187 assert crs_input_from_prj(text) == "EPSG:5187" @pytest.mark.skipif(ESRI_PRJ is None, reason="실무문서 PRJ 표본이 없다") def test_AUTHORITY_없는_ESRI_WKT도_판별된다(): """Korean_1985_Modified_Korea_East_Belt — 파일명이 EPSG5176임을 근거로 삼는다.""" text = _read(ESRI_PRJ) crs = CRS.from_user_input(text) assert identify_epsg(crs, text) == 5176 assert crs_input_from_prj(text) == "EPSG:5176" def test_불량_입력은_None을_돌려준다(): """차단은 WKT 자체가 불량일 때만 — 라벨 실패는 차단 사유가 아니다.""" assert crs_input_from_prj("이건 WKT가 아니다") is None assert crs_input_from_prj(" ") is None assert crs_input_from_prj("") is None def test_TOWGS84_보정이_박힌_WKT는_원문을_돌려준다(): """EPSG로 갈아타면 파일의 지역 보정이 사라지므로 WKT 원문을 그대로 써야 한다.""" wkt = ( 'PROJCS["Korea 2000 / East Belt 2010",' 'GEOGCS["Korea 2000",DATUM["Korea_2000",' 'SPHEROID["GRS 1980",6378137,298.257222101],' "TOWGS84[-115.8,474.99,674.11,1.16,-2.31,-1.63,6.43]]," 'PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],' 'PROJECTION["Transverse_Mercator"],' 'PARAMETER["latitude_of_origin",38],PARAMETER["central_meridian",129],' 'PARAMETER["scale_factor",1],PARAMETER["false_easting",200000],' 'PARAMETER["false_northing",600000],UNIT["metre",1]]' ) got = crs_input_from_prj(wkt) assert got is not None assert not got.startswith("EPSG:") # 라벨로 갈아타지 않는다 assert "TOWGS84" in got # 보정 모수가 살아 있다