Preserve offline geometry, marking, replay and evaluation pipelines with source manifests and synthetic tests. Research qualification does not activate these methods as production navigation.
43 lines
2.8 KiB
Python
43 lines
2.8 KiB
Python
"""Structural acceptance for a four-class plan; does not certify survey accuracy."""
|
|
import numpy as np
|
|
import shapely
|
|
from shapely.geometry import shape
|
|
from shapely.ops import unary_union
|
|
|
|
CLASSES=frozenset(['carriageway','pedestrian_area','building_facade','road_marking'])
|
|
|
|
|
|
def inspect_plan(document):
|
|
features=document['features'];errors=[];counts={c:0 for c in sorted(CLASSES)};geometries=[]
|
|
for feature in features:
|
|
cls=feature['properties']['class']
|
|
if cls not in CLASSES:errors.append(dict(kind='class',id=feature.get('id')));continue
|
|
counts[cls]+=1;g=shape(feature['geometry']);geometries.append((feature,g))
|
|
if not g.is_valid or g.is_empty or not np.isfinite(shapely.get_coordinates(g,include_z=True)).all():errors.append(dict(kind='geometry',id=feature.get('id')))
|
|
if feature['properties'].get('route_permission')!='unassigned' or feature['properties'].get('authority')!='observation-only':errors.append(dict(kind='authority',id=feature.get('id')))
|
|
expected={'LineString'} if cls=='building_facade' else {'Polygon'}
|
|
if cls=='road_marking' and feature['properties'].get('geometry_role')=='partial-paint-footprint':expected.add('LineString')
|
|
if g.geom_type not in expected:errors.append(dict(kind='type',id=feature.get('id')))
|
|
areas=[shapely.force_2d(g) for f,g in geometries if f['properties']['class'] in ['carriageway','pedestrian_area']]
|
|
valid_coverage=bool(shapely.coverage_is_valid(areas))
|
|
if not valid_coverage:errors.append(dict(kind='area-overlap-or-unmatched-edge'))
|
|
road=unary_union([shapely.force_2d(g) for f,g in geometries if f['properties']['class']=='carriageway'])
|
|
frontages=[(f,shapely.force_2d(g)) for f,g in geometries if f['properties']['class']=='building_facade']
|
|
for i,(f,line) in enumerate(frontages):
|
|
conflict=line.intersection(road.buffer(-.3)).length
|
|
if conflict>.3:errors.append(dict(kind='facade-inside-road',id=f['id'],length_m=conflict))
|
|
for other,b in frontages[i+1:]:
|
|
cross=line.intersection(b)
|
|
if cross.geom_type=='Point' and .4<line.project(cross)<line.length-.4 and .4<b.project(cross)<b.length-.4:
|
|
errors.append(dict(kind='crossing-facades',ids=[f['id'],other['id']]))
|
|
return dict(passed=not errors,errors=errors,counts=counts,shared_area_coverage=valid_coverage,
|
|
physical_accuracy_certified=False,route_permission='unassigned',
|
|
facade_length_m=sum(g.length for _,g in frontages),
|
|
areas_m2={c:sum(g.area for f,g in geometries if f['properties']['class']==c) for c in ['carriageway','pedestrian_area']})
|
|
|
|
|
|
def require_plan(document):
|
|
result=inspect_plan(document)
|
|
if not result['passed']:raise ValueError('Plan structural acceptance failed: '+str(result['errors'][:8]))
|
|
return result
|