from pyproj import CRS, Transformer
from shapely.geometry import shape, mapping
from shapely.ops import transform as shapely_transform


def make_transformer(src_crs, dst_crs) -> Transformer:
    """Create a coordinate transformer between two CRS.

    Uses always_xy=True to prevent silent lon/lat axis swaps.
    """
    return Transformer.from_crs(src_crs, dst_crs, always_xy=True)


def reproject_feature(feature: dict, transformer: Transformer) -> dict:
    """Reproject a single GeoJSON-like feature dict."""
    geom = shape(feature["geometry"])
    reprojected = shapely_transform(transformer.transform, geom)
    feature = dict(feature)
    feature["geometry"] = mapping(reprojected)
    return feature
