Changes between Version 12 and Version 13 of Help/Plugin/Scripting/Python


Ignore:
Timestamp:
2017-10-09T17:56:51+02:00 (8 days ago)
Author:
Polyglot
Comment:

removed mapView from the other scripts as well

Legend:

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

    v12 v13  
    33Some more examples in Python:
    44
    5 Export a collection of routes to Garmin GPX file:
     5Export a collection of routes to Garmin GPX file (not a super example, as I don't think we do collection relations anymore):
    66
    77
     
    1010'''
    1111RWN2Garmin.py  - Numbered networks to Garmin GPX file converter
    12 This code is released under the GNU General
    13 Public License v2 or later.
     12This code is released under the GNU General Public License v2 or later.
    1413
    1514The GPL v3 is accessible here:
    1615http://www.gnu.org/licenses/gpl.html
    1716
    18 The GPL v2 is accessible here:
    19 http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    20 
    2117It comes with no warranty whatsoever.
    22 
    23 This code illustrates how to use Jython to:
    24 * work with selected items or how to process all the primitives of a certain kind (node, way, relation)
    25 
    2618'''
    2719from javax.swing import JOptionPane, JDialog
     
    3527import time
    3628
    37 def getMapView():
    38     if Main.main and Main.main.map:
    39         return Main.main.map.mapView
    40     else:
    41         return None
    42 
    43 mv = getMapView()
    4429f = open('C:/export.gpx', 'w')
    4530f.write('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n')
    4631f.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')
    4732f.write('<!-- All data by OpenStreetMap, licensed under cc-by-sa-2.0 (http://creativecommons.org/licenses/by-sa/2.0/). -->\n')
    48 if mv and mv.editLayer and mv.editLayer.data:
    49     #selectedNodes = mv.editLayer.data.getSelectedNodes()
    50     #selectedWays = mv.editLayer.data.getSelectedWays()
     33
     34editLayer = Main.getLayerManager().getEditLayer()
     35if editLayer and editLayer.data:
    5136    selectedRelations = mv.editLayer.data.getSelectedRelations()
    5237
     
    5439        JOptionPane.showMessageDialog(Main.parent, "Please select a collection relation")
    5540    else:
    56         # nodetype = Node().getType()
    5741        print
    5842        for collection in selectedRelations:
     
    389373
    390374{{{#!python
    391 
    392375#!/bin/jython
    393376
     
    401384http://www.gnu.org/licenses/gpl.html
    402385
    403 The GPL v2 is accessible here:
    404 http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    405 
    406386It comes with no warranty whatsoever.
    407387
    408388This code Loops through selected turn restriction relations, trying to remove ways split from originally the same way (with to / from roles) under turn restriction relations which should no longer remain as members of these relations, as a result of a Potlatch issue: https://trac.openstreetmap.org/ticket/3254
    409389
    410 Only work for turn restrictions with one via node
     390Only works for turn restrictions with one via node
    411391
    412392e.g. Original      : from: Way1, via: Node, to:Way2
     
    435415class RestrictionError(Exception):
    436416    pass
    437 
    438 def getMapView():
    439     if Main.main and Main.main.map:
    440         return Main.main.map.mapView
    441     else:
    442         return None
    443417
    444418def getMembers (restriction):
     
    577551   
    578552validrestrictiontypes = ('only_straight_on', 'only_right_turn', 'only_left_turn', 'no_right_turn', 'no_left_turn', 'no_straight_on', 'no_u_turn')
    579 mv = getMapView()
    580 if mv and mv.editLayer and mv.editLayer.data:
    581     selectedRelations = mv.editLayer.data.getSelectedRelations()
     553editLayer = Main.getLayerManager().getEditLayer()
     554if editLayer and editLayer.data:
     555    selectedRelations = editLayer.data.getSelectedRelations()
    582556   
    583557    if not(selectedRelations):
     
    588562            if relation.get('type') == "restriction" and relation.get('restriction') in validrestrictiontypes:
    589563                try:
    590                     memberlist = getMembers (relation)     
    591                     #print "".join(v * len(memberlist[v]) for v in memberlist.keys())           
     564                    memberlist = getMembers (relation)
    592565                    if (len (memberlist["from"])) > 1 or (len (memberlist["to"])) > 1 :
    593566                        # Repair attempt