added covarage

This commit is contained in:
2026-06-24 08:07:50 +03:00
parent bc9b70764d
commit 23a6b83a02
3 changed files with 61 additions and 4 deletions
+13 -2
View File
@@ -16,8 +16,9 @@ from rasterio.warp import (
reproject,
transform,
)
from pyproj import Transformer
from shapely.geometry import mapping, shape
from shapely.ops import unary_union
from shapely.ops import transform as shapely_transform, unary_union
from app.core.dem import _dem_files, _sample_dataset
from app.core.geo import GeoPoint
@@ -122,6 +123,16 @@ def _run_gdal_viewshed(
subprocess.run(command, check=True, capture_output=True, text=True)
def _to_wgs84(geom, src_crs: CRS | None):
if src_crs is None:
return geom
crs_text = src_crs.to_string()
if crs_text in {"EPSG:4326", "OGC:CRS84", "WGS84"}:
return geom
transformer = Transformer.from_crs(src_crs, "EPSG:4326", always_xy=True)
return shapely_transform(transformer.transform, geom)
def _viewshed_geojson(viewshed_path: Path, observer: GeoPoint) -> dict[str, Any]:
features: list[dict[str, Any]] = []
with rasterio.open(viewshed_path) as dataset:
@@ -130,7 +141,7 @@ def _viewshed_geojson(viewshed_path: Path, observer: GeoPoint) -> dict[str, Any]
for geom, value in shapes(mask, mask=mask.astype(bool), transform=dataset.transform):
if int(value) != 1:
continue
polygon = shape(geom)
polygon = _to_wgs84(shape(geom), dataset.crs)
if polygon.is_empty:
continue
features.append(