[josm-dev] How to use DownloadTask in Python/Jython
Jo
winfixit at gmail.com
Fri Jan 16 23:27:22 UTC 2015
Hi Paul,
Many thanks for your help. f.get() makes the script hang forever. When I
don't add it the download works correctly. At least, once I cleaned up the
Overpass Query.
This is where I am now (# means comment and shows all the other stuff I
tried).
At the moment the query runs and the download is performed, but I'll have
to abort the script there, (and have the user restart it), as I can't find
a way to make it wait for the download to complete.
The other problem is that I don't see how to restrict it to the bbox I
zoomed in upon. So the script downloads all the routes with that same ref
all over the region, for the operator in question.
for relation in selectedRelations:
for member in relation.getMembers():
if member.isNode():
n = member.getNode()
haltNodes.append(n)
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()
print dir(dt)
f = dt.loadUrl(False, 'http://overpass-api.de/api/interpreter?data='
+ overpassQuery.replace(' ', ' ').replace(' ', ' ').replace(' ', '
').replace(' ', ' ').replace('\r', '').replace('\n', ''), None)
# mv.getVisibleRect().getBounds(),
# print dir(dt)
# print dir(relation)
# bboxCalculator = BoundingXYVisitor()
# bboxCalculator.computeBoundingBox(haltNodes)
# print dir(bboxCalculator)
# print bboxCalculator
# print dir(mv)
# print dir(mv.getVisibleRect().getBounds())
# print dir(mv.getVisibleRect().getMinX())
# print dir(mv.getVisibleRect().getMinY())
# print dir(mv.getVisibleRect().getMaxX())
# print dir(mv.getVisibleRect().getMaxY())
# dt.download(False,
Bounds(mv.getVisibleRect().getMinX(),mv.getVisibleRect().getMinY(),mv.getVisibleRect().getMaxX(),mv.getVisibleRect().getMaxY(),),
None)
# print dt.isFailed()
# dt.getDownloadedData()
print dir(f)
# time.sleep(20)
2015-01-16 15:00 GMT+01:00 Paul Hartmann <phaaurlt at gmail.com>:
> On 16.01.2015 14:23, Jo wrote:
>
>> 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:
>>
>> [...]
>>
>> dt = DownloadOsmTask()
>> dt.loadUrl(False, 'http://overpass-api.de/api/interpreter?data='
>> +
>> overpassQuery, None)
>> dt.realRun()
>>
>>
> loadUrl returns a Future object. You can call the get() method on that
> object, to wait for the download to finish (it is done in a background
> thread):
>
> f = dt.loadUrl(...)
> f.get()
>
> Also you don't call dt.realRun() directly, the method loadUrl should
> already do this.
>
> Paul
>
>
> _______________________________________________
> josm-dev mailing list
> josm-dev at openstreetmap.org
> https://lists.openstreetmap.org/listinfo/josm-dev
>
More information about the josm-dev
mailing list