forked from MapComplete/MapComplete
Themes(benches): last tweaks to openbenches script
This commit is contained in:
parent
55c2af394e
commit
43ff72d262
1 changed files with 21 additions and 26 deletions
|
@ -241,13 +241,17 @@ class Openbenches extends Script {
|
||||||
const mediaInscr = media.filter(m => m.media_type === "inscription")
|
const mediaInscr = media.filter(m => m.media_type === "inscription")
|
||||||
const mediaView = media.filter(m => m.media_type === "view")
|
const mediaView = media.filter(m => m.media_type === "view")
|
||||||
|
|
||||||
|
const inscription = benchWithUser.inscription.replaceAll("\\r\\n", "\n")
|
||||||
const properties = {
|
const properties = {
|
||||||
lastModifiedTime: benchWithUser.added,
|
lastModifiedTime: benchWithUser.added,
|
||||||
"openbenches:id": id,
|
"openbenches:id": id,
|
||||||
inscription: benchWithUser.inscription.replaceAll("\\r\\n", "\n"),
|
inscription: inscription.slice(0,255),
|
||||||
amenity: "bench",
|
amenity: "bench",
|
||||||
lastModifiedBy: benchWithUser.name,
|
lastModifiedBy: benchWithUser.name,
|
||||||
}
|
}
|
||||||
|
if(inscription.length >= 255){
|
||||||
|
properties["inscription:0"] = inscription.slice(255)
|
||||||
|
}
|
||||||
|
|
||||||
let mediaMerged = Lists.dedup(mediaBench.concat(mediaInscr).map(m => mediaUrl(m)))
|
let mediaMerged = Lists.dedup(mediaBench.concat(mediaInscr).map(m => mediaUrl(m)))
|
||||||
for (let i = 0; i < mediaMerged.length; i++) {
|
for (let i = 0; i < mediaMerged.length; i++) {
|
||||||
|
@ -394,6 +398,8 @@ class Openbenches extends Script {
|
||||||
console.log("No database file found at "+dbFile+", recreating the database")
|
console.log("No database file found at "+dbFile+", recreating the database")
|
||||||
await this.buildDatabase("/home/pietervdvn/git/openbenches.org/database", dbFile)
|
await this.buildDatabase("/home/pietervdvn/git/openbenches.org/database", dbFile)
|
||||||
}
|
}
|
||||||
|
const alreadyLinked: Set<number> = new Set(osmData.features.map(f => Number(f.properties["openbenches:id"])))
|
||||||
|
|
||||||
|
|
||||||
this.db = await this.loadDb(dbFile)
|
this.db = await this.loadDb(dbFile)
|
||||||
|
|
||||||
|
@ -412,57 +418,46 @@ class Openbenches extends Script {
|
||||||
tagsOnBenches.get(bench).push(tags.get(tg.tagID))
|
tagsOnBenches.get(bench).push(tags.get(tg.tagID))
|
||||||
}
|
}
|
||||||
|
|
||||||
const alreadyLinked = new Set(osmData.features.map(f => f.properties["openbenches:id"]))
|
const openbenches = await this.all<Bench & User>("SELECT * FROM benches INNER JOIN users ON benches.userID = users.userID")
|
||||||
const r = await this.all<Bench & User>("SELECT * FROM benches INNER JOIN users ON benches.userID = users.userID")
|
|
||||||
const features: Feature<Point>[] = []
|
const features: Feature<Point>[] = []
|
||||||
for (let i = 0; i < r.length; i++) {
|
let skipped = 0
|
||||||
const benchWithUser = r[i]
|
for (let i = 0; i < openbenches.length; i++) {
|
||||||
|
if(alreadyLinked.has(i)){
|
||||||
|
skipped++
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
const benchWithUser = openbenches[i]
|
||||||
if (benchWithUser.present === 0 || benchWithUser.published === 0) {
|
if (benchWithUser.present === 0 || benchWithUser.published === 0) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
const tags = tagsOnBenches.get(benchWithUser.benchID)
|
const tags = tagsOnBenches.get(benchWithUser.benchID)
|
||||||
if (i % 100 === 0) {
|
if (i % 100 === 0) {
|
||||||
ScriptUtils.erasableLog(`Processing bench ${i}/${r.length} (${Math.round(100 * i / r.length)}%) `)
|
ScriptUtils.erasableLog(`Processing bench ${i}/${openbenches.length} (${Math.round(100 * i / openbenches.length)}%) `)
|
||||||
}
|
}
|
||||||
features.push(await this.createBenchInfo(benchWithUser, tags))
|
features.push(await this.createBenchInfo(benchWithUser, tags))
|
||||||
if (createTest && features.length > 1000) {
|
if (createTest && features.length > 1000) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
writeFileSync(`openbenches_export_josm_${createTest ? "_test" : ""}.geojson`, JSON.stringify({
|
writeFileSync(`openbenches_export_josm_${createTest ? "_test" : ""}.geojson`, JSON.stringify({
|
||||||
type: "FeatureCollection", features,
|
type: "FeatureCollection", features,
|
||||||
}, null, " "), "utf-8")
|
}, null, " "), "utf-8")*/
|
||||||
|
|
||||||
const maproulette = features
|
const maproulette = features
|
||||||
.filter(f => {
|
|
||||||
const openbenchesId = f.properties["openbenches:id"]
|
|
||||||
return !alreadyLinked.has(openbenchesId)
|
|
||||||
})
|
|
||||||
.map(f => {
|
.map(f => {
|
||||||
const properties = {tags: JSON.stringify(f.properties)}
|
const properties = {tags: JSON.stringify(f.properties)}
|
||||||
properties["id"] = "openbenches/"+f.properties["openbenches:id"]
|
properties["id"] = "openbenches/"+f.properties["openbenches:id"]
|
||||||
return {...f, properties}
|
return {...f, properties}
|
||||||
})
|
})
|
||||||
|
console.log("Skipped",skipped,"benches as already linked/imported")
|
||||||
writeFileSync(`openbenches_export_maproulette${createTest ? "_test" : ""}.geojson`, JSON.stringify({
|
writeFileSync(`openbenches_export_maproulette${createTest ? "_test" : ""}.geojson`, JSON.stringify({
|
||||||
type: "FeatureCollection", features: maproulette,
|
type: "FeatureCollection", features: maproulette,
|
||||||
}, null, " "), "utf-8")
|
}, null, " "), "utf-8")
|
||||||
|
|
||||||
if(!createTest){
|
|
||||||
writeFileSync(`openbenches_export_maproulette_first_100.geojson`, JSON.stringify({
|
|
||||||
type: "FeatureCollection", features: maproulette.slice(0, 100),
|
|
||||||
}, null, " "), "utf-8")
|
|
||||||
}
|
|
||||||
|
|
||||||
const openBenches = JSON.parse(readFileSync("openbenches_export_josm_.geojson", "utf-8"))
|
|
||||||
for (const area in areas) {
|
await this.conflate(osmData.features, { type: "FeatureCollection", features }, "_all")
|
||||||
const areaGeo = areas[area]
|
|
||||||
await this.conflate(osmData.features.filter(
|
|
||||||
f => GeoOperations.inside(GeoOperations.centerpointCoordinates(f),
|
|
||||||
areaGeo)
|
|
||||||
), openBenches, "_"+area)
|
|
||||||
}
|
|
||||||
await this.conflate(osmData.features, openBenches, "_all")
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue