mirror of
https://forge.chapril.org/tykayn/libre-charge-map
synced 2025-10-04 17:04:53 +02:00
add script find bad stations
This commit is contained in:
parent
db76768bd9
commit
a1677fff21
6 changed files with 668 additions and 3 deletions
71
find_bad_stations.js
Normal file
71
find_bad_stations.js
Normal file
|
@ -0,0 +1,71 @@
|
|||
import fetch from 'node-fetch';
|
||||
import fs from 'fs';
|
||||
|
||||
const overpassUrl = 'https://overpass-api.de/api/interpreter';
|
||||
const query = `[out:json][timeout:180];
|
||||
(
|
||||
node["amenity"="charging_station"];
|
||||
way["amenity"="charging_station"];
|
||||
relation["amenity"="charging_station"];
|
||||
);
|
||||
out body tags center;`;
|
||||
|
||||
function hasTrueFalseTag(tags) {
|
||||
return Object.values(tags).some(v => v === 'true' || v === 'false');
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('Envoi de la requête Overpass...');
|
||||
const response = await fetch(overpassUrl, {
|
||||
method: 'POST',
|
||||
body: `data=${encodeURIComponent(query)}`,
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Erreur Overpass: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
const features = [];
|
||||
|
||||
for (const el of data.elements) {
|
||||
const tags = el.tags || {};
|
||||
if (!hasTrueFalseTag(tags)) continue;
|
||||
|
||||
let coords;
|
||||
if (el.type === 'node') {
|
||||
coords = [el.lon, el.lat];
|
||||
} else if ((el.type === 'way' || el.type === 'relation') && el.center) {
|
||||
coords = [el.center.lon, el.center.lat];
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
features.push({
|
||||
type: 'Feature',
|
||||
geometry: {
|
||||
type: 'Point',
|
||||
coordinates: coords
|
||||
},
|
||||
properties: {
|
||||
id: el.id,
|
||||
type: el.type,
|
||||
tags: tags
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const geojsonObj = {
|
||||
type: 'FeatureCollection',
|
||||
features: features
|
||||
};
|
||||
|
||||
fs.writeFileSync('charging_stations_true_false.geojson', JSON.stringify(geojsonObj, null, 2), 'utf8');
|
||||
console.log(`Fichier GeoJSON écrit avec ${features.length} objets.`);
|
||||
}
|
||||
|
||||
main().catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue