You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.9 KiB
PowerShell
96 lines
2.9 KiB
PowerShell
$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 = '
|
|
<osm-script>
|
|
<query into="_" type="area">
|
|
<has-kv k="name" modv="" v="Öhringen"/>
|
|
</query>
|
|
<query into="_" type="way">
|
|
<has-kv k="name" modv="" v="{0}"/>
|
|
<area-query/>
|
|
</query>
|
|
<union into="_">
|
|
<item from="_" into="_"/>
|
|
<recurse type="way-node"/>
|
|
</union>
|
|
<print e="" from="_" geometry="skeleton" ids="yes" limit="" mode="body" n="" order="id" s="" w=""/>
|
|
</osm-script>' -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 = $pollingStation.Name
|
|
description = $street
|
|
}
|
|
geometry = [PSCustomObject]@{
|
|
type = 'LineString'
|
|
coordinates = $coordinateList
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$output = [PSCustomObject]@{
|
|
type = 'FeatureCollection'
|
|
features = $featureList
|
|
}
|
|
|
|
$output | ConvertTo-Json -Depth 99 | Out-File output.geojson
|