$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,$_.Wahllokal2,$_.Wahllokal3 -join ' '} | 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