Changes between Version 16 and Version 18 of Help/Plugin/Scripting/Python


Ignore:
Timestamp:
(multiple changes)
Author:
(multiple changes)
Comment:
(multiple changes)

Legend:

Unmodified
Added
Removed
Modified
  • Help/Plugin/Scripting/Python

    v16 v18  
    11[[TranslatedPages]]
    22
     3= Plugin -> Scripting -> Python =
     4== Purpose ==
    35Some more examples in Python:
    46
     7[[PageOutline(2,Table of Contents)]]
     8
     9
     10== Convert a way that connects to an unsplit roundabout to a fork ==
    511Convert a way that connects to a roundabout to a fork consisting of 2 oneway ways. Splitting the way on its last node and attaching to the 2 nodes adjacent to the common node of the roundabout way. This version only works on unsplit roundabouts. See the next example for an updated version.
    612
     
    1824
    1925    if not(selected_ways) or len(selected_ways)>1:
    20         JOptionPane.showMessageDialog(MainApplication.parent,
     26        JOptionPane.showMessageDialog(MainApplication.getMainFrame(),
    2127                                         "Please select a single way that connects to a roundabout")
    2228    else:
    2329        for way in selected_ways:
    2430            if way.get('oneway') in ['yes', '-1']:
    25                 JOptionPane.showMessageDialog(MainApplication.parent, "This way has oneway tag set")
     31                JOptionPane.showMessageDialog(MainApplication.getMainFrame(), "This way has oneway tag set")
    2632            else:
    2733                node_before = None
     
    6773                            adjacent_node_to_split_on = way.getNodes()[-1]
    6874                if not(common_node) or common_node_becomes_node_before==None:
    69                     JOptionPane.showMessageDialog(MainApplication.parent,
     75                    JOptionPane.showMessageDialog(MainApplication.getMainFrame(),
    7076                                               "Please select a way that connects to a roundabout")
    7177                else:
     
    114120
    115121
     122== Convert a way that connects to a split roundabout to a fork ==
    116123This script does the same as the previous one, but it also works on roundabouts where the ways are split. It's not taking care of the relations.
    117124
     
    130137
    131138    if not(selected_ways) or len(selected_ways)>1:
    132         JOptionPane.showMessageDialog(MainApplication.parent, "Please select a single way that connects to a roundabout")
     139        JOptionPane.showMessageDialog(MainApplication.getMainFrame(), "Please select a single way that connects to a roundabout")
    133140    else:
    134141        for way in selected_ways:
    135142            if way.get('oneway') in ['yes', '-1']:
    136                 JOptionPane.showMessageDialog(MainApplication.parent, "This way has oneway tag set")
     143                JOptionPane.showMessageDialog(MainApplication.getMainFrame(), "This way has oneway tag set")
    137144            elif way.get('junction') in ['roundabout']:
    138                 JOptionPane.showMessageDialog(MainApplication.parent, "This way is part of a roundabout")
     145                JOptionPane.showMessageDialog(MainApplication.getMainFrame(), "This way is part of a roundabout")
    139146            else:
    140147                node_before = None
     
    206213
    207214                if not(common_node) or ((parentway.isClosed() and common_node_becomes_node_before==None)):
    208                     JOptionPane.showMessageDialog(MainApplication.parent, "Please select a way that connects to a roundabout")
     215                    JOptionPane.showMessageDialog(MainApplication.getMainFrame(), "Please select a way that connects to a roundabout")
    209216                else:
    210217                    commandsList = []
     
    270277
    271278
     279== Export a collection of routes to Garmin GPX file ==
    272280Export a collection of routes to Garmin GPX file (not a super example, as I don't think we do collection relations anymore):
    273281
     
    279287
    280288The GPL v3 is accessible here:
    281 http://www.gnu.org/licenses/gpl.html
     289https://www.gnu.org/licenses/gpl.html
    282290
    283291It comes with no warranty whatsoever.
     
    295303f = open('C:/export.gpx', 'w')
    296304f.write('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n')
    297 f.write('<gpx xmlns="http://www.topografix.com/GPX/1/1" creator="OSM Route Manager" version="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">\n')
    298 f.write('<!-- All data by OpenStreetMap, licensed under cc-by-sa-2.0 (http://creativecommons.org/licenses/by-sa/2.0/). -->\n')
     305f.write('<gpx xmlns="https://www.topografix.com/GPX/1/1" creator="OSM Route Manager" version="1.1" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://www.topografix.com/GPX/1/1 https://www.topografix.com/GPX/1/1/gpx.xsd">\n')
     306f.write('<!-- All data by OpenStreetMap, licensed under cc-by-sa-2.0 (https://creativecommons.org/licenses/by-sa/2.0/). -->\n')
    299307
    300308editLayer = Main.getLayerManager().getEditLayer()
     
    351359
    352360
    353 Download missing parent elements for the selected element:
    354 
     361== Download missing parent elements for the selected element ==
    355362
    356363{{{#!python
     
    362369
    363370The GPL v3 is accessible here:
    364 http://www.gnu.org/licenses/gpl.html
     371https://www.gnu.org/licenses/gpl.html
    365372
    366373The GPL v2 is accessible here:
    367 http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
     374https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    368375
    369376It comes with no warranty whatsoever.
     
    388395
    389396
    390 Download missing relation members:
     397== Download missing relation members ==
    391398
    392399{{{
     
    398405
    399406The GPL v3 is accessible here:
    400 http://www.gnu.org/licenses/gpl.html
     407https://www.gnu.org/licenses/gpl.html
    401408
    402409The GPL v2 is accessible here:
    403 http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
     410https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    404411
    405412It comes with no warranty whatsoever.
     
    434441
    435442
    436 Validate an rcn route relation:
    437 
     443== Validate an rcn route relation ==
    438444
    439445{{{
     
    446452
    447453The GPL v3 is accessible here:
    448 http://www.gnu.org/licenses/gpl.html
     454https://www.gnu.org/licenses/gpl.html
    449455
    450456The GPL v2 is accessible here:
    451 http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
     457https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    452458
    453459It comes with no warranty whatsoever.
     
    634640}}}
    635641
    636 [wiki:Python/RCN_Route_Validator]
    637 
     642[wiki:/Help/Plugin/Scripting/Python/RCN_Route_Validator]
     643
     644
     645== Remove extra ways resulting from Potlatch operations ==
    638646Remove extra ways resulting from Potlatch way split operations under turn restriction relations
    639647
     
    648656
    649657The GPL v3 is accessible here:
    650 http://www.gnu.org/licenses/gpl.html
     658https://www.gnu.org/licenses/gpl.html
    651659
    652660It comes with no warranty whatsoever.
     
    730738    """
    731739    if (way.isOneway() != 0 and reverse):
    732         return node == way.lastNode(True), way.firstNode(True) # True: auto process case whan isOneway == -1
     740        return node == way.lastNode(True), way.firstNode(True) # True: auto process case when isOneway == -1
    733741    if (way.isOneway() != 0):     # not reverse
    734742        return node == way.firstNode(True), way.lastNode(True)
     
    843851        commandsList=[]
    844852}}}
     853
     854
     855----
     856Back to [wikitr:/Help/Plugin/Scripting Plugin Scripting] \\
     857Back to [wikitr:/Plugins Plugin Help] \\
     858Back to [wikitr:/Help Main Help]