From d2b4a5b0ff1a332a75f4d6c485cc996e680d3d3d Mon Sep 17 00:00:00 2001 From: lub Date: Sat, 13 Jan 2024 15:56:52 +0100 Subject: [PATCH] add alternative approach via streets --- streets.ps1 | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 streets.ps1 diff --git a/streets.ps1 b/streets.ps1 new file mode 100644 index 0000000..b2dd8cd --- /dev/null +++ b/streets.ps1 @@ -0,0 +1,95 @@ +$partyMapping = @{ + ARD = 'Blue' + ZDF = 'Orange' + 'C&A' = 'Red' +} + +# nested array instead of hashtable, because hashtable keys are case-insensitive +$replacementList = @( + ,('strasse','straße') + ,('Strasse','Straße') + ,('Albrecht-von-Bernegger-S','Albrecht-von-Bernegger-Straße') + ,('Geschwister-Scholl-Str.','Geschwister-Scholl-Straße') + ,('Albert-Schweitzer-Str.','Albert-Schweitzer-Straße') + ,('Freiherr-V-Stein-Str','Freiherr-vom-Stein-Straße') + ,('Nussbaumweg','Nußbaumweg') + ,('Elstarweg ','Elstarweg') +) + +$featureList = Import-Csv ./data.csv +| Sort-Object -Unique Strassenname +| Group-Object Wahllokal1 +| ForEach-Object { + $pollingStation = $_ + + $party = ('ARD','ZDF','C&A' | Get-Random) + + $pollingStation.Group | ForEach-Object { + $street = $_.Strassenname + foreach ($replacement in $replacementList) { + $street = $street.Replace($replacement[0], $replacement[1]) + } + + $query = ' + + + + + + + + + + + + + +' -f $street + + $overpassSplat = @{ + Method = 'Post' + Uri = 'https://overpass-api.de/api/interpreter' + Body = $query + } + $overpassResult = Invoke-RestMethod @overpassSplat + + if (!$overpassResult.osm.way.nd) { + Write-Error ('way "{0}" for polling station "{1}" probably not found' -f $street,$pollingStation.name) + return + } + + $overpassResult.osm.way | ForEach-Object { + $coordinateList = $_.nd.ref | ForEach-Object { + $overpassResult.osm.node + | Where-Object id -eq $_ + | ForEach-Object{ + ,($_.lon,$_.lat) + } + } + + [PSCustomObject]@{ + type = 'Feature' + properties = [PSCustomObject]@{ + _umap_options = [PSCustomObject]@{ + #color = ($using:partyMapping).$party + color = $partyMapping.$party + weight = 10 + } + name = $street + description = $pollingStation.Name + } + geometry = [PSCustomObject]@{ + type = 'LineString' + coordinates = $coordinateList + } + } + } + } +} + +$output = [PSCustomObject]@{ + type = 'FeatureCollection' + features = $featureList +} + +$output | ConvertTo-Json -Depth 99 | Out-File output.geojson