perf(520-6): B04 배수유역 확장 한 번 셈 · 노선 무관 흐름 방향장 저장본 · 등고선 점 구름 메모리 보관

- 흐름 방향장 열쇠 · 짓기에서 노선 최저점 하한 뺌 — 프로젝트마다 지형 저장본 한 종류 · 초안 [업데이트] 때 다시 짓지 않음
- expand_by_red_boundary 안 — 저장 큰 방향장 전체에서 도로 도달 한 번 판정 → 「도로로 오는 셀 + 확장 폭 띠 ∪ 1차 영역」으로 자름 · 큰 격자 가장자리에 닿으면 옛 회차 확장
- 끊기 확인 = 한 번 셈 앞 · [계측] 줄(한 번 셈 · 점 구름)
- build_contour_cloud — 하한 없는 구름을 피처 목록 · 자르는 범위 열쇠로 2 벌 보관 · 하한은 점 표고로 거름(옛 결과와 점 · 차례 같음)
- test_347_1 열쇠 시험 — 하한 인자 없어짐에 맞춰 고침
- 지킴 시험 test_520_6 — 합성 비탈에서 한 번 셈 = 회차 확장(도로로 오는 셀 · 도로 셀 귀속) · 하한 달라도 방향장 한 번만 지음
- 실데이터 대조(검증_sub2 · 검증_랩탑메인 · 검증_sub3) — 도로로 오는 셀 · 귀속 · 관별 면적 12 개 차이 0 · 초안 8.0~9.3 s → 0.8~2.5 s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-25 08:18:05 +09:00
co-authored by Claude Opus 5.5
parent 80615cce2f
commit fb4beb99c9
6 changed files with 216 additions and 31 deletions
@@ -143,6 +143,10 @@ def iter_linestrings(geometry: Any) -> list[LineString]:
return []
# 점 구름 메모리 보관(520-6) — 열쇠 = 피처 목록(객체째 들고 있음) · 개수 · 자르는 범위 · 2 벌.
_CLOUD_CACHE: list[tuple[Any, int, Any, ContourCloud]] = []
def build_contour_cloud(
contour_features: list[dict[str, Any]],
elevation_floor_m: float | None = None,
@@ -156,11 +160,30 @@ def build_contour_cloud(
`clip_bounds`(x_min, y_min, x_max, y_max)를 주면 그 밖 등고선은 읽지 않는다. 도엽
전체 등고선을 다 물고 가면 TIN 삼각망 비용만 커지고 결과는 같다.
하한 없는 구름을 보관해 두고 하한은 점 표고로 거른다 — 피처를 거른 것과 점 · 차례가 같다.
"""
for holder, count, bounds, cached in _CLOUD_CACHE:
if holder is contour_features and count == len(contour_features) and bounds == clip_bounds:
cloud = cached
break
else:
cloud = _contour_cloud(contour_features, clip_bounds)
_CLOUD_CACHE.append((contour_features, len(contour_features), clip_bounds, cloud))
del _CLOUD_CACHE[:-2]
if elevation_floor_m is None:
return cloud
keep = cloud.z >= elevation_floor_m
return ContourCloud(cloud.xy[keep], cloud.z[keep])
def _contour_cloud(
contour_features: list[dict[str, Any]],
clip_bounds: tuple[float, float, float, float] | None,
) -> ContourCloud:
xs: list[np.ndarray] = []
ys: list[np.ndarray] = []
zs: list[np.ndarray] = []
dropped_low = 0
dropped_short = 0
dropped_outside = 0
for feature in contour_features:
@@ -170,9 +193,6 @@ def build_contour_cloud(
elevation = _feature_elevation(feature.get("properties") or {})
if elevation is None:
continue
if elevation_floor_m is not None and elevation < elevation_floor_m:
dropped_low += 1
continue
try:
parsed = shape(geometry)
except Exception: # noqa: BLE001 - 손상된 피처는 건너뛴다
@@ -192,8 +212,7 @@ def build_contour_cloud(
zs.append(np.full(coords.shape[0], elevation, dtype=np.float64))
if not xs:
logger.warning(
"배수유역: 사용할 등고선이 없습니다(저지대 %d, 파편 %d, 범위밖 %d 제외).",
dropped_low,
"배수유역: 사용할 등고선이 없습니다(파편 %d, 범위밖 %d 제외).",
dropped_short,
dropped_outside,
)
@@ -201,9 +220,8 @@ def build_contour_cloud(
xy = np.column_stack((np.concatenate(xs), np.concatenate(ys)))
z = np.concatenate(zs)
logger.info(
"배수유역: 등고선 정점 %d개 (저지대 %d, 파편 %d, 범위밖 %d 제외)",
"배수유역: 등고선 정점 %d개 (파편 %d, 범위밖 %d 제외)",
xy.shape[0],
dropped_low,
dropped_short,
dropped_outside,
)