Improve data

This commit is contained in:
Andras Schmelczer 2026-06-10 07:54:25 +01:00
parent b4d66a28c1
commit 85da1941aa
31 changed files with 901 additions and 319 deletions

View file

@ -906,6 +906,37 @@ class TestToWgs84Geojson:
assert result is not None
assert result["type"] == "Polygon"
def test_pointlike_input_gets_building_scale_footprint(self):
"""A tower-block postcode (all UPRNs at one point) must not collapse to a
sub-metre dot; it gets a building-scale footprint instead."""
import pyproj
from shapely.geometry import Point, shape
from shapely.ops import transform as transform_geometry
to_bng = pyproj.Transformer.from_crs(
"EPSG:4326", "EPSG:27700", always_xy=True
)
result = to_wgs84_geojson(Point(360000, 170000))
assert result is not None
area_m2 = transform_geometry(to_bng.transform, shape(result)).area
assert area_m2 > 100, f"point footprint only {area_m2:.1f} m^2"
def test_thin_sliver_keeps_minimal_buffer(self):
"""A genuine elongated sliver still carries length, so it is NOT inflated
to building scale only truly pointlike inputs are."""
import pyproj
from shapely.geometry import LineString, shape
from shapely.ops import transform as transform_geometry
to_bng = pyproj.Transformer.from_crs(
"EPSG:4326", "EPSG:27700", always_xy=True
)
sliver = LineString([(360000, 170000), (360040, 170000)]).buffer(0.05)
result = to_wgs84_geojson(sliver)
assert result is not None
area_m2 = transform_geometry(to_bng.transform, shape(result)).area
assert area_m2 < 100, f"sliver inflated to {area_m2:.1f} m^2"
def test_coordinates_have_limited_precision(self):
"""GeoJSON coordinates should be rounded to 6 decimal places."""
import json