1

I'd like to set up a Python dash application, or a Leaflet map that uses data from a layer sitting in a QField Cloud project. Is it possible to access the data from layers sitting in a QField Cloud project via an API? How would I go about doing that if it is?

(In ESRI this would involve someone collecting data through field maps and then it can be viewed live through an ArcGIS dashboard).

I've seen the API docs through QField Cloud but I can't find my project ID which I think I need and I can't figure out what call I'd need to make

https://docs.qfield.org/reference/qfieldcloud/api/

1 Answer 1

1

I don't think it's possible to directly access the geospatial data in QFieldCloud using the API. You could use the API to download the files into your local environment however.

Here's a potential Python solution. One assumption I have made is your data is in GeoPackage format, but you could adapt it for other filetypes (I've never used PostGIS in QField, so wouldn't know what to do in that situation):

Install the qfeldcloud-sdk module for Python:

pip install qfieldcloud-sdk

The Python:

    import requests
    from qfieldcloud_sdk import sdk
    
    client = sdk.Client(
        url="https://app.qfield.cloud/api/v1/"
    )
    client.login(username='yourusername', password='yourpassword')
    
    try:
        projects = client.list_projects()
        
        
        for proj in projects:
            
            files= []
            
            for file in client.list_remote_files(proj["id"]):
                if file["name"][-5:] == '.gpkg':
                    files.append(file)
            
            client.download_files(files, proj["id"], sdk.FileTransferType.PROJECT, 'your_destination_path' )

            print('Downloaded')
                   
        
    except requests.exceptions.RequestException:
        print("Oops!")

This should download all GeoPackages from your QFieldCloud. This answer has been adapted from the example in the documentation: https://docs.qfield.org/reference/qfieldcloud/sdk/

The documentation for the sdk is pretty light (what I found anyway), but you can view the code here which is pretty handy: https://github.com/opengisch/qfieldcloud-sdk-python/blob/master/qfieldcloud_sdk/sdk.py

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.