Tag: qgis

[Blog] Support Tip: Using HTML to improve your Mergin Maps project

Learn how to use HTML in your Mergin Maps project to improve survey workflows, create Google Maps links, display species info dynamically, and access offline documents.
Learn More

Sync Data from Multiple QField Users to QGIS - QGIS LAB by MIERUNE

Introduction In work and fieldwork, several people often split the tasks. Have you ever been unsure how to efficiently sync and merge data that multiple users collected in QField into QGIS ? This arti...
Learn More

(Fr) Conférence “Automatisation & SIG” mardi 25 novembre

Sorry, this entry is only available in French.

Learn More

QGIS to (Geo)Pandas follow-up

The conversation around Looking for better ways to convert between QGIS VectorLayer and (Geo)DataFrame is continuing over at https://fosstodon.org/@underdarkGIS/115442614331293320

What I’ve learned so far:

Exciting times for spatial data science tooling 🤩

Learn More

How to Open QField Projects in QGIS on a PC - QGIS LAB by MIERUNE

Introduction After you finish fieldwork with QField, you need to transfer the data you collected to QGIS before you can use it there. This article explains, separately for Android and iOS, how to tran...
Learn More

[Blog] Photo sketching is now available in Mergin Maps

Discover the new photo sketching feature in Mergin Maps – annotate images with sketches, notes, and highlights directly in the app using touch or stylus. Learn how to enable and use this tool in your QGIS projects.
Learn More

Trigger Happy: Live edits in QGIS

QGIS and PostgreSQL working well together
Learn More

Looking for better ways to convert between QGIS VectorLayer and (Geo)DataFrame

Plugin developers who want to use (Geo)Pandas-based functionality in their plugins regularly face the challenge of converting QGIS vector layers to (Geo)DataFrames. There is currently no built-in convenience function.

In Trajectools, so far, I have been performing the conversion manually, looping through all features and taking care of tricky column types, such as datetimes and geometries:

def df_from_layer_trajectools(layer,time_field_name="t"):
    # Original Trajectools 2.7 version
    names = [field.name() for field in layer.fields()]
    data = []
    for feature in layer.getFeatures():
        my_dict = {}
        for i, a in enumerate(feature.attributes()):
            if names[i] == time_field_name and isinstance(a, QDateTime):
                a = a.toPyDateTime()
            my_dict[names[i]] = a
        pt = feature.geometry().asPoint()
        my_dict["geom_x"] = pt.x()
        my_dict["geom_y"] = pt.y()
        data.append(my_dict)
    df = pd.DataFrame(data)
    return df

It works (mostly), but it’s far from fast. For the 25 million Geolife points, it takes 4 minutes:

In an attempt to speed-up (and make the conversion more robust, e.g. regarding datetime/timezone conversion and null values), I’ve spent some time at SDSL2025 with Joris Van den Bossche trying a workaround that writes the QGIS layer to an Arrow file and then reads that file with pyogrio:

def gdf_from_layer_arrow(layer):
    # SDSL2025 version
    with tempfile.TemporaryDirectory() as tmpdirname:
        path = os.path.join(tmpdirname, "data.arrow")

        options = QgsVectorFileWriter.SaveVectorOptions()
        options.actionOnExistingFile = QgsVectorFileWriter.CreateOrOverwriteFile 
        options.layerName = 'data'
        options.driverName = "arrow"
        
        QgsVectorFileWriter.writeAsVectorFormatV3(
            layer, path, QgsProject.instance().transformContext(), options
        )
       
        meta, table = pyogrio.read_arrow(path)
        gdf = gpd.GeoDataFrame.from_arrow(table)

    return gdf

Not only do we get a GeoDataFrame in return, this also runs in half the time, i.e. in 2 minutes instead of 4:

Switching to this approach will require adding pyogrio to the plugin dependencies. Looks like it could be worth it.

We also discussed another alternative: It would be faster to read the vector layer data source directly, in case it is a supported file format. However, this means we’d need separate handling for other input layers.

There’s also the issue of supporting the Processing feature that allows users to run the algorithm only on the selected features because selected features are only exposed through QgsProcessingParameterFeatureSource (and not through QgsProcessingParameterVectorLayer). Maybe the Export Selected Features algorithm can cover this case but it will export an empty layer if there is no selection.

Are you aware of any other / better ways to approach this issue? Any pointers are appreciated.

Learn More

Japan to the World: FOSS4G 2025 Japan Report - QGIS LAB by MIERUNE

Introduction On October 11 and 12, 2025, FOSS4G 2025 Japan was held at the Ikuta Campus of Senshu University. It was organized by the OSGeo Japan Chapter ( OSGeo.JP ), a general incorporated associati...
Learn More

Batch Export Maps with the QGIS Atlas Tool - QGIS LAB by MIERUNE

Introduction Have you ever wanted to use the QGIS print layout to efficiently create a large number of maps with the same layout, such as one map per municipality or one per location in a customer lis...
Learn More