forked from MapComplete/MapComplete
Add module to fetch data (via a proxy) from the website with jsonld
This commit is contained in:
parent
1b06eee15b
commit
352414b29d
17 changed files with 388 additions and 351 deletions
|
@ -1,39 +1,42 @@
|
|||
import Script from "../Script"
|
||||
import { Utils } from "../../src/Utils"
|
||||
import VeloparkLoader, { VeloparkData } from "../../src/Logic/Web/VeloparkLoader"
|
||||
import fs from "fs"
|
||||
import { Overpass } from "../../src/Logic/Osm/Overpass"
|
||||
import { RegexTag } from "../../src/Logic/Tags/RegexTag"
|
||||
import Constants from "../../src/Models/Constants"
|
||||
import { ImmutableStore } from "../../src/Logic/UIEventSource"
|
||||
import { BBox } from "../../src/Logic/BBox"
|
||||
import LinkedDataLoader from "../../src/Logic/Web/LinkedDataLoader"
|
||||
|
||||
class VeloParkToGeojson extends Script {
|
||||
constructor() {
|
||||
super(
|
||||
"Downloads the latest Velopark data and converts it to a geojson, which will be saved at the current directory"
|
||||
"Downloads the latest Velopark data and converts it to a geojson, which will be saved at the current directory",
|
||||
)
|
||||
}
|
||||
|
||||
exportTo(filename: string, features) {
|
||||
fs.writeFileSync(
|
||||
filename + "_" + new Date().toISOString() + ".geojson",
|
||||
features = features.slice(0,25) // TODO REMOVE
|
||||
const file = filename + "_" + /*new Date().toISOString() + */".geojson"
|
||||
fs.writeFileSync(file,
|
||||
JSON.stringify(
|
||||
{
|
||||
type: "FeatureCollection",
|
||||
"#":"Only 25 features are shown!", // TODO REMOVE
|
||||
features,
|
||||
},
|
||||
null,
|
||||
" "
|
||||
)
|
||||
" ",
|
||||
),
|
||||
)
|
||||
console.log("Written",file)
|
||||
}
|
||||
|
||||
async main(args: string[]): Promise<void> {
|
||||
console.log("Downloading velopark data")
|
||||
// Download data for NIS-code 1000. 1000 means: all of belgium
|
||||
const url = "https://www.velopark.be/api/parkings/1000"
|
||||
const data = <VeloparkData[]>await Utils.downloadJson(url)
|
||||
const allVelopark = await LinkedDataLoader.fetchJsonLd(url, { country: "be" })
|
||||
this.exportTo("velopark_all", allVelopark)
|
||||
|
||||
const bboxBelgium = new BBox([
|
||||
[2.51357303225, 49.5294835476],
|
||||
|
@ -44,15 +47,13 @@ class VeloParkToGeojson extends Script {
|
|||
[],
|
||||
Constants.defaultOverpassUrls[0],
|
||||
new ImmutableStore(60 * 5),
|
||||
false
|
||||
false,
|
||||
)
|
||||
const alreadyLinkedFeatures = await alreadyLinkedQuery.queryGeoJson(bboxBelgium)
|
||||
const seenIds = new Set<string>(
|
||||
alreadyLinkedFeatures[0].features.map((f) => f.properties["ref:velopark"])
|
||||
alreadyLinkedFeatures[0].features.map((f) => f.properties["ref:velopark"]),
|
||||
)
|
||||
console.log("OpenStreetMap contains", seenIds.size, "bicycle parkings with a velopark ref")
|
||||
const allVelopark = data.map((f) => VeloparkLoader.convert(f))
|
||||
this.exportTo("velopark_all", allVelopark)
|
||||
|
||||
const features = allVelopark.filter((f) => !seenIds.has(f.properties["ref:velopark"]))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue