[josm-dev] How to use DownloadTask in Python/Jython
Jo
winfixit at gmail.com
Fri Jan 16 13:23:46 UTC 2015
Hi guys,
Unfortunately I'm not smart enough to code in Java, so I use Python in the
scripting plugin, which gets me quite far, but now I'm stuck:
import
org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask as
DownloadRelationMemberTask
import org.openstreetmap.josm.actions.DownloadReferrersAction as
DownloadReferrersAction
import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask as
DownloadOsmTask
import org.openstreetmap.josm.actions.search.SearchAction as SearchAction
import re, time
selectedRelations = mv.editLayer.data.getSelectedRelations()
if not(selectedRelations):
'''This script can be run with some PT route relations selected
In case it wasn't we'll use the newly added relations with fresh
information about stops of De lijn or TEC.
But we need to find the possibly already present route
relations.'''
SearchAction.search('type:relation type=route
tttttt',SearchAction.SearchMode.fromCode('R'))
selectedRelations = mv.editLayer.data.getSelectedRelations()
for relation in selectedRelations:
DownloadRelationMemberTask.run(DownloadRelationMemberTask(relation,
relation.getIncompleteMembers(), mv.editLayer ))
AutoScaleAction.zoomToSelection()
route_master = relation.getReferrers()[0]
ref = route_master.get('ref')
operator = route_master.get('operator')
# time.sleep(3)
overpassQuery = '''(rel
["type"="route"]
["route"~"bus|tram"]
["ref"="''' + ref + '''"]
["operator"="''' + operator + '''"]
->.routes;
.routes << ->.route_masters;
way(r.routes);
node(w);
node(around:30.0);
way(bn);
node(w);
);
out meta;'''
dt = DownloadOsmTask()
dt.loadUrl(False, 'http://overpass-api.de/api/interpreter?data=' +
overpassQuery, None)
dt.realRun()
I prepared data files with route and route_master relations. The bus stop
nodes are not included, so the
DownloadRelationMemberTask.run(DownloadRelationMemberTask(relation,
relation.getIncompleteMembers(), mv.editLayer )) fetches those.
Then I want to download existing route relations with the same refs in the
bounding box defined by the nodes from the template route relations using
an Overpass query.
The script then proceeds to comparing the template routes with routes
already present in OSM. I got that part covered. I'd like to make life as
easy as possible for fellow contributors who may want to work on adding PT
route relations.
Jo
More information about the josm-dev
mailing list