param

This topic contains 5 replies, has 3 voices, and was last updated by

 
Participant
3 months, 3 weeks ago.

  • Author
    Posts
  • #109876

    Participant
    Points: 3
    Rank: Member

    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.

     

  • #109889

    Participant
    Points: 894
    Helping Hand
    Rank: Major Contributor

    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.

    • #109916

      Participant
      Points: 3
      Rank: Member

      Thanks very much for hint

  • #109895

    Participant
    Points: 332
    Helping Hand
    Rank: Contributor

    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
  • #109910

    Participant
    Points: 3
    Rank: Member

    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.

  • #110014

    Participant
    Points: 894
    Helping Hand
    Rank: Major Contributor

    You have got your answer here

The topic ‘param’ is closed to new replies.