Changes between Version 12 and Version 13 of Help/Plugin/Scripting/Python
- Timestamp:
- 2017-10-09T17:56:51+02:00 (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Help/Plugin/Scripting/Python
v12 v13 3 3 Some more examples in Python: 4 4 5 Export a collection of routes to Garmin GPX file :5 Export a collection of routes to Garmin GPX file (not a super example, as I don't think we do collection relations anymore): 6 6 7 7 … … 10 10 ''' 11 11 RWN2Garmin.py - Numbered networks to Garmin GPX file converter 12 This code is released under the GNU General 13 Public License v2 or later. 12 This code is released under the GNU General Public License v2 or later. 14 13 15 14 The GPL v3 is accessible here: 16 15 http://www.gnu.org/licenses/gpl.html 17 16 18 The GPL v2 is accessible here:19 http://www.gnu.org/licenses/old-licenses/gpl-2.0.html20 21 17 It 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 26 18 ''' 27 19 from javax.swing import JOptionPane, JDialog … … 35 27 import time 36 28 37 def getMapView():38 if Main.main and Main.main.map:39 return Main.main.map.mapView40 else:41 return None42 43 mv = getMapView()44 29 f = open('C:/export.gpx', 'w') 45 30 f.write('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n') 46 31 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') 47 32 f.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 34 editLayer = Main.getLayerManager().getEditLayer() 35 if editLayer and editLayer.data: 51 36 selectedRelations = mv.editLayer.data.getSelectedRelations() 52 37 … … 54 39 JOptionPane.showMessageDialog(Main.parent, "Please select a collection relation") 55 40 else: 56 # nodetype = Node().getType()57 41 print 58 42 for collection in selectedRelations: … … 389 373 390 374 {{{#!python 391 392 375 #!/bin/jython 393 376 … … 401 384 http://www.gnu.org/licenses/gpl.html 402 385 403 The GPL v2 is accessible here:404 http://www.gnu.org/licenses/old-licenses/gpl-2.0.html405 406 386 It comes with no warranty whatsoever. 407 387 408 388 This 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 409 389 410 Only work for turn restrictions with one via node390 Only works for turn restrictions with one via node 411 391 412 392 e.g. Original : from: Way1, via: Node, to:Way2 … … 435 415 class RestrictionError(Exception): 436 416 pass 437 438 def getMapView():439 if Main.main and Main.main.map:440 return Main.main.map.mapView441 else:442 return None443 417 444 418 def getMembers (restriction): … … 577 551 578 552 validrestrictiontypes = ('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()553 editLayer = Main.getLayerManager().getEditLayer() 554 if editLayer and editLayer.data: 555 selectedRelations = editLayer.data.getSelectedRelations() 582 556 583 557 if not(selectedRelations): … … 588 562 if relation.get('type') == "restriction" and relation.get('restriction') in validrestrictiontypes: 589 563 try: 590 memberlist = getMembers (relation) 591 #print "".join(v * len(memberlist[v]) for v in memberlist.keys()) 564 memberlist = getMembers (relation) 592 565 if (len (memberlist["from"])) > 1 or (len (memberlist["to"])) > 1 : 593 566 # Repair attempt