Refactoring: reorder parameters in overpass, remove old script

This commit is contained in:
Pieter Vander Vennet 2025-05-07 15:35:35 +02:00
parent 1ef82ef6cc
commit bb33c43950
6 changed files with 13 additions and 122 deletions

View file

@ -33,7 +33,7 @@ export default class CleanRepair extends Script {
"repair!=assisted_self_service", "repair!=assisted_self_service",
], ],
}) })
const overpass = new Overpass(criteria, [], "https://overpass-api.de/api/interpreter") const overpass = new Overpass("https://overpass-api.de/api/interpreter", criteria)
const data: Feature<Geometry, Record<string, string>>[] = ( const data: Feature<Geometry, Record<string, string>>[] = (
await overpass.queryGeoJson(BBox.global) await overpass.queryGeoJson(BBox.global)
)[0].features )[0].features

View file

@ -1,101 +0,0 @@
import Script from "./Script"
import { Overpass } from "../src/Logic/Osm/Overpass"
import { Or } from "../src/Logic/Tags/Or"
import { RegexTag } from "../src/Logic/Tags/RegexTag"
import { Utils } from "../src/Utils"
import Constants from "../src/Models/Constants"
import { ImmutableStore } from "../src/Logic/UIEventSource"
import { BBox } from "../src/Logic/BBox"
import ChangeTagAction from "../src/Logic/Osm/Actions/ChangeTagAction"
import { Tag } from "../src/Logic/Tags/Tag"
import { Panoramax } from "panoramax-js/dist"
import { Changes } from "../src/Logic/Osm/Changes"
import OsmChangeAction from "../src/Logic/Osm/Actions/OsmChangeAction"
import { writeFileSync } from "fs"
import { Feature } from "geojson"
class RepairPanoramax extends Script {
private static readonly europe: Feature = {
type: "Feature",
properties: {},
geometry: {
coordinates: [
[
[-20.091159690050006, 25.773375277790038],
[46.12276429398841, 25.773375277790038],
[46.12276429398841, 65.41389761819318],
[-20.091159690050006, 65.41389761819318],
[-20.091159690050006, 25.773375277790038],
],
],
type: "Polygon",
},
}
constructor() {
super(
"See https://source.mapcomplete.org/MapComplete/MapComplete/issues/2372\n" +
"We accidentally added the full image URL instead of the hash due to a bug. This scripts rewrites all"
)
}
async main(args: string[]): Promise<void> {
const keys = ["panoramax", ...Utils.TimesT(10, (i) => "panoramax:" + i)]
const overpass = new Overpass(
new Or(keys.map((k) => new RegexTag(k, /^https:\/\/panoramax.mapcomplete.org\/.*/))),
[],
Constants.defaultOverpassUrls[0],
new ImmutableStore(500)
)
const [wrongFeatures] = await overpass.queryGeoJson(BBox.global)
const allChanges: OsmChangeAction[] = []
for (const f of wrongFeatures.features) {
for (const key of keys) {
const v = f.properties[key]
if (!v) {
continue
}
const pre = "https://panoramax.mapcomplete.org/api/pictures/"
const pre1 = "https://panoramax.mapcomplete.org/permanent/"
let correct: string
if (v.startsWith(pre)) {
correct = v.substring(pre.length)
correct = correct.substring(0, correct.indexOf("/"))
} else if (v.startsWith(pre1)) {
const stripped = v.substring(pre1.length)
correct = stripped.replace(/\//g, "").replace(/\.jpg$/, "")
correct = correct.substring(0, 8) + "-" + correct.substring(8)
} else if (Panoramax.isId(v)) {
// This is a valid ID that came on an object also having an _invalid_ id
// We can safely skip this
continue
} else {
throw "Unknown url " + v
}
console.log(key, correct, " old: ", v)
if (!Panoramax.isId(correct)) {
throw "Constructed an invalid id:" + correct
}
const change = new ChangeTagAction(
f.properties.id,
new Tag(key, correct),
f.properties,
{
theme: "fix",
changeType: "fix",
}
)
allChanges.push(change)
}
}
const xml = await Changes.createChangesetXMLForJosm(allChanges)
console.log(xml)
const path = "repairPanoramax.osc"
writeFileSync(path, xml)
console.log("Written XML to", path)
}
}
new RepairPanoramax().run()

View file

@ -186,13 +186,7 @@ class VeloParkToGeojson extends Script {
[6.15665815596, 51.4750237087], [6.15665815596, 51.4750237087],
]) ])
const alreadyLinkedQuery = new Overpass( const alreadyLinkedQuery = new Overpass(Constants.defaultOverpassUrls[0], new RegexTag("ref:velopark", /.+/), [], new ImmutableStore(60 * 5), false)
new RegexTag("ref:velopark", /.+/),
[],
Constants.defaultOverpassUrls[0],
new ImmutableStore(60 * 5),
false
)
const alreadyLinkedFeatures = (await alreadyLinkedQuery.queryGeoJson(bboxBelgium))[0] const alreadyLinkedFeatures = (await alreadyLinkedQuery.queryGeoJson(bboxBelgium))[0]
const seenIds = new Set<string>( const seenIds = new Set<string>(
alreadyLinkedFeatures.features.map((f) => f.properties?.["ref:velopark"]) alreadyLinkedFeatures.features.map((f) => f.properties?.["ref:velopark"])

View file

@ -1,4 +1,4 @@
import { Feature, Geometry } from "geojson" import { Feature, FeatureCollection, Geometry } from "geojson"
import { UpdatableFeatureSource } from "../FeatureSource" import { UpdatableFeatureSource } from "../FeatureSource"
import { ImmutableStore, Store, UIEventSource } from "../../UIEventSource" import { ImmutableStore, Store, UIEventSource } from "../../UIEventSource"
import LayerConfig from "../../../Models/ThemeConfig/LayerConfig" import LayerConfig from "../../../Models/ThemeConfig/LayerConfig"
@ -7,9 +7,9 @@ import { Overpass } from "../../Osm/Overpass"
import { Utils } from "../../../Utils" import { Utils } from "../../../Utils"
import { TagsFilter } from "../../Tags/TagsFilter" import { TagsFilter } from "../../Tags/TagsFilter"
import { BBox } from "../../BBox" import { BBox } from "../../BBox"
import { FeatureCollection } from "@turf/turf"
import { OsmTags } from "../../../Models/OsmFeature" import { OsmTags } from "../../../Models/OsmFeature"
;("use strict")
("use strict")
/** /**
* A wrapper around the 'Overpass'-object. * A wrapper around the 'Overpass'-object.
@ -204,7 +204,7 @@ export default class OverpassFeatureSource implements UpdatableFeatureSource {
if (filters.length === 0) { if (filters.length === 0) {
return undefined return undefined
} }
return new Overpass(new Or(filters), [], interpreterUrl, this.state.overpassTimeout) return new Overpass(interpreterUrl, new Or(filters), [], this.state.overpassTimeout)
} }
/** /**

View file

@ -5,7 +5,8 @@ import { BBox } from "../BBox"
import osmtogeojson from "osmtogeojson" import osmtogeojson from "osmtogeojson"
import { FeatureCollection, Geometry } from "geojson" import { FeatureCollection, Geometry } from "geojson"
import { OsmTags } from "../../Models/OsmFeature" import { OsmTags } from "../../Models/OsmFeature"
;("use strict")
("use strict")
/** /**
* Interfaces overpass to get all the latest data * Interfaces overpass to get all the latest data
*/ */
@ -17,9 +18,9 @@ export class Overpass {
private readonly _includeMeta: boolean private readonly _includeMeta: boolean
constructor( constructor(
filter: TagsFilter,
extraScripts: string[],
interpreterUrl: string, interpreterUrl: string,
filter: TagsFilter,
extraScripts: string[] = [],
timeout?: Store<number>, timeout?: Store<number>,
includeMeta = true includeMeta = true
) { ) {
@ -146,7 +147,7 @@ export class Overpass {
* Little helper method to quickly open overpass-turbo in the browser * Little helper method to quickly open overpass-turbo in the browser
*/ */
public static AsOverpassTurboLink(tags: TagsFilter) { public static AsOverpassTurboLink(tags: TagsFilter) {
const overpass = new Overpass(tags, [], "", undefined, false) const overpass = new Overpass("", tags, [], undefined, false)
const script = overpass.buildScript("", "({{bbox}})", true) const script = overpass.buildScript("", "({{bbox}})", true)
const url = "http://overpass-turbo.eu/?Q=" const url = "http://overpass-turbo.eu/?Q="
return url + encodeURIComponent(script) return url + encodeURIComponent(script)

View file

@ -135,11 +135,8 @@
step.setData("loading") step.setData("loading")
featuresStore.set([]) featuresStore.set([])
const overpass = new Overpass( const overpass = new Overpass(Constants.defaultOverpassUrls[0], undefined,
undefined, user.split(";").map((user) => "nw(user_touched:\"" + user + "\");"))
user.split(";").map((user) => 'nw(user_touched:"' + user + '");'),
Constants.defaultOverpassUrls[0]
)
if (!maplibremap.bounds.data) { if (!maplibremap.bounds.data) {
return return
} }