f.get() doesn't do the trick. As long as my Python code is running in the scripting plugin, the download occurs correctly but the downloaded data is not arriving somehow. Or some thread is not released. I'm not sure. I created some loops and I see the data coming in, but the loop never terminates.
As soon as I dare to use f.get() the script simply hangs. nothing gets executed after that. All output to my terminal window stalls. 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(' ', ' ').replace('\r', '').replace('\n', ''), None) print dir(f) t = 8 while t: print t, f time.sleep(1) t -= 1 print f while f and not(f.isDone() or f.isCancelled()): # or f.get()): print 'waiting for download to complete' time.sleep(1) ew__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__u nicode__', 'acceptsDocumentationSummary', 'acceptsUrl', 'cancel', 'canceled', 'c lass', 'download', 'downloadedData', 'equals', 'errorObjects', 'failed', 'getCla ss', 'getConfirmationMessage', 'getDownloadedData', 'getErrorObjects', 'getPatte rns', 'getTitle', 'hashCode', 'isCanceled', 'isFailed', 'isSafeForRemotecontrolR equests', 'loadUrl', 'notify', 'notifyAll', 'patterns', 'safeForRemotecontrolReq uests', 'setCanceled', 'setFailed', 'title', 'toString', 'wait'] INFO: GET http://overpass-api.de/api/interpreter?data=(rel%20[ "type"="route"]%20 ["route"~"bus|tram"]%20["ref"="H9"]%20["operator"="De%20Lijn"]%20->.routes;%20.r outes%20<<%20->.route_masters;%20way(r.routes);%20node(w);%20node(around:30.0);% 20way(bn);%20node(w);%20);%20out%20meta; ['__class__', '__copy__', '__deepcopy__', '__delattr__', '__doc__', '__eq__', '_ _getattribute__', '__hash__', '__init__', '__ne__', '__new__', '__reduce__', '__ reduce_ex__', '__repr__', '__setattr__', '__str__', '__unicode__', 'cancel', 'ca ncelled', 'class', 'done', 'equals', 'get', 'getClass', 'hashCode', 'isCancelled ', 'isDone', 'notify', 'notifyAll', 'run', 'toString', 'wait'] 8 java.util.concurrent.FutureTask@505819ca 7 java.util.concurrent.FutureTask@505819ca 6 java.util.concurrent.FutureTask@505819ca INFO: Undefined element 'note' found in input stream. Skipping. INFO: Undefined element 'meta' found in input stream. Skipping. 5 java.util.concurrent.FutureTask@505819ca 4 java.util.concurrent.FutureTask@505819ca 3 java.util.concurrent.FutureTask@505819ca 2 java.util.concurrent.FutureTask@505819ca 1 java.util.concurrent.FutureTask@505819ca java.util.concurrent.FutureTask@505819ca waiting for download to complete waiting for download to complete waiting for download to complete waiting for download to complete waiting for download to complete waiting for download to complete waiting for download to complete waiting for download to complete waiting for download to complete waiting for download to complete waiting for download to complete waiting for download to complete waiting for download to complete ... ad eternum I'll resort to messaging the user that the script performed a download, and that they'll have to run it again so the rest of the script can do its thing. Thanks, Jo 2015-01-17 0:27 GMT+01:00 Jo <winfi...@gmail.com>: > 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 <phaau...@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@openstreetmap.org >> https://lists.openstreetmap.org/listinfo/josm-dev >> > > _______________________________________________ josm-dev mailing list josm-dev@openstreetmap.org https://lists.openstreetmap.org/listinfo/josm-dev