majd
August 24, 2018, 9:53am
1
I Wrote this Code and i wanted use it with Parameter:
Param( [double]$MinLon, [double]$MinLat, [double]$MaxLon, [double]$MaxLat)
$url = ‘http://www.overpass-api.de/api/xapi?node[bbox=$MinLon,$MinLat,$MaxLon,$MaxLat][natural=tree][@meta] ’
$output = “C:\Users\alo\Desktop\Muenchen.osm”
Invoke-WebRequest -Uri $url -OutFile $Output
Then in Powre Shell i wrote : .\Muenchen.ps1 -$MinLon 5.97 -$MinLat 50.66 -$MaxLon 6.21 -$MaxLat 50.85
but it didn’t work well.
Can any give me one please tips.
Thank you alot.
You parameter usage during calling the script is wrong.
.\Muenchen.ps1 -MinLon 5.97 -MinLat 50.66 -MaxLon 6.21 -MaxLat 50.85
I suggest you to get some pure basics by reading the help docs and videos on PowerShell scripting .
A well recommended book is this book by Don Jones.
Note: And always use code posting tags while posting code in the forum.
There is no .osm script type in PS.
I assume you meant .psm1, but even then that is a module specification that a script calls. So, this should be .ps1 as you have in your final line.
As for this…
$url = 'http://www.overpass-api.de/api/xapi?node[bbox=$MinLon,$MinLat,$MaxLon,$MaxLat][natural=tree][@meta]'
That is just a explicit sting, and those variable will not expand the value. You use double quotes for expand variable content.
As for this…
.\Muenchen.ps1 -$MinLon 5.97 -$MinLat 50.66 -$MaxLon 6.21 -$MaxLat
… this is not how you’d specify the params, you just use the name, not the variable $name.
So, this…
Function New-Muenchen
{
Param
(
[double]$MinLon,
[double]$MinLat,
[double]$MaxLon,
[double]$MaxLat
)
$url = "http://www.overpass-api.de/api/xapi?node[bbox=$MinLon,$MinLat,$MaxLon,$MaxLat][natural=tree][@meta]"
$output = "C:\Users\alo\Desktop\Muenchen.ps1"
Invoke-WebRequest -Uri $url -OutFile $Output
}
New-Muenchen -MinLon 5.97 -MinLat 50.66 -MaxLon 6.21 -MaxLat 50.85
majd
August 24, 2018, 1:02pm
4
Thanks for you answer. I maybe describes my problem not so good.
I wrote this Code and
$minLon = Read-Host "Pleas enter minLon"$minLat = Read-Host "Pleas enter minLat"$maxLon = Read-Host "Pleas enter maxLon"$maxLat = Read-Host "Pleas enter maxLat"$url = '<a href="https://slack-redir.net/link?url=http%3A%2F%2Fwww.overpass-api.de%2Fapi%2Fxapi%3Fnode%5Bbbox%3D&v=3" target="_blank" rel="noopener noreferrer">http://www.overpass-api.de/api/xapi?node[bbox=</a> {0},{1},{2},{3}][natural=tree][@meta]' -f $minLon,$minLat,$maxLon,$maxLat$output = "C:\Users\alo\Desktop\Treese.osm"$start_time = Get-DateInvoke-WebRequest -Uri $url -OutFile $outputWrite-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"
and it works very good but i want modify it so i can enter coordinaten(minLon,minLat,maxLon,maxLat) by invoke script in one line i mean.
majd
August 24, 2018, 1:18pm
5
Thanks very much for hint
You have got your answer here