forked from MapComplete/MapComplete
chore: automated housekeeping...
This commit is contained in:
parent
21d01a46f9
commit
ee6c63ee14
67 changed files with 2358 additions and 2198 deletions
|
|
@ -1,11 +1,11 @@
|
|||
import Script from "./Script"
|
||||
import fs from "fs"
|
||||
import {Feature} from "geojson"
|
||||
import {GeoOperations} from "../Logic/GeoOperations"
|
||||
import {Utils} from "../Utils"
|
||||
import {OsmObject} from "../Logic/Osm/OsmObject"
|
||||
import {PhoneTextField, UrlTextfieldDef} from "../UI/Input/ValidatedTextField"
|
||||
import {OsmId} from "../Models/OsmFeature"
|
||||
import { Feature } from "geojson"
|
||||
import { GeoOperations } from "../Logic/GeoOperations"
|
||||
import { Utils } from "../Utils"
|
||||
import { OsmObject } from "../Logic/Osm/OsmObject"
|
||||
import { PhoneTextField, UrlTextfieldDef } from "../UI/Input/ValidatedTextField"
|
||||
import { OsmId } from "../Models/OsmFeature"
|
||||
import ScriptUtils from "./ScriptUtils"
|
||||
|
||||
interface PossibleMatch {
|
||||
|
|
@ -46,15 +46,12 @@ export class Conflate extends Script {
|
|||
}
|
||||
|
||||
private static toXml(changedObjects: OsmObject[]): string {
|
||||
|
||||
return [
|
||||
"<?xml version='1.0' encoding='UTF-8'?>",
|
||||
"<osm version=\"0.6\" generator='mapcomplete-conflate-script'>",
|
||||
...changedObjects.map(obj =>
|
||||
obj.ChangesetXML(undefined, ' action="modify" ')
|
||||
),
|
||||
"</osm>"
|
||||
].join("\n");
|
||||
...changedObjects.map((obj) => obj.ChangesetXML(undefined, ' action="modify" ')),
|
||||
"</osm>",
|
||||
].join("\n")
|
||||
}
|
||||
|
||||
async main(args: string[]): Promise<void> {
|
||||
|
|
@ -82,10 +79,10 @@ export class Conflate extends Script {
|
|||
}
|
||||
|
||||
const external_features: Feature[] = JSON.parse(
|
||||
fs.readFileSync(external_file_path, {encoding: "utf-8"})
|
||||
fs.readFileSync(external_file_path, { encoding: "utf-8" })
|
||||
).features
|
||||
const osm_features: Feature[] = JSON.parse(
|
||||
fs.readFileSync(osm_file_path, {encoding: "utf-8"})
|
||||
fs.readFileSync(osm_file_path, { encoding: "utf-8" })
|
||||
).features
|
||||
|
||||
const bestMatches = await this.calculateMatches(external_features, osm_features, max_range)
|
||||
|
|
@ -104,9 +101,9 @@ export class Conflate extends Script {
|
|||
]
|
||||
|
||||
const changedObjects: OsmObject[] = []
|
||||
for (const {match, replayed} of bestMatches) {
|
||||
const {external_feature, d, osm_feature} = match
|
||||
const {possibly_imported, certainly_imported, resting_properties} = replayed
|
||||
for (const { match, replayed } of bestMatches) {
|
||||
const { external_feature, d, osm_feature } = match
|
||||
const { possibly_imported, certainly_imported, resting_properties } = replayed
|
||||
const status = resting_properties["status"]
|
||||
delete resting_properties["status"]
|
||||
if (Object.keys(resting_properties).length === 0) {
|
||||
|
|
@ -137,13 +134,10 @@ export class Conflate extends Script {
|
|||
match_lengths.map((l) => l.join("\t")).join("\n")
|
||||
)
|
||||
|
||||
fs.writeFileSync(targetDir + "/changeset.xml",
|
||||
Conflate.toXml(changedObjects)
|
||||
)
|
||||
fs.writeFileSync(targetDir + "/changeset.xml", Conflate.toXml(changedObjects))
|
||||
|
||||
|
||||
fs.writeFileSync(targetDir +
|
||||
"/unmatched.geojson",
|
||||
fs.writeFileSync(
|
||||
targetDir + "/unmatched.geojson",
|
||||
JSON.stringify(
|
||||
{
|
||||
type: "FeatureCollection",
|
||||
|
|
@ -191,7 +185,7 @@ export class Conflate extends Script {
|
|||
this.latestDate = latest
|
||||
}
|
||||
|
||||
return {earliestDateOfImport: earliest, latestDateOfImport: latest}
|
||||
return { earliestDateOfImport: earliest, latestDateOfImport: latest }
|
||||
}
|
||||
|
||||
private findPossibleMatchesFor(
|
||||
|
|
@ -227,7 +221,7 @@ export class Conflate extends Script {
|
|||
}
|
||||
const cachePath = this.historyCacheDir + "/urls/ " + url.replace(/[/\\:]/g, "_")
|
||||
if (fs.existsSync(cachePath)) {
|
||||
return JSON.parse(fs.readFileSync(cachePath, {encoding: "utf-8"}))
|
||||
return JSON.parse(fs.readFileSync(cachePath, { encoding: "utf-8" }))
|
||||
}
|
||||
let online: boolean | string = false
|
||||
try {
|
||||
|
|
@ -239,7 +233,7 @@ export class Conflate extends Script {
|
|||
console.log("Maybe trying the homepage will help?")
|
||||
}
|
||||
}
|
||||
fs.writeFileSync(cachePath, JSON.stringify(online, null, " "), {encoding: "utf-8"})
|
||||
fs.writeFileSync(cachePath, JSON.stringify(online, null, " "), { encoding: "utf-8" })
|
||||
return online
|
||||
}
|
||||
|
||||
|
|
@ -250,7 +244,8 @@ export class Conflate extends Script {
|
|||
url = url.replace("http://", "https://")
|
||||
try {
|
||||
const result = await ScriptUtils.Download(url, {
|
||||
"User-agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0"
|
||||
"User-agent":
|
||||
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0",
|
||||
})
|
||||
if (result["redirect"]) {
|
||||
if (result["redirect"].startsWith("/")) {
|
||||
|
|
@ -275,10 +270,10 @@ export class Conflate extends Script {
|
|||
fs.mkdirSync(this.historyCacheDir)
|
||||
}
|
||||
if (fs.existsSync(cachePath)) {
|
||||
return JSON.parse(fs.readFileSync(cachePath, {encoding: "utf-8"}))
|
||||
return JSON.parse(fs.readFileSync(cachePath, { encoding: "utf-8" }))
|
||||
}
|
||||
const history = await OsmObject.DownloadHistory(id).AsPromise((l) => l.length > 0)
|
||||
fs.writeFileSync(cachePath, JSON.stringify(history, null, " "), {encoding: "utf-8"})
|
||||
fs.writeFileSync(cachePath, JSON.stringify(history, null, " "), { encoding: "utf-8" })
|
||||
return history
|
||||
}
|
||||
|
||||
|
|
@ -323,7 +318,7 @@ export class Conflate extends Script {
|
|||
let certainly_imported = match.d < 0.0001
|
||||
let possibly_imported = false
|
||||
|
||||
const resting_properties = {...match.external_feature.properties}
|
||||
const resting_properties = { ...match.external_feature.properties }
|
||||
await this.normalize(resting_properties)
|
||||
|
||||
for (const historyElement of history) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue