implement a cache

so we don't hammer the overpass API as much
main
lub 10 months ago
parent 903ab73788
commit 3d4e9ced0e

@ -4,6 +4,47 @@ 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
@ -81,29 +122,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 +160,5 @@ $output = [PSCustomObject]@{
}
$output | ConvertTo-Json -Depth 99 | Out-File output.geojson
$cache | Export-Clixml ./cache.xml

Loading…
Cancel
Save