Vincent Bré
  • Member for 4 years, 2 months
  • Last seen this week
  • France
Getting unique values from multiple fields as matched using PyQGIS
10 votes

You can use the class Counter() from the collections module. from collections import Counter layer = iface.activeLayer() c = Counter([(feat['Code'],feat['Color']) for feat in layer.getFeatures()]) ...

View answer
Creating convex hull of set of points using QGIS
Accepted answer
9 votes

Instead of using the "Convex hull" tool, use the "Minimum bounding geometry" tool by specifying the desired type of geometry output as shown in the image below.

View answer
datetime to date in QGIS field calculator
Accepted answer
8 votes

I advice you to use the format_date method like this: format_date( "Enddate" , 'yyyy/MM/dd') or the to_date method without specifying a format: to_date( "Enddate" ) In both cases, ...

View answer
Counting points in polygon to analyze data using QGIS
Accepted answer
7 votes

You can use the algorithm "Join attributes by location (Summary)". For my example, I have two layers : points (your coyotes), polygons (your areas). Run the algorithm Join attributes by ...

View answer
Applying field calculator for multiple layers at once
7 votes

You can do this by making 2 loops: the first on the layers of your project and the second on the features of each layer. # Project layers project_layers = QgsProject.instance().mapLayers().values() ...

View answer
How to Intersect a variety of Polygons with lines?
Accepted answer
7 votes

This is my layer of polygons and lines. Then you use the tool "sum of line lengths" The result is a new polygonal layer (the same as the one at the entrance) but with 2 new fields: the first ...

View answer
Error transforming geometry into lat-long coordinates
6 votes

A polygon does not have a single X coordinate and a single Y coordinate. A polygon is an accumulation of vertices with an X and Y coordinate. You can use the ST_AsText function to get the WKT ...

View answer
Conditional statements in Field Calculator QGIS
6 votes

You can use the CASE WHEN statement. I will give you an example, adapt it. CASE WHEN "VALUE1" < 0.01 THEN 2 WHEN "VALUE1" >= 0.01 AND "VALUE1" < 0.1 THEN 3 ELSE 4 END I applied this ...

View answer
Selecting point with maximum value for each polygon
6 votes

The user of a SQL query is appropriate for your problem. I created 2 tables: one with 2 polygons and another with 5 points. Then I go to the database manager > Virtual layers > and open a SQL ...

View answer
Creating QgsVectorLayer from Pandas dataframe
Accepted answer
6 votes

Your method is the simplest. However, there is an alternative by creating a new layer in QGIS and completing it by browsing your dataframe pandas. import pandas as pd # Declaration of my pandas ...

View answer
Get folder path to QGIS processing scripts from PyQGIS
5 votes

If you have not changed the default path, you can recreate it using the path of your profile using qgisSettingsDirPath method from the QgsApplication class. user_directory = QgsApplication....

View answer
Adding column with area values in attributes table with standalone PyQGIS
Accepted answer
5 votes

You can execute the following code in the Python Console of QGIS. from PyQt5.QtCore import QVariant # Step 1 : Adding the Area field layer = QgsVectorLayer("C:/Users/ja/Inne/Desktop/...

View answer
Find polygons that has no points in PostGIS
Accepted answer
5 votes

Solution 1 using LEFT OUTER JOIN: SELECT polygons.id FROM polygons LEFT OUTER JOIN points ON st_within(points.geom, polygons.geom) WHERE points.id IS NULL Solution 2 using a subquery: SELECT ...

View answer
Open specific page of a PDF using QGIS actions
Accepted answer
5 votes

You can use the following Python action: import subprocess import os path_to_pdf = os.path.abspath(r'[% "path" %]') # path of your pdf file in the field path path_to_acrobat = os.path....

View answer
Create quantity map in QGIS
5 votes

For the example, I created a point layer with 5 points and a field "population". Properties of your layer > Symbology > Simple marker > Assistant The assistant allows you to vary the size of your ...

View answer
SQLite error - no such function: InitSpatialMetadata
5 votes

You won't make a error if you load the extension mod_spatialite. Look at the following code : import sqlite3 con = sqlite3.connect(dbname) con.enable_load_extension(True) cur = con.cursor() cur....

View answer
Launching processing when opening / closing QGIS project
5 votes

In your project properties, you can define Python macros. You have 3 macros: one when the project opens one when the project is saved one when the project is closed

View answer
Is it possible to import movie into QGIS?
5 votes

For work with movies, you can try QGIS Full Motion Video plugin. I don't know if he allows geotag. The link is the following: https://plugins.qgis.org/plugins/QGIS_FMV/ You must have at least QGIS ...

View answer
How to include non aggregate columns in select function if not including them in aggregate function (like GROUP BY) in PostGIS table
4 votes

If you do not want to include these fields in the GROUP BY clause, you must use an aggregation function in your SELECT clause. I illustrate an example using the array_agg function. (Documentation ...

View answer
Adding consecutive unique ID for distinct value sets and sorting by date
4 votes

You can execute the following code in the Python Console of QGIS: # Your layer your_layer = iface.activeLayer() # Unique values for your Date field stored in a list (adapts the name of your field) ...

View answer
QGIS 3x apply one data attribute table for more than 1 layer
Accepted answer
4 votes

You can execute the following code in the QGIS Python console to create a table and add it to the QGIS project. For the example, this is a temporary layer with a Polygon geometry which will be called ...

View answer
Managing layers from a specific group with PyQGIS
4 votes

If each layer of your QGIS project has a unique name, you can use the following code. The loop retrieves the name of the layers of your group then you will identify the layer with the mapLayersByName ...

View answer
Selecting features whose text is equal to the text after certain word in QGIS
4 votes

@Taras has already given an answer that solves your problem. Let me give you another one using PyQGIS. I have an attribute table with 2 fields: descriptions which corresponds to your text and equal to ...

View answer
Count number of points by name within distinct polygons
4 votes

You can use the following code (I work in the schema public): -- Creation of a new table : I use distinct to get one row for each value of polyname CREATE TABLE polytable2 AS SELECT DISTINCT polyname ...

View answer
Find and split Multipolygons in spatialite
Accepted answer
4 votes

In SpatiaLite, you can use the function ElementaryGeometries such as the following code : SELECT ElementaryGeometries('multipoly', 'geom', 'singlepoly','gid','fid') as geom FROM multipoly This ...

View answer
QGIS and PostGIS, dimensions problems
4 votes

Since the values of Z are at 0, you can create a new table on PostGIS (or update) without a z value by using ST_Force2D function. For example : DROP TABLE IF EXISTS new_table_without_z_value ; -- ...

View answer
Getting QGIS interface in French on Mac
4 votes

The following instruction is in French so that a non-English-speaking user can set QGIS to French. Pour avoir QGIS en français, tu dois avoir les paramètres suivants dans l'onglet Préférences. ...

View answer
QGIS - SQL GROUP BY and MAX
4 votes

Open the DB Manager > Virtual Layers > SQL Window and execute the following request. SELECT UID, max(Score) as max_score FROM test -- name of your layer GROUP BY UID

View answer
Keep unique names of places
4 votes

A tip is to use the QGIS tool Dissolve tool by specifying province as the grouping field. This operation makes it possible to switch from simple polygon geometry to multi-polygon geometry. Then, you ...

View answer
XY Tools unavailable under QGIS 3?
4 votes

The plugin is not available under QGIS 3. Click on this link (the official deposit of this plugin :https://plugins.qgis.org/plugins/xytools/ Click on the github link : https://github.com/...

View answer