Question

Call FME server from QGIS and import the returned data (geopackage)

  • 23 March 2021
  • 5 replies
  • 60 views

Badge +4

Hi All,

Does anyone have any experience and examples for calling FME server from a QGIS processing script? I have published some (data download) workspaces in FME server into workspace apps for my end users within the company. They really like this, but they would prefer not to leave QGIS.

I would like the script to place the zip file returned bij FME server in a folder and unpack it.

Thank you.


5 replies

Userlevel 4
Badge +26

Presumably tha scripting language is Python?

If so then you will need to create a webhook in FME server and get an API token for the job.

​You will then need to use python to build the request Url from the user parameters including the API token.

Once you have the URL sorted then you can fire off the request. The response will include the URL for downloading the zip.

You will then need to use python to download it and extract it.

​This is just the summary of steps. Writing the script will be the real task but this should at least give you a framework to start from.

Hope it helps​

Badge +4

Presumably tha scripting language is Python?

If so then you will need to create a webhook in FME server and get an API token for the job.

​You will then need to use python to build the request Url from the user parameters including the API token.

Once you have the URL sorted then you can fire off the request. The response will include the URL for downloading the zip.

You will then need to use python to download it and extract it.

​This is just the summary of steps. Writing the script will be the real task but this should at least give you a framework to start from.

Hope it helps​

No sorry, this doesn't really help. Id like'to have examples and experiences from people who have actually done this. The steps I could figure out myself. I even made a script that actually works. It calls a fmedatadownload service with some parameters and it returns with a download URL. I managed to download the data and show it in QGIS.

But I have a few problems/questions:

  1. When the workspace is asked for a larger dataset, I get a timeout and no data download URL! How can I prevent this from happening?
  2. I use a data download, but maybe its better to use data streaming?
  3. I use a requests.post, but maybe it needs a get.
  4. How can I upload data, like a shapefile, to FME server from QGIS?
  5. There is a Rest API, but I don't see any examples on how to use this with Python.
Userlevel 4
Badge +26

No sorry, this doesn't really help. Id like'to have examples and experiences from people who have actually done this. The steps I could figure out myself. I even made a script that actually works. It calls a fmedatadownload service with some parameters and it returns with a download URL. I managed to download the data and show it in QGIS.

But I have a few problems/questions:

  1. When the workspace is asked for a larger dataset, I get a timeout and no data download URL! How can I prevent this from happening?
  2. I use a data download, but maybe its better to use data streaming?
  3. I use a requests.post, but maybe it needs a get.
  4. How can I upload data, like a shapefile, to FME server from QGIS?
  5. There is a Rest API, but I don't see any examples on how to use this with Python.

First off, here is a nice litte github repo with how to use Python and FME Server - I think you should find stuff in here for uploading: https://github.com/bcgov/dbc-pylib/blob/master/docs/FMEServer.md

 

And yeah, the timeout is a pain:

 

You might want to consider using: opt_servicemode=async in your request.

 

The problem here is that you will not get a download link in the response. But, you will get the job id. You can then poll the job table every few seconds until the job is successful, in that case the result will include the download link. Not ideal, but should work.

 

DataStreaming can still timeout so not the best solution, I don't think. Stick with datadownload if you can't just write directly to the output.

 

 

Badge +4

No sorry, this doesn't really help. Id like'to have examples and experiences from people who have actually done this. The steps I could figure out myself. I even made a script that actually works. It calls a fmedatadownload service with some parameters and it returns with a download URL. I managed to download the data and show it in QGIS.

But I have a few problems/questions:

  1. When the workspace is asked for a larger dataset, I get a timeout and no data download URL! How can I prevent this from happening?
  2. I use a data download, but maybe its better to use data streaming?
  3. I use a requests.post, but maybe it needs a get.
  4. How can I upload data, like a shapefile, to FME server from QGIS?
  5. There is a Rest API, but I don't see any examples on how to use this with Python.

Thank you for yoyr reply,

I've added the pt_servicemode=async in my request and get back:

{"serviceResponse": {

  "jobID": 292954,

  "statusInfo": {

   "mode": "async",

   "status": "success"

  }

}}

 

Status says it's success but it's not finished yet. How do I go from here. Is there a way to find out when this job is finished and get the download URL?

Userlevel 4
Badge +26

No sorry, this doesn't really help. Id like'to have examples and experiences from people who have actually done this. The steps I could figure out myself. I even made a script that actually works. It calls a fmedatadownload service with some parameters and it returns with a download URL. I managed to download the data and show it in QGIS.

But I have a few problems/questions:

  1. When the workspace is asked for a larger dataset, I get a timeout and no data download URL! How can I prevent this from happening?
  2. I use a data download, but maybe its better to use data streaming?
  3. I use a requests.post, but maybe it needs a get.
  4. How can I upload data, like a shapefile, to FME server from QGIS?
  5. There is a Rest API, but I don't see any examples on how to use this with Python.

OK so the "status": "success" in your result above just means that the job was submitted successfully not that it is complete here. Async mode means that the request wont wait for the job to finish.

 

You will need to use the returned job ID to make periodic requests to the job table using this call (perhaps every 5 seconds):

https://docs.safe.com/fme/html/FME_REST/apidoc/v3/index.html#!/transformations/result_get_22

This will get you the result details including the download url in the case of a successful result.

 

 

Reply