|
|
|
@ -4,12 +4,58 @@ param (
|
|
|
|
|
$DataSource = './Gesamtergebnis-Gemeinderatswahl-2019_stripped.csv'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
function Get-OverpassStreet {
|
|
|
|
|
param (
|
|
|
|
|
[string]
|
|
|
|
|
$Name
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if (!$cache.$Name) {
|
|
|
|
|
$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 $Name
|
|
|
|
|
|
|
|
|
|
$overpassSplat = @{
|
|
|
|
|
Method = 'Post'
|
|
|
|
|
Uri = 'https://overpass-api.de/api/interpreter'
|
|
|
|
|
Body = $query
|
|
|
|
|
}
|
|
|
|
|
$cache.$Name = Invoke-RestMethod @overpassSplat
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$cache.$Name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Test-Path ./cache.xml) {
|
|
|
|
|
$cache = Import-Clixml ./cache.xml
|
|
|
|
|
} else {
|
|
|
|
|
$cache = @{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$data = Import-Csv $DataSource
|
|
|
|
|
|
|
|
|
|
$greenParty = ($data[0].PSObject.Properties.Name -like '*Grüne*')[0]
|
|
|
|
|
|
|
|
|
|
$partyMapping = $data | Where-Object Description -eq 'Color'
|
|
|
|
|
$dataMeasure = $data.$greenParty
|
|
|
|
|
| Where-Object {$_ -match '%$'}
|
|
|
|
|
| ForEach-Object {$_ -replace '%$'}
|
|
|
|
|
| Measure-Object -Minimum -Maximum
|
|
|
|
|
$minimumResultValue = $dataMeasure.Minimum
|
|
|
|
|
$maximumResultValue = $dataMeasure.Maximum
|
|
|
|
|
|
|
|
|
|
# nested array instead of hashtable, because hashtable keys are case-insensitive
|
|
|
|
|
$replacementList = @(
|
|
|
|
@ -47,27 +93,21 @@ $featureList = Import-Csv ./polling_stations.csv
|
|
|
|
|
$_.Formatted + "`t" + $_.Party
|
|
|
|
|
}) -join "`n"
|
|
|
|
|
|
|
|
|
|
$greenResult = ($electionResultArray | Where-Object Party -eq $greenParty).ResultValue
|
|
|
|
|
$greenResultValue = ($electionResultArray | Where-Object Party -eq $greenParty).ResultValue
|
|
|
|
|
|
|
|
|
|
$opacity = ($greenResult - 20) / 5 * 0.6 + 0.4
|
|
|
|
|
$opacity = $opacity -gt 1.0 ? 1.0 : $opacity
|
|
|
|
|
$opacity = $opacity -lt 0.4 ? 0.4 : $opacity
|
|
|
|
|
$colorGreen = (($greenResultValue - $minimumResultValue) * (100 - 220)) / ($maximumResultValue - $minimumResultValue) + 220
|
|
|
|
|
$color = "rgb(0, $colorGreen, 0)"
|
|
|
|
|
|
|
|
|
|
$weight = ($greenResult - 20) / 5 * 10 + 5
|
|
|
|
|
$weight = $weight -gt 15 ? 15 : $weight
|
|
|
|
|
$weight = $weight -lt 5 ? 5 : $weight
|
|
|
|
|
|
|
|
|
|
$party = $electionResultArray[0].Party
|
|
|
|
|
$opacity = (($greenResultValue - $minimumResultValue) * (1.0 - 0.4)) / ($maximumResultValue - $minimumResultValue) + 0.4
|
|
|
|
|
} else {
|
|
|
|
|
$electionResultString = 'no data available'
|
|
|
|
|
$opacity = 0.5
|
|
|
|
|
$party = $null
|
|
|
|
|
$color = '#ff00ff'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$umapOptiones = [PSCustomObject]@{
|
|
|
|
|
#color = ($using:partyMapping).$party
|
|
|
|
|
color = $partyMapping.$party ?? '#ff00ff'
|
|
|
|
|
weight = $weight
|
|
|
|
|
color = $color
|
|
|
|
|
weight = 10
|
|
|
|
|
opacity = $opacity
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -81,29 +121,7 @@ $featureList = Import-Csv ./polling_stations.csv
|
|
|
|
|
$description += "`n`n"
|
|
|
|
|
$description += $electionResultString
|
|
|
|
|
|
|
|
|
|
$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
|
|
|
|
|
$overpassResult = Get-OverpassStreet -Name $street
|
|
|
|
|
|
|
|
|
|
if (!$overpassResult.osm.way.nd) {
|
|
|
|
|
Write-Error ('way "{0}" for polling station "{1}" probably not found' -f $street,$pollingStation.name)
|
|
|
|
@ -141,3 +159,5 @@ $output = [PSCustomObject]@{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$output | ConvertTo-Json -Depth 99 | Out-File output.geojson
|
|
|
|
|
|
|
|
|
|
$cache | Export-Clixml ./cache.xml
|
|
|
|
|