forked from MapComplete/MapComplete
Scripts: add script to fix panoramax-hashes; see #2372
This commit is contained in:
parent
1493c00edf
commit
c4f0e18b9e
3 changed files with 153 additions and 10 deletions
|
@ -95,8 +95,34 @@ export class Changes {
|
|||
})
|
||||
}
|
||||
|
||||
public static async createChangesetXMLForJosm(actions: OsmChangeAction[], osmConnection?: OsmConnection): Promise<string> {
|
||||
osmConnection ??= new OsmConnection()
|
||||
const changes = new Changes({
|
||||
osmConnection
|
||||
})
|
||||
const descriptions: ChangeDescription[] = []
|
||||
for (const action of actions) {
|
||||
descriptions.push(...await action.Perform(changes))
|
||||
}
|
||||
const downloader = new OsmObjectDownloader(osmConnection.Backend(), undefined)
|
||||
const downloaded: OsmObject[] = []
|
||||
for (const action of actions) {
|
||||
const osmObj = await downloader.DownloadObjectAsync(action.mainObjectId)
|
||||
if (osmObj === "deleted") {
|
||||
continue
|
||||
}
|
||||
downloaded.push(osmObj)
|
||||
}
|
||||
return Changes.buildChangesetXML("", changes.CreateChangesetObjects(descriptions, downloaded))
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a changeset
|
||||
* @param csId either the ID-number of the changeset, or an empty string (e.g. when uploading with JOSM)
|
||||
* @param allChanges use 'new Changes()
|
||||
*/
|
||||
static buildChangesetXML(
|
||||
csId: string,
|
||||
csId: number | string,
|
||||
allChanges: {
|
||||
modifiedObjects: OsmObject[]
|
||||
newObjects: OsmObject[]
|
||||
|
@ -111,20 +137,20 @@ export class Changes {
|
|||
if (newElements.length > 0) {
|
||||
changes +=
|
||||
"\n<create>\n" +
|
||||
newElements.map((e) => e.ChangesetXML(csId)).join("\n") +
|
||||
newElements.map((e) => e.ChangesetXML("" + csId)).join("\n") +
|
||||
"</create>"
|
||||
}
|
||||
if (changedElements.length > 0) {
|
||||
changes +=
|
||||
"\n<modify>\n" +
|
||||
changedElements.map((e) => e.ChangesetXML(csId)).join("\n") +
|
||||
changedElements.map((e) => e.ChangesetXML("" + csId)).join("\n") +
|
||||
"\n</modify>"
|
||||
}
|
||||
|
||||
if (deletedElements.length > 0) {
|
||||
changes +=
|
||||
"\n<delete>\n" +
|
||||
deletedElements.map((e) => e.ChangesetXML(csId)).join("\n") +
|
||||
deletedElements.map((e) => e.ChangesetXML("" + csId)).join("\n") +
|
||||
"\n</delete>"
|
||||
}
|
||||
|
||||
|
@ -722,7 +748,7 @@ export class Changes {
|
|||
deletedObjects: OsmObject[]
|
||||
} = this.CreateChangesetObjects(toUpload, objects)
|
||||
|
||||
return Changes.buildChangesetXML("" + csId, changes)
|
||||
return Changes.buildChangesetXML(csId, changes)
|
||||
},
|
||||
metatags,
|
||||
openChangeset
|
||||
|
|
|
@ -3,10 +3,10 @@ import { Utils } from "../../Utils"
|
|||
import { ImmutableStore, Store } from "../UIEventSource"
|
||||
import { BBox } from "../BBox"
|
||||
import osmtogeojson from "osmtogeojson"
|
||||
import { FeatureCollection } from "@turf/turf"
|
||||
import { Geometry } from "geojson"
|
||||
import { FeatureCollection, Geometry } from "geojson"
|
||||
import { OsmTags } from "../../Models/OsmFeature"
|
||||
;("use strict")
|
||||
|
||||
("use strict")
|
||||
/**
|
||||
* Interfaces overpass to get all the latest data
|
||||
*/
|
||||
|
@ -64,14 +64,14 @@ export class Overpass {
|
|||
elements: []
|
||||
remark
|
||||
osm3s: { timestamp_osm_base: string }
|
||||
}>(this.buildUrl(query))
|
||||
}>(this.buildUrl(query), {})
|
||||
|
||||
if (json.elements.length === 0 && json.remark !== undefined) {
|
||||
console.warn("Timeout or other runtime error while querying overpass", json.remark)
|
||||
throw `Runtime error (timeout or similar)${json.remark}`
|
||||
}
|
||||
if (json.elements.length === 0) {
|
||||
console.warn("No features for", json)
|
||||
console.warn("No features for", this.buildUrl(query))
|
||||
}
|
||||
|
||||
const geojson = <FeatureCollection<Geometry, OsmTags>>osmtogeojson(json)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue