37 lines
2.5 KiB
JavaScript
37 lines
2.5 KiB
JavaScript
#!/usr/bin/env node
|
|
"use strict";
|
|
|
|
const assert = require("assert");
|
|
const fs = require("fs");
|
|
const os = require("os");
|
|
const path = require("path");
|
|
const { gcj02ToWgs84, convertGeoJson, inspectReference } = require("../packages/road-compiler/src/reference/gaode");
|
|
|
|
const converted = gcj02ToWgs84([114.12864875054062, 30.460485279762146]);
|
|
assert.ok(Math.abs(converted[0] - 114.1229659) < 0.00001);
|
|
assert.ok(Math.abs(converted[1] - 30.4628266) < 0.00001);
|
|
assert.throws(() => gcj02ToWgs84([Infinity, 30]), /finite/);
|
|
assert.deepEqual(convertGeoJson({ type: "FeatureCollection", features: [{ type: "Feature", properties: {}, geometry: { type: "Point", coordinates: [114.12864875054062, 30.460485279762146] } }] }).features[0].geometry.coordinates.map((value) => Number(value.toFixed(6))), [114.122966, 30.462827]);
|
|
|
|
const temp = fs.mkdtempSync(path.join(os.tmpdir(), "gaode-junction-reference-"));
|
|
try {
|
|
const reference = path.join(temp, "reference.geojson");
|
|
const osm = path.join(temp, "input.osm");
|
|
const native = path.join(temp, "intersections.geojson");
|
|
fs.writeFileSync(reference, JSON.stringify({ type: "FeatureCollection", features: [{ type: "Feature", properties: { type: 1 }, geometry: { type: "Polygon", coordinates: [[[114.12860, 30.46040], [114.12870, 30.46040], [114.12870, 30.46050], [114.12860, 30.46040]]] } }] }));
|
|
fs.writeFileSync(osm, "<osm><node id='8005332807' lon='114.1229249' lat='30.462899'><tag k='highway' v='traffic_signals'/></node></osm>");
|
|
fs.writeFileSync(native, JSON.stringify({ type: "FeatureCollection", features: [{ type: "Feature", properties: { osm_node_id: "8005332807" }, geometry: { type: "Polygon", coordinates: [[[114.1228, 30.4627], [114.1231, 30.4627], [114.1231, 30.4630], [114.1228, 30.4627]]] } }] }));
|
|
const result = inspectReference({ referenceFile: reference, osmFile: osm, nativeIntersectionFile: native, nodeId: "8005332807" });
|
|
assert.equal(result.matchedOsmNode.id, "8005332807");
|
|
assert.equal(result.matchedOsmNode.match, "node-id");
|
|
assert.ok(result.matchedOsmNode.centerDistanceMeters < 20);
|
|
assert.ok(result.nativeIntersection.bboxIoU > 0);
|
|
assert.deepEqual(result.diagnostics, []);
|
|
fs.writeFileSync(native, JSON.stringify({ type: "FeatureCollection", features: [] }));
|
|
assert.match(inspectReference({ referenceFile: reference, osmFile: osm, nativeIntersectionFile: native, nodeId: "8005332807" }).diagnostics[0], /No native intersection/);
|
|
} finally {
|
|
fs.rmSync(temp, { recursive: true, force: true });
|
|
}
|
|
|
|
console.log("Gaode junction reference tests passed.");
|