Files
Aislo/resources/tester/test_611_1_sheet_frame.py
T

84 lines
2.7 KiB
Python

"""611-1 — 도곽선 N3L_H0010000 읽기(도로 없는 도엽 zip · 옛 zip 대신) · 공용 창고 prune 안 지움."""
import sys
import tempfile
import zipfile
from pathlib import Path
import geopandas as gpd
import pytest
from shapely.geometry import box
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
from B04_PreProcess.B04_PreProcess_Engine_MapSheet import sheet5k_to_bounds # noqa: E402
from B04_PreProcess.B04_PreProcess_Engine_SheetStore import ( # noqa: E402
_read_frame_bounds_wgs84,
ingest_zip,
prune_sheets,
)
SHEET = "36712079"
CRS = "EPSG:5186"
def _make_zip(path: Path, layers: dict[str, tuple[float, float, float, float]]) -> None:
"""layers: {레이어 코드: WGS84 box} — SHP 로 써서 zip 에 넣음."""
with tempfile.TemporaryDirectory() as td, zipfile.ZipFile(path, "w") as zf:
for code, bb in layers.items():
gdf = gpd.GeoDataFrame(geometry=[box(*bb)], crs="EPSG:4326").to_crs(CRS)
shp = Path(td) / f"{SHEET}_{code}.shp"
gdf.to_file(shp)
for f in Path(td).glob(f"{SHEET}_{code}.*"):
zf.write(f, f.name)
def _frame():
return sheet5k_to_bounds(SHEET)
def _road_part():
w, s, e, n = _frame()
return (w + (e - w) * 0.2, s + (n - s) * 0.2, w + (e - w) * 0.5, s + (n - s) * 0.5)
def test_도곽_겹이_있으면_도곽선_범위(tmp_path):
z = tmp_path / f"{SHEET}.zip"
_make_zip(z, {"N3L_H0010000": _frame(), "N3L_A0010000": _road_part()})
b, _ = _read_frame_bounds_wgs84(z)
for got, want in zip(b, _frame()):
assert got == pytest.approx(want, abs=1e-6)
def test_도로_없는_도엽도_받기_통과(tmp_path):
z = tmp_path / f"{SHEET}.zip"
_make_zip(z, {"N3L_H0010000": _frame()})
entry = ingest_zip(tmp_path / "store", z, sheet_no=SHEET)
assert entry["bounds_wgs84"][0] == pytest.approx(_frame()[0], abs=1e-6)
def test_도곽_겹_없으면_옛_방식(tmp_path):
z = tmp_path / f"{SHEET}.zip"
_make_zip(z, {"N3L_A0010000": _road_part()})
b, _ = _read_frame_bounds_wgs84(z)
for got, want in zip(b, _road_part()):
assert got == pytest.approx(want, abs=1e-6)
def test_공용_창고는_prune_안_지움(tmp_path):
shared = tmp_path / "_shared" / "sheets" / SHEET
shared.mkdir(parents=True)
z = shared / "36712078.zip"
_make_zip(z, {"N3L_H0010000": sheet5k_to_bounds("36712078")})
assert prune_sheets(shared, [SHEET]) == []
assert z.exists()
def test_프로젝트_창고는_prune_지움(tmp_path):
store = tmp_path / "proj" / "map_sheets"
store.mkdir(parents=True)
z = store / "36712078.zip"
_make_zip(z, {"N3L_H0010000": sheet5k_to_bounds("36712078")})
assert prune_sheets(store, [SHEET]) == ["36712078"]
assert not z.exists()