mapcomplete/test/SplitAction.spec.ts

280 lines
43 KiB
TypeScript
Raw Normal View History

import T from "./TestHelper";
import {Changes} from "../Logic/Osm/Changes";
import SplitAction from "../Logic/Osm/Actions/SplitAction";
import {equal} from "assert";
import {Utils} from "../Utils";
export default class SplitActionSpec extends T {
private static async split(): Promise<void> {
Utils.injectJsonDownloadForTests(
"https://www.openstreetmap.org/api/0.6/way/295132739/full",
{
"version": "0.6",
"generator": "CGImap 0.8.5 (3138407 spike-07.openstreetmap.org)",
"copyright": "OpenStreetMap and contributors",
"attribution": "http://www.openstreetmap.org/copyright",
"license": "http://opendatacommons.org/licenses/odbl/1-0/",
"elements": [{
"type": "node",
"id": 170497153,
"lat": 51.1825167,
"lon": 3.2487885,
"timestamp": "2011-11-18T16:33:43Z",
"version": 5,
"changeset": 9865255,
"user": "TripleBee",
"uid": 497177
}, {
"type": "node",
"id": 170497155,
"lat": 51.1817632,
"lon": 3.2472706,
"timestamp": "2011-11-18T16:33:43Z",
"version": 5,
"changeset": 9865255,
"user": "TripleBee",
"uid": 497177
}, {
"type": "node",
"id": 170497157,
"lat": 51.1815203,
"lon": 3.2465569,
"timestamp": "2011-11-18T16:33:43Z",
"version": 5,
"changeset": 9865255,
"user": "TripleBee",
"uid": 497177
}, {
"type": "node",
"id": 170497158,
"lat": 51.1812261,
"lon": 3.2454261,
"timestamp": "2011-11-18T16:33:43Z",
"version": 5,
"changeset": 9865255,
"user": "TripleBee",
"uid": 497177
}, {
"type": "node",
"id": 170497160,
"lat": 51.1810957,
"lon": 3.2443030,
"timestamp": "2011-11-18T16:33:43Z",
"version": 5,
"changeset": 9865255,
"user": "TripleBee",
"uid": 497177
}, {
"type": "node",
"id": 1507524573,
"lat": 51.1810778,
"lon": 3.2437148,
"timestamp": "2011-11-18T16:33:36Z",
"version": 1,
"changeset": 9865255,
"user": "TripleBee",
"uid": 497177
}, {
"type": "node",
"id": 1507524582,
"lat": 51.1821130,
"lon": 3.2481284,
"timestamp": "2011-11-18T16:33:37Z",
"version": 1,
"changeset": 9865255,
"user": "TripleBee",
"uid": 497177
}, {
"type": "node",
"id": 1507524610,
"lat": 51.1811645,
"lon": 3.2450828,
"timestamp": "2011-11-18T16:33:38Z",
"version": 1,
"changeset": 9865255,
"user": "TripleBee",
"uid": 497177
}, {
"type": "node",
"id": 1575932830,
"lat": 51.1811153,
"lon": 3.2431503,
"timestamp": "2019-05-04T22:44:13Z",
"version": 2,
"changeset": 69891295,
"user": "Pieter Vander Vennet",
"uid": 3818858
}, {
"type": "node",
"id": 3208166178,
"lat": 51.1810837,
"lon": 3.2439090,
"timestamp": "2014-11-27T20:23:10Z",
"version": 1,
"changeset": 27076816,
"user": "JanFi",
"uid": 672253
}, {
"type": "node",
"id": 3208166179,
"lat": 51.1812062,
"lon": 3.2453151,
"timestamp": "2014-11-27T20:23:10Z",
"version": 1,
"changeset": 27076816,
"user": "JanFi",
"uid": 672253
}, {
"type": "node",
"id": 4524321710,
"lat": 51.1820656,
"lon": 3.2480253,
"timestamp": "2017-12-09T18:56:37Z",
"version": 2,
"changeset": 54493928,
"user": "CacherB",
"uid": 1999108
}, {
"type": "node",
"id": 5273988967,
"lat": 51.1826590,
"lon": 3.2490040,
"timestamp": "2017-12-09T18:40:21Z",
"version": 1,
"changeset": 54493533,
"user": "CacherB",
"uid": 1999108
}, {
"type": "node",
"id": 6448669326,
"lat": 51.1811346,
"lon": 3.2428910,
"timestamp": "2019-05-04T22:44:12Z",
"version": 1,
"changeset": 69891295,
"user": "Pieter Vander Vennet",
"uid": 3818858,
"tags": {"barrier": "bollard"}
}, {
"type": "way",
"id": 295132739,
"timestamp": "2021-07-29T21:14:53Z",
"version": 17,
"changeset": 108847202,
"user": "kaart_fietser",
"uid": 11022240,
"nodes": [5273988967, 170497153, 1507524582, 4524321710, 170497155, 170497157, 170497158, 3208166179, 1507524610, 170497160, 3208166178, 1507524573, 1575932830, 6448669326],
"tags": {
"highway": "cycleway",
"name": "Abdijenroute",
"railway": "abandoned",
"surface": "compacted"
}
}]
})
Utils.injectJsonDownloadForTests(
"https://www.openstreetmap.org/api/0.6/way/295132739/relations",
// Mimick that there are no relations relation is missing
{
"version": "0.6",
"generator": "CGImap 0.8.5 (2935793 spike-07.openstreetmap.org)",
"copyright": "OpenStreetMap and contributors",
"attribution": "http://www.openstreetmap.org/copyright",
"license": "http://opendatacommons.org/licenses/odbl/1-0/",
"elements": []
}
)
// Lets split road https://www.openstreetmap.org/way/295132739
const id = "way/295132739"
const splitPoint: [number, number] = [3.246733546257019, 51.181710380278176]
2021-10-06 02:36:58 +02:00
const splitter = new SplitAction(id, [splitPoint], {
theme: "test"
})
const changeDescription = await splitter.CreateChangeDescriptions(new Changes())
equal(changeDescription[0].type, "node")
equal(changeDescription[0].id, -1)
equal(changeDescription[0].changes["lat"], 51.181710380278176)
equal(changeDescription[0].changes["lon"], 3.246733546257019)
equal(changeDescription[1].type, "way")
equal(changeDescription[1].id, -2)
equal(changeDescription[1].changes["coordinates"].length, 6)
equal(changeDescription[1].changes["coordinates"][5][0], splitPoint[0])
equal(changeDescription[1].changes["coordinates"][5][1], splitPoint[1])
equal(changeDescription[2].type, "way")
equal(changeDescription[2].id, 295132739)
equal(changeDescription[2].changes["coordinates"].length, 10)
equal(changeDescription[2].changes["coordinates"][0][0], splitPoint[0])
equal(changeDescription[2].changes["coordinates"][0][1], splitPoint[1])
}
private static async SplitHoutkaai() : Promise<void>{
Utils.injectJsonDownloadForTests(
"https://www.openstreetmap.org/api/0.6/way/61435323/full" ,
{"version":"0.6","generator":"CGImap 0.8.5 (53092 spike-08.openstreetmap.org)","copyright":"OpenStreetMap and contributors","attribution":"http://www.openstreetmap.org/copyright","license":"http://opendatacommons.org/licenses/odbl/1-0/","elements":[{"type":"node","id":766990983,"lat":51.2170219,"lon":3.2022337,"timestamp":"2021-04-26T15:48:22Z","version":6,"changeset":103647857,"user":"M!dgard","uid":763799},{"type":"node","id":766990985,"lat":51.2169574,"lon":3.2017548,"timestamp":"2016-07-05T22:41:12Z","version":6,"changeset":40511250,"user":"M!dgard","uid":763799},{"type":"node","id":8669018379,"lat":51.2169592,"lon":3.2017683,"timestamp":"2021-04-26T15:48:22Z","version":1,"changeset":103647857,"user":"M!dgard","uid":763799},{"type":"way","id":61435323,"timestamp":"2021-08-21T12:24:13Z","version":7,"changeset":110026637,"user":"Thibault Rommel","uid":5846458,"nodes":[766990983,8669018379,766990985],"tags":{"bicycle":"yes","bridge":"yes","cycleway":"shared_lane","highway":"unclassified","layer":"1","maxspeed":"50","name":"Houtkaai","surface":"asphalt","zone:traffic":"BE-VLG:urban"}}]}
)
Utils.injectJsonDownloadForTests(
"https://www.openstreetmap.org/api/0.6/way/61435323/relations" ,
{"version":"0.6","generator":"CGImap 0.8.5 (3622541 spike-06.openstreetmap.org)","copyright":"OpenStreetMap and contributors","attribution":"http://www.openstreetmap.org/copyright","license":"http://opendatacommons.org/licenses/odbl/1-0/","elements":[{"type":"relation","id":1723870,"timestamp":"2021-09-18T06:29:31Z","version":183,"changeset":111362343,"user":"emvee","uid":5211,"members":[{"type":"way","ref":261428947,"role":""},{"type":"way","ref":162774622,"role":""},{"type":"way","ref":317060244,"role":""},{"type":"way","ref":81155378,"role":""},{"type":"way","ref":99749583,"role":""},{"type":"way","ref":131332113,"role":""},{"type":"way","ref":949518831,"role":""},{"type":"way","ref":99749584,"role":""},{"type":"way","ref":129133519,"role":""},{"type":"way","ref":73241312,"role":""},{"type":"way","ref":785514256,"role":""},{"type":"way","ref":58509643,"role":""},{"type":"way","ref":73241332,"role":""},{"type":"way","ref":58509653,"role":""},{"type":"way","ref":100044097,"role":""},{"type":"way","ref":946999067,"role":""},{"type":"way","ref":73241327,"role":""},{"type":"way","ref":58509617,"role":""},{"type":"way","ref":58509627,"role":""},{"type":"way","ref":69990655,"role":""},{"type":"way","ref":73241311,"role":""},{"type":"way","ref":123142336,"role":""},{"type":"way","ref":249671053,"role":""},{"type":"way","ref":73241324,"role":""},{"type":"way","ref":66706953,"role":""},{"type":"way","ref":112679357,"role":""},{"type":"way","ref":112679358,"role":""},{"type":"way","ref":53105113,"role":""},{"type":"way","ref":66706952,"role":""},{"type":"way","ref":64083661,"role":""},{"type":"way","ref":53105162,"role":""},{"type":"way","ref":249671070,"role":""},{"type":"way","ref":249671064,"role":""},{"type":"way","ref":101498587,"role":""},{"type":"way","ref":69001236,"role":""},{"type":"way","ref":101498585,"role":""},{"type":"way","ref":70909444,"role":""},{"type":"way","ref":73241314,"role":""},{"type":"way","ref":69001235,"role":""},{"type":"way","ref":113150200,"role":""},{"type":"way","ref":137305843,"role":""},{"type":"way","ref":936827687,"role":""},{"type":"way","ref":936827688,"role":""},{"type":"way","ref":112952373,"role":""},{"type":"way","ref":930798379,"role":""},{"type":"way","ref":930798378,"role":""},{"type":"way","ref":112951439,"role":""},{"type":"way","ref":445541591,"role":""},{"type":"way","ref":103843896,"role":""},{"type":"way","ref":23734118,"role":""},{"type":"way","ref":103840557,"role":""},{"type":"way","ref":433852210,"role":""},{"type":"way","ref":313604670,"role":""},{"type":"way","ref":103839402,"role":""},{"type":"way","ref":23736061,"role":""},{"type":"way","ref":73241328,"role":""},{"type":"way","ref":295392689,"role":""},{"type":"way","ref":297168171,"role":""},{"type":"way","ref":297168170,"role":""},{"type":"way","ref":433852205,"role":""},{"type":"way","ref":295392695,"role":""},{"type":"way","ref":663268954,"role":""},{"type":"way","ref":663267598,"role":""},{"type":"way","ref":292478843,"role":""},{"type":"way","ref":981853853,"role":""},{"type":"way","ref":663270140,"role":""},{"type":"way","ref":981853854,"role":""},{"type":"way","ref":295392703,"role":""},{"type":"way","ref":663304916,"role":""},{"type":"way","ref":297169116,"role":""},{"type":"way","ref":295400810,"role":""},{"type":"way","ref":981853855,"role":""},{"type":"way","ref":663304806,"role":""},{"type":"way","ref":516452870,"role":""},{"type":"way","ref":66459239,"role":""},{"type":"way","ref":791430504,"role":""},{"type":"way","ref":178926037,"role":""},{"type":"way","ref":864799431,"role":""},{"type":"way","ref":178926107,"role":""},{"type":"way","ref":663320459,"role":""},{"type":"way","ref":62033993,"role":""},{"type":"way","ref":62283023,"role":""},{"type":"way","ref":62283057,"role":""},{"type":"way","ref":62283032,"role":""},{"type":"way","ref":490551085,"role":""},{"type":"way","ref":435318979,"role":""},{"type":"way","ref":371750677,"role":""},{"type":"way","ref":371750670,"role":""},{"type":"way","ref":371750673,"role":""},{"type":"way","ref":371750675,"role":""},{"type":"way","ref":459885691,"r
)
Utils.injectJsonDownloadForTests(
"https://www.openstreetmap.org/api/0.6/way/61435332/full" ,
{"version":"0.6","generator":"CGImap 0.8.5 (3819319 spike-06.openstreetmap.org)","copyright":"OpenStreetMap and contributors","attribution":"http://www.openstreetmap.org/copyright","license":"http://opendatacommons.org/licenses/odbl/1-0/","elements":[{"type":"node","id":766990985,"lat":51.2169574,"lon":3.2017548,"timestamp":"2016-07-05T22:41:12Z","version":6,"changeset":40511250,"user":"M!dgard","uid":763799},{"type":"node","id":3450208876,"lat":51.2169482,"lon":3.2016802,"timestamp":"2016-07-05T22:41:11Z","version":2,"changeset":40511250,"user":"M!dgard","uid":763799},{"type":"way","id":61435332,"timestamp":"2021-08-21T12:24:13Z","version":8,"changeset":110026637,"user":"Thibault Rommel","uid":5846458,"nodes":[766990985,3450208876],"tags":{"bicycle":"yes","cycleway":"shared_lane","highway":"unclassified","maxspeed":"50","name":"Houtkaai","surface":"asphalt","zone:traffic":"BE-VLG:urban"}}]}
)
Utils.injectJsonDownloadForTests(
"https://www.openstreetmap.org/api/0.6/way/509668834/full" ,
{"version":"0.6","generator":"CGImap 0.8.5 (3735280 spike-06.openstreetmap.org)","copyright":"OpenStreetMap and contributors","attribution":"http://www.openstreetmap.org/copyright","license":"http://opendatacommons.org/licenses/odbl/1-0/","elements":[{"type":"node","id":131917824,"lat":51.2170327,"lon":3.2023577,"timestamp":"2019-09-16T09:48:28Z","version":17,"changeset":74521581,"user":"Peter Elderson","uid":7103674,"tags":{"network:type":"node_network","rcn_ref":"4","rcn_region":"Brugse Ommeland"}},{"type":"node","id":766990983,"lat":51.2170219,"lon":3.2022337,"timestamp":"2021-04-26T15:48:22Z","version":6,"changeset":103647857,"user":"M!dgard","uid":763799},{"type":"way","id":509668834,"timestamp":"2021-08-21T12:24:13Z","version":5,"changeset":110026637,"user":"Thibault Rommel","uid":5846458,"nodes":[131917824,766990983],"tags":{"bicycle":"yes","cycleway":"shared_lane","highway":"residential","lit":"yes","maxspeed":"30","name":"Houtkaai","sidewalk":"both","surface":"paving_stones","zone:maxspeed":"BE:30","zone:traffic":"BE-VLG:urban"}}]}
)
const id = "way/61435323"
const splitPoint: [number, number] = [ 3.2021324336528774, 51.2170001600597]
2021-10-06 02:36:58 +02:00
const splitter = new SplitAction(id, [splitPoint], {
theme: "test"
})
const changeDescription = await splitter.CreateChangeDescriptions(new Changes())
// Should be a new node
equal(changeDescription[0].type ,"node")
equal(changeDescription[3].type , "relation")
}
private static async splitWithPointReuse(): Promise<void> {
// Lets split road near an already existing point https://www.openstreetmap.org/way/295132739
const id = "way/295132739"
const splitPoint: [number, number] = [3.2451081275939937, 51.18116898253599]
2021-10-06 02:36:58 +02:00
const splitter = new SplitAction(id, [splitPoint], {
theme: "test"
})
const changeDescription = await splitter.CreateChangeDescriptions(new Changes())
equal(2, changeDescription.length)
const ch0 = changeDescription[0]
const ch1 = changeDescription[1]
const nodes0: number[] = ch0.changes["nodes"]
const nodes1: number[] = ch1.changes["nodes"]
equal(ch0.type, "way")
equal(ch1.type, "way")
equal(nodes0[nodes0.length - 1], nodes1[0])
equal(3208166179, nodes1[0])
}
constructor() {
super("splitaction", [
["split 295132739",
() => SplitActionSpec.split().then(_ => console.log("OK"))],
["split 295132739 on already existing node",
() => SplitActionSpec.splitWithPointReuse().then(_ => console.log("OK"))],
["split 61435323 on already existing node",
() => SplitActionSpec.SplitHoutkaai().then(_ => console.log("OK"))]
]);
}
}