3

I am writing a QGIS processing algorithm that reads rows including addresses from a CSV file. The addresses are geocoded one by one via external REST API and then a vector layer containing the point features corresponding each row is created. The layer is saved to a file and possibly also opened in the QGIS.

I am using QGIS 3.0 but if someone knows how this should be handled in QGIS 2.x that would also be helpful. I am planning to use the PyQt5.QtNetwork module for the REST API calls.

Is it possible to do the REST API calls asynchronously and when they all have finished then finish the processing algorithm?

If not, what is the proper way to handle this kind of process?

  • In python 3 use concurrent.futures, for python 2 use the backported futures (needs to be installed via pip/conda). – user2856 Mar 25 '18 at 7:36
  • @luke Thank you for the suggestion. I decided to not to make asynchronous REST API calls but instead to use urllib to make the API calls that works fine for my needs. – Orienteerix Mar 25 '18 at 8:37
  • You can use urllib (or even better, the requests package) with concurrent.futures. I assume that the REST calls would be the bottleneck in your code so makes sense to run them asynchronously. – user2856 Mar 25 '18 at 9:03
  • See also pypi.python.org/pypi/requests-futures – user2856 Mar 27 '18 at 0:46
  • Thank you @luke. I actually think it is not good idea to do a lot of REST calls to the same server at the same time as it will consume server resources and could even be considered DOS attack. But I agree with you that there are situations where asynchronous processing algorithms and also the futures and requests libraries with them would be useful. – Orienteerix Mar 27 '18 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.