forked from MapComplete/MapComplete
First draft of loading 'notes'
This commit is contained in:
parent
bafaba7011
commit
ebb510da04
20 changed files with 580 additions and 199 deletions
45
scripts/perProperty.ts
Normal file
45
scripts/perProperty.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
import * as fs from "fs";
|
||||
|
||||
function main(args){
|
||||
if(args.length < 2){
|
||||
console.log("Given a single geojson file, generates the partitions for every found property")
|
||||
console.log("USAGE: perProperty `file.geojson` `property-key`")
|
||||
return
|
||||
}
|
||||
const path = args[0]
|
||||
const key = args[1]
|
||||
|
||||
const data= JSON.parse(fs.readFileSync(path, "UTF8"))
|
||||
const perProperty = new Map<string, any[]>()
|
||||
|
||||
console.log("Partitioning",data.features.length, "features")
|
||||
for (const feature of data.features) {
|
||||
const v = feature.properties[key]
|
||||
if(!perProperty.has(v)){
|
||||
console.log("Found a new category:", v)
|
||||
perProperty.set(v, [])
|
||||
}
|
||||
perProperty.get(v).push(feature)
|
||||
}
|
||||
|
||||
const stripped = path.substr(0, path.length - ".geojson".length)
|
||||
perProperty.forEach((features, v) => {
|
||||
|
||||
fs.writeFileSync(stripped+"."+v.replace(/[^a-zA-Z0-9_]/g, "_")+".geojson",
|
||||
JSON.stringify({
|
||||
type:"FeatureCollection",
|
||||
features
|
||||
}))
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
let args = [...process.argv]
|
||||
args.splice(0, 2)
|
||||
try {
|
||||
main(args)
|
||||
} catch (e) {
|
||||
console.error("Error building cache:", e)
|
||||
}
|
||||
console.log("All done!")
|
Loading…
Add table
Add a link
Reference in a new issue