feat(junction): mark complex crossing evidence
This commit is contained in:
1 parent
c14b8b09f2
commit
d49cdab40a
4 files changed
+112
-2
No files matched your search
@@ -113,6 +113,8 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
const crossingRadius = armCrosswalkRadiusFor(arm);
|
||||
const stopOffset = crossingControls.get(crossingKey)?.stopLineOffsetMeters || 3;
|
||||
const stopCenter = pointOnCarriagewayRadius(item, center, crossingRadius + stopOffset, helpers);
|
||||
const crossingCenter = pointOnCarriagewayRadius(item, center, crossingRadius, helpers);
|
||||
const crossingEvidence = crossingEvidenceForArm(model, arm, crossingCenter, helpers);
|
||||
const ring = [
|
||||
helpers.offsetCoordinate(
|
||||
helpers.offsetCoordinate(stopCenter, item.heading + 90, -outerHalf),
|
||||
@@ -153,6 +155,10 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
road_id: incomingRoad.id,
|
||||
node_id: item.nodeId,
|
||||
direction: item.heading,
|
||||
facility_evidence: crossingEvidence.kind,
|
||||
...(crossingEvidence.crossingNodeIds.length
|
||||
? { source_crossing_node_ids: crossingEvidence.crossingNodeIds }
|
||||
: {}),
|
||||
provenance: 'native-road-complex-junction-stop-line/v1',
|
||||
},
|
||||
geometry: { type: 'Polygon', coordinates: [ring] },
|
||||
@@ -173,6 +179,7 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
supportHeading: normalizeHeading(arm.heading + 90),
|
||||
envelopeWidthMeters: envelope.widthMeters,
|
||||
};
|
||||
arm.crosswalkEvidence = crossingEvidenceForArm(model, arm, envelope.center, helpers);
|
||||
}
|
||||
for (let index = 0; index < arms.length; index += 1) {
|
||||
const arm = arms[index];
|
||||
@@ -243,6 +250,10 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
stripe_spacing_m: stripeSpacing,
|
||||
frame_center: arm.crosswalkFrame.center,
|
||||
frame_support_heading: arm.crosswalkFrame.supportHeading,
|
||||
facility_evidence: arm.crosswalkEvidence.kind,
|
||||
...(arm.crosswalkEvidence.crossingNodeIds.length
|
||||
? { source_crossing_node_ids: arm.crosswalkEvidence.crossingNodeIds }
|
||||
: {}),
|
||||
provenance: 'native-road-complex-junction-crosswalk/v6-road-clipped',
|
||||
},
|
||||
geometry: { type: 'Polygon', coordinates: [ring] },
|
||||
@@ -259,6 +270,19 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
const cornerFills = [];
|
||||
const sidewalkCorners = [];
|
||||
const cornerDiagnostics = [];
|
||||
for (const arm of arms) {
|
||||
if (!arm.crosswalkFrame || arm.crosswalkEvidence.kind !== 'inferred-road-envelope') continue;
|
||||
cornerDiagnostics.push(
|
||||
helpers.diagnostic(
|
||||
'info',
|
||||
`crossing:${arm.key}`,
|
||||
arm.members.flatMap((member) => member.approach.roadIds.map(String)),
|
||||
'complex-junction-crossing-inferred',
|
||||
'该进口未找到与道路及当前位置匹配的 OSM 过街节点;已按最终车行道范围推断斑马线和停止线。',
|
||||
arm.crosswalkFrame.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
const omittedCornerFacilityCount = arms.filter((arm, index) => {
|
||||
const next = arms[(index + 1) % arms.length];
|
||||
const delta = positiveHeadingDelta(arm.heading, next.heading);
|
||||
@@ -698,6 +722,27 @@ function armEnvelopeAtRadius(arm, radius, center, helpers) {
|
||||
widthMeters: maximum - minimum,
|
||||
};
|
||||
}
|
||||
function crossingEvidenceForArm(model, arm, center, helpers) {
|
||||
const osmWayIds = new Set(
|
||||
arm.members.flatMap((member) => member.roads.flatMap((road) => (road.osmWayIds || []).map(String))),
|
||||
);
|
||||
const maximumDistance = Math.max(
|
||||
8,
|
||||
arm.members.reduce((width, member) => width + member.approach.widthMeters, 0) / 2 + 3,
|
||||
);
|
||||
const crossingNodeIds = (model.crossings || [])
|
||||
.filter(
|
||||
(crossing) =>
|
||||
(crossing.osmWayIds || []).some((wayId) => osmWayIds.has(String(wayId))) &&
|
||||
helpers.distanceMeters(crossing.coordinate, center) <= maximumDistance,
|
||||
)
|
||||
.map((crossing) => String(crossing.id))
|
||||
.sort();
|
||||
return {
|
||||
kind: crossingNodeIds.length ? 'source-crossing-node' : 'inferred-road-envelope',
|
||||
crossingNodeIds,
|
||||
};
|
||||
}
|
||||
function cornerEdgeAt(arm, radius, bisector, center, helpers) {
|
||||
const candidates = arm.members.flatMap((member) => {
|
||||
const point = pointOnCarriagewayRadius(member, center, radius, helpers);
|
||||
|
||||
@@ -40,11 +40,22 @@ function metadata(input) {
|
||||
if (input.provenance !== undefined) {
|
||||
if (!input.provenance || typeof input.provenance !== 'object' || Array.isArray(input.provenance))
|
||||
throw new Error('Junction provenance must be an object');
|
||||
for (const field of ['nodeIds', 'segmentIds', 'roadIds', 'osmWayIds', 'carriagewayKeys', 'armKeys', 'featureIds']) {
|
||||
for (const field of [
|
||||
'nodeIds',
|
||||
'segmentIds',
|
||||
'roadIds',
|
||||
'osmWayIds',
|
||||
'carriagewayKeys',
|
||||
'armKeys',
|
||||
'featureIds',
|
||||
'crossingNodeIds',
|
||||
]) {
|
||||
const values = input.provenance[field];
|
||||
if (values !== undefined && (!Array.isArray(values) || values.some((value) => typeof value !== 'string')))
|
||||
throw new Error(`Junction provenance.${field} must be an array of strings`);
|
||||
}
|
||||
if (input.provenance.facilityEvidence !== undefined && typeof input.provenance.facilityEvidence !== 'string')
|
||||
throw new Error('Junction provenance.facilityEvidence must be a string');
|
||||
result.provenance = JSON.parse(JSON.stringify(input.provenance));
|
||||
}
|
||||
if (input.capability !== undefined) {
|
||||
|
||||
@@ -93,7 +93,12 @@ function structureFromTopology(topology, shape, center, features) {
|
||||
: {}),
|
||||
editable: false,
|
||||
capability: capability(),
|
||||
provenance: { featureIds: [], ...(p.road_id ? { roadIds: [String(p.road_id)] } : {}) },
|
||||
provenance: {
|
||||
featureIds: [],
|
||||
...(p.road_id ? { roadIds: [String(p.road_id)] } : {}),
|
||||
...(p.facility_evidence ? { facilityEvidence: String(p.facility_evidence) } : {}),
|
||||
...(p.source_crossing_node_ids ? { crossingNodeIds: p.source_crossing_node_ids.map(String).sort() } : {}),
|
||||
},
|
||||
});
|
||||
facilitiesByKey.get(p.object_key).provenance.featureIds.push(String(p.native_id));
|
||||
}
|
||||
|
||||
@@ -135,4 +135,53 @@ assert.equal(
|
||||
false,
|
||||
);
|
||||
assert.ok(complexGeometry.diagnostics.some((item) => item.rule === 'complex-junction-corner-facilities-omitted'));
|
||||
const inferredComplexCrosswalk = complexGeometry.crosswalks.features.find(
|
||||
(feature) => feature.properties?.kind === 'complex-crosswalk',
|
||||
);
|
||||
assert.equal(inferredComplexCrosswalk.properties.facility_evidence, 'inferred-road-envelope');
|
||||
assert.ok(complexGeometry.diagnostics.some((item) => item.rule === 'complex-junction-crossing-inferred'));
|
||||
const sourceCrossingModel = structuredClone(complexModel);
|
||||
const sourceRoad = sourceCrossingModel.roads.find((road) => road.id === inferredComplexCrosswalk.properties.road_id);
|
||||
sourceCrossingModel.crossings = [
|
||||
{
|
||||
id: 'known-complex-crossing',
|
||||
coordinate: inferredComplexCrosswalk.properties.frame_center,
|
||||
osmWayIds: sourceRoad.osmWayIds,
|
||||
},
|
||||
];
|
||||
const sourceCrossingGeometry = compiler.nativeRoad.compileGeometry(
|
||||
sourceCrossingModel,
|
||||
{ schema: 'native-road-overrides/v1', overrides: [] },
|
||||
{
|
||||
edgeLines: false,
|
||||
junctionTemplates: {
|
||||
enabled: true,
|
||||
clusters: [
|
||||
{
|
||||
id: 'fixture-five-arm',
|
||||
template: 'complex-junction-v1',
|
||||
nodeIds: ['8005332807', '8024512135', '8024512145', '8024512147', '8613058676'],
|
||||
coreRadiusMeters: 24,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
);
|
||||
const sourcedComplexCrosswalk = sourceCrossingGeometry.crosswalks.features.find(
|
||||
(feature) => feature.properties?.crossing_key === inferredComplexCrosswalk.properties.crossing_key,
|
||||
);
|
||||
assert.equal(sourcedComplexCrosswalk.properties.facility_evidence, 'source-crossing-node');
|
||||
assert.deepEqual(sourcedComplexCrosswalk.properties.source_crossing_node_ids, ['known-complex-crossing']);
|
||||
const sourcedStopLine = sourceCrossingGeometry.vehicleStopLines.features.find(
|
||||
(feature) => feature.properties?.crossing_key === inferredComplexCrosswalk.properties.crossing_key,
|
||||
);
|
||||
if (sourcedStopLine) assert.equal(sourcedStopLine.properties.facility_evidence, 'source-crossing-node');
|
||||
const sourceStructure = sourceCrossingGeometry.roadSurface.features.find(
|
||||
(feature) => feature.properties?.junction_structure,
|
||||
)?.properties.junction_structure;
|
||||
assert.equal(
|
||||
sourceStructure.facilities.find((facility) => facility.key === inferredComplexCrosswalk.properties.object_key)
|
||||
.provenance.facilityEvidence,
|
||||
'source-crossing-node',
|
||||
);
|
||||
console.log('road compiler package tests passed');
|
||||
Reference in new issue
Block a user