From d29302ca8487c6efbff04dff1c62619c31abc174 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Tue, 24 Aug 2021 12:13:47 +0200 Subject: [PATCH] Small (and rough) script to create some very specific changesets --- Logic/Osm/OsmObject.ts | 12 ++++++++---- scripts/CycleHighwayFix.ts | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Logic/Osm/OsmObject.ts b/Logic/Osm/OsmObject.ts index 8a97e9ba1..224e4ff37 100644 --- a/Logic/Osm/OsmObject.ts +++ b/Logic/Osm/OsmObject.ts @@ -115,6 +115,7 @@ export abstract class OsmObject { const rels = data.elements.map(wayInfo => { const rel = new OsmRelation(wayInfo.id) rel.LoadData(wayInfo) + rel.SaveExtraData(wayInfo) return rel }) relsSrc.setData(rels) @@ -496,10 +497,13 @@ export class OsmRelation extends OsmObject { } let tags = this.TagsXML(); - return ' \n' + - members + - tags + - ' \n'; + let cs = "" + if(changesetId !== undefined){ + cs = `changeset="${changesetId}"` + } + return ` +${members}${tags} +`; } diff --git a/scripts/CycleHighwayFix.ts b/scripts/CycleHighwayFix.ts index e69de29bb..5ce8b46d9 100644 --- a/scripts/CycleHighwayFix.ts +++ b/scripts/CycleHighwayFix.ts @@ -0,0 +1,21 @@ +import ScriptUtils from "./ScriptUtils"; +ScriptUtils.fixUtils() +import {appendFileSync, readFileSync, writeFileSync} from "fs"; +import {OsmObject} from "../Logic/Osm/OsmObject"; + +ScriptUtils.erasableLog("Fixing the cycle highways...") +writeFileSync("cycleHighwayFix.osc","\n" + + " ", "utf8") +const ids = JSON.parse(readFileSync("export.geojson","utf-8")).features.map(f => f.properties["@id"]) +console.log(ids) +ids.map(id => OsmObject.DownloadReferencingRelations(id).addCallbackAndRunD(relations => { + console.log(relations) + const changeparts = relations.filter(relation => relation.tags["cycle_highway"] == "yes" && relation.tags["note:state"] == undefined) + .map(relation => { + relation.tags["note:state"]="has_highway_under_construction"; + return relation.ChangesetXML(undefined) + }) + appendFileSync("cycleHighwayFix.osc", changeparts.join("\n"), "utf8") + return true; +})) \ No newline at end of file