Author Posts

August 24, 2018 at 3:23 pm

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.

 

August 24, 2018 at 5:34 pm

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.

August 24, 2018 at 5:43 pm

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

August 24, 2018 at 6:32 pm

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 = 'http://www.overpass-api.de/api/xapi?node[bbox= {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.

August 24, 2018 at 6:48 pm

Thanks very much for hint

August 26, 2018 at 9:27 am

You have got your answer here