Some checks failed
Build & Deploy / 🔍 Prepare (push) Failing after 4s
Build & Deploy / 🧪 QA (push) Has been skipped
Build & Deploy / 🏗️ Build (push) Has been skipped
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 2s
65 lines
3.1 KiB
TypeScript
65 lines
3.1 KiB
TypeScript
import fs from 'fs';
|
|
|
|
const newLocations = [
|
|
{ raw: 'NS-Verkabelung, Klein Gastrose, 03172 Schenkendöbern', zip: '03172', type: 'power', city: 'Schenkendöbern' },
|
|
{ raw: 'MS-Verkabelung, Auras-Cottbus, 03051 Cottbus', zip: '03051', type: 'power', city: 'Cottbus' },
|
|
{ raw: 'MS-Verkabelung, 15848 Rietz-Neuendorf', zip: '15848', type: 'power', city: 'Rietz-Neuendorf' },
|
|
{ raw: 'NS-Verkabelung, 15910 Schlepzig', zip: '15910', type: 'power', city: 'Schlepzig' },
|
|
{ raw: 'MS-Verkabelung, 15306 Falkenhagen Mark', zip: '15306', type: 'power', city: 'Falkenhagen Mark' },
|
|
{ raw: 'MS-Verkabelung, 15898 Neuzelle', zip: '15898', type: 'power', city: 'Neuzelle' },
|
|
{ raw: 'MS-Verkabelung, 15890 Eisenhüttenstadt OT Diehlo', zip: '15890', type: 'power', city: 'Eisenhüttenstadt' },
|
|
{ raw: 'MS-Verkabelung, 15848 Karras', zip: '15848', type: 'power', city: 'Karras' },
|
|
{ raw: 'MS-Verkabelung, Gewerbegebiet, 14669 Ketzin', zip: '14669', type: 'power', city: 'Ketzin' },
|
|
{ raw: 'MS-Verkabelung, 15868 Lieberose', zip: '15868', type: 'power', city: 'Lieberose' },
|
|
{ raw: 'MS-Verkabelung, 15344 Strausberg', zip: '15344', type: 'power', city: 'Strausberg' },
|
|
{ raw: 'MS-Verkabelung, 15366 Neuenhagen', zip: '15366', type: 'power', city: 'Neuenhagen' },
|
|
{ raw: 'MS-Verkabelung, 15868 Jamlitz', zip: '15868', type: 'power', city: 'Jamlitz' },
|
|
{ raw: 'MS-Verkabelung, 03096 Burg (Spreewald)', zip: '03096', type: 'power', city: 'Burg' },
|
|
{ raw: 'MS-Verkabelung, 03130 Bohsdorf', zip: '03130', type: 'power', city: 'Bohsdorf' },
|
|
{ raw: 'Windpark, 29575 Altenmedingen', zip: '29575', type: 'wind', city: 'Altenmedingen' }
|
|
];
|
|
|
|
async function geocode() {
|
|
let output = '';
|
|
for (const item of newLocations) {
|
|
try {
|
|
const res = await fetch(`https://nominatim.openstreetmap.org/search?postalcode=${item.zip}&country=Germany&format=json`, {
|
|
headers: {
|
|
'User-Agent': 'E-TIB Internal Script / info@mintel.com'
|
|
}
|
|
});
|
|
const data = await res.json();
|
|
if (data && data.length > 0) {
|
|
// slightly jitter the coordinates to prevent perfect overlap if there are duplicates
|
|
const jitterLat = (Math.random() - 0.5) * 0.01;
|
|
const jitterLon = (Math.random() - 0.5) * 0.01;
|
|
const lat = parseFloat(data[0].lat) + jitterLat;
|
|
const lon = parseFloat(data[0].lon) + jitterLon;
|
|
const x = (lon - 4.64) * 8.395;
|
|
const y = (55.215 - lat) * 12.589;
|
|
|
|
const id = item.city.toLowerCase().replace(/[^a-z0-9]/g, '-') + '-' + item.zip;
|
|
|
|
output += ` {\n`;
|
|
output += ` id: '${id}',\n`;
|
|
output += ` name: '${item.raw}',\n`;
|
|
output += ` type: 'minor_node',\n`;
|
|
output += ` x: ${x.toFixed(2)},\n`;
|
|
output += ` y: ${y.toFixed(2)},\n`;
|
|
output += ` description: '${item.type}',\n`;
|
|
output += ` },\n`;
|
|
} else {
|
|
console.log(`// Could not geocode ${item.zip}`);
|
|
}
|
|
} catch(e) {
|
|
console.log(`// Error geocoding ${item.zip}`);
|
|
}
|
|
// wait 1 second to respect nominatim rate limits
|
|
await new Promise(r => setTimeout(r, 1000));
|
|
}
|
|
|
|
console.log(output);
|
|
}
|
|
|
|
geocode();
|