Questions tagged [virtual-layer]

A QGIS vector layer that is a database view built using SQL over other QGIS layers.

Filter by
Sorted by
Tagged with
10
votes
2answers
2k views

Creating new Virtual Layer programmatically in QGIS?

Is it possible to create a Virtual Layer through a python script. For example, I have a layer "road", and I would like to perform sql " SELECT * FROM road WHERE type = 'Expressway' " Will this be ...
10
votes
2answers
1k views

Polygon intersection using QGIS virtual layers

I'm trying to intersect polygon geometries in QGIS by using a virtual layer: SELECT sbqry.rowid AS gid, sbqry.geom FROM (SELECT ST_Intersection(land_parcels.geometry, flood_zone....
9
votes
2answers
268 views

Using RECURSIVE in Virtual Layer

Preface For a while, I was wondering about applying the looping/iterable functions in QGIS's Virtual Layer. There were several cases when the application of a loop would be beneficial and ...
8
votes
1answer
854 views

How to create dissolved buffers using QGIS virtual layers?

To create dissolved buffers (single geometries) in PostGIS I use ST_Dump and ST_Union: SELECT row_number() over() AS gid, sbqry.* FROM ( SELECT (ST_Dump(ST_Union(ST_Buffer(...
7
votes
2answers
706 views

In QGIS is it possible to apply an expression to a join

I am trying to join by 2 text fields and there is a lot of mismatch due to CaSe and space issues... can it be run so that it's lower("field1")=lower("field2") I otherwise have to create a new field ...
6
votes
3answers
1k views

Is there a way of labeling the number of points with the same coordinates?

After reading through the following question (which is kinda related but not quite what I need): How can I show points on the same coordinate as e.g. a bigger symbol in QGIS? I found out that there ...
5
votes
2answers
234 views

How to toggle editing on a virtual layer?

When I'm adding a virtual layer to a project using QGIS 3.12.2, it cannot be toggled to edit mode. That is: the pencil icon is greyed colored. This can be said for layers created either by the Create ...
5
votes
2answers
704 views

Keeping virtual layer up to date

I have a virtual layer in QGIS 2 with a query on a CSV. The CSV gets updated regulary. I need the max/min attributes in the virtual layer to be updated as well. The virtual layer is used as a title in ...
5
votes
1answer
375 views

Getting the line middle point with SQL in QGIS

Using SQL in a Virtual Layer is it possible to get the midpoint of a line on the line? I have tried Finding middle point (midpoint) of line in QGIS? but got an error I also tried SELECT road, ...
5
votes
1answer
226 views

QGIS and 1-to-many relationship

I am using QGIS 3.10.0 I am attempting to join a spatial vector layer to a non-spatial layer (CSV). Each polygon on the spatial layer has a unique id attribute. The CSV also has this id attribute ...
5
votes
1answer
641 views

Can't export geometry generator styling to DXF - alternatives?

I've been using QGIS' wonderful geometry generator to dynamically generate root protection zones and crown areas for some tree inventories I've been working on. It's been a massive time saver. ...
5
votes
1answer
545 views

What spatial functions are available to shapefiles as “virtual layers” in QGIS DB Manager?

Can anyone provide a list of the spatial functions available in the QGIS DB Manager plugin when using shapefiles as Virtual Layers? I've been trying to use things like ST_DWithin and even ST_Buffer ...
5
votes
1answer
628 views

QGIS “Execute SQL” don't accept more than 1 input table

I have some problems using the "Execute SQL" algorithm (in General Vector Tool) in the Processing Toolbox. No problem when I've got only 1 input table, but when I try to select 2 tables as input data ...
5
votes
0answers
104 views

Selecting minimum number of neighbouring polygons required to give a fixed total area

I have a polygon layer. I would like to select the minimum number of neighbouring polygons to give a total area greater than a fixed value. In reality the polygons are land parcels and I would like to ...
4
votes
2answers
611 views

Getting concatenated attribute values from Spatial Join

How can I query polygon features that intersect other polygon features in QGIS? I have ZIP code areas and city areas, and I would like to list all the ZIP codes that intersect the city areas. Example:...
4
votes
1answer
164 views

Select all columns except geometry using virtual layers

Is it possible to select all columns except geometry using virtual layers in QGIS? For example I have this (simplified) query: Select *, st_buffer(geometry, 100) From mypolygons It does not work. ...
4
votes
1answer
724 views

Creating virtual layers using the processing toolbox

A few days ago Cy T posted an interesting question about creating virtual layers using the Python console: Creating new Virtual Layer programmatically in QGIS? Is it also possible to create virtual ...
4
votes
1answer
90 views

Using a virtual layer, display polygons based on location of another polygon layer

QGIS 3.4 I have a .gml file of every freehold title in a city outlined red below. I want to create a virtual layer of the freeholds which are contained within the blue-green isochrones. Even if a ...
4
votes
0answers
87 views

QGIS Server Adding a virtual layer

All my layers in the qgs-project-file are working fine as WMS-layers, but I only can't provide the virtual layer. The virtual layer is an ODBC-Connection of an Access-Database which contains one ...
3
votes
2answers
502 views

Virtual layer functionality does not seem to support memory layers

I have a memory layer loaded in the QGIS virtual layer in the data source manager. I am trying to run a very simple query: select * from layer Here is a snapshot: While this works for the physical ...
3
votes
1answer
67 views

Virtual Layer Symbology in Legend

I am new to QGIS and I'm using QGIS 3.8 on a Windows machine. I'm creating a commuter flow map using a virtual layer similar to the one Anita Graser has created here. When I try to add in a legend all ...
3
votes
1answer
204 views

Extending a segment in QGIS to check intersection with a polygon

I am trying to find the adress points (red dots) located in front of an obstacle (red polygon). The street is green and the pink line represents the street face (Si). This is what I have so far, but ...
3
votes
1answer
70 views

How to load polygon layer with single field as virtual layer?

I have a polygon layer with 3 fields (A, B and C). I want to create a copy and add as a virtual layer so I use CREATE VIRTUAL LAYER option but only want the first field. So I use the expression ...
3
votes
1answer
1k views

How to update SQL query for a virtual layer?

I created a virtual layer which contains all the geometries and attributes from a shapefile using the following code: vlayer = QgsVectorLayer( "?layer=ogr:path/to/shapefile", "layerName", "virtual" ) ...
3
votes
2answers
218 views

Creating a virtual layer based on a virtual field for dynamic selection in QGIS 3.4?

Working on a PostGIS database, I would like to send to the print composer the selected features only. I'v tried several methods including working with is_selected() expression but the only way that ...
3
votes
1answer
276 views

Difference between JOIN ON and WHERE in Virtual Layers in QGIS

There is already a question on this topic Difference between SpatialJoin with “…where…” and “join…on…”. However, it is dedicated to PostGIS. Since in the Virtual Layer query window, I cannot simply ...
3
votes
1answer
103 views

Add virtual layer to aggregate feature

newbie here of QGIS here, I was trying to aggregate a feature from a CSV with no geometries. The query is very basic: SELECT "PROV", SUM("POP_2012") AS POP_2012 FROM "municipalities-tuscany" ...
3
votes
1answer
289 views

How to include layer names when union'ing in virtual layers?

I am creating a virtual layer in QGIS using the following statement: SELECT * FROM ( SELECT * FROM a UNION ALL SELECT * FROM b UNION ALL SELECT * FROM c ) AS merged_tables What is the best way to ...
3
votes
0answers
360 views

Virtual layer from query with special characters in field name using PyQGIS

I have a layer loaded from a WFS server that contains fields with æøå in some of the names. I am making SQL queries to make virtual layers from this layer, but whenever I query a field with æøå in its ...
3
votes
0answers
153 views

Identify Results form for virtual layers in QGIS keeps displaying wrong feature

When I load up a virtual layer and I use the Identify Results tool, it will display the correct information in the Identify Results panel, but in the feature form popup it will always display only the ...
2
votes
1answer
431 views

How to speed up a query in a virtual layer of QGIS?

I'm trying to speed up a query in a virtual layer. I noticed that the query runs at the same time for a partial extension and full extent of the layer shown on the map. So I thought if I filtered the ...
2
votes
2answers
109 views

Selecting lines where start and end points within polygon using Virtual Layer

In QGIS 2.18 project there are several layers, lines and polygons respectively My task is to select all lines when their start and end points are laying within polygons using Virtual Layer, see image ...
2
votes
2answers
240 views

Calculating point layer values within polygon features in QGIS 2

There are two layers polygon BereichBerechnung with a field "Are_Number" points EW2017 with a field "EWjeAdr" In QGIS with a Virtual Layer, I want to calculate the sum of the field "EWjeAdr" for ...
2
votes
1answer
46 views

QGIS: no geometry in virtual layer

In QGIS 3.12.2. I created a virtual layer to use for the sort-order in a print layout as described here: Sort attribute table by hidden column in Print Composer That works, but I have a problem with ...
2
votes
1answer
69 views

Merging a legend and a table

I'm using QGIS 3.4 for this, and am creating a map that will see quite a lot of use. It will show plant species, and the area of the plants in question. For this, we have a main "plant" table. This ...
2
votes
2answers
67 views

Saving Virtual Layer to temporary layer

I like the idea of Virtual Layers, but when they are too big and constructed from complex queries, QGIS takes a lot of time to redraw it (it seems like it recalculates the entire layer at every zoom/...
2
votes
1answer
43 views

Writing txt file from Virtual Layer

I have a Virtual Table which is a result set for a particular process. select "RECORD_IDENTIFIER", CAST ("UPRN" AS textstring) AS UPRN, "KEY", "WARNING_CODE", "EXCEPTION" from Exceptions ...
2
votes
1answer
82 views

Merging shapefiles as Virtual Layer in QGIS

In QGIS 3.6.3 I'm trying to create a Virtual Layer obtained by merging 12 shapefiles (with the columns named and ordered in the same way) using the expression SELECT * FROM _January, _February, ...
2
votes
2answers
278 views

Getting nearest line to point with virtual layer using QGIS?

I have a streetmap and the position of hundred sensorlocations. I am currently trying to calculate the nearest line for each point. I have already done it with the nnjoin plugin. But now I want to do ...
2
votes
1answer
80 views

ST_Distance in Virtual Layer query not working on QGIS on Mac but on Windows

I tried to use solution posted here, but ST_Distance in the Virtual Layer query doesn't work properly in Qgis (v3.2) on Mac, the result is showing blank while the same script is working properly in ...
2
votes
2answers
84 views

write z-value from polygon layer to point layer in QGIS

I have two layers: 1 polygon layer where the depth of an area is written in the database (as DRVAL1) and and where the depth is exported as a Z-value to the geometry. 1 point layer that I use to plan ...
2
votes
1answer
131 views

UNION two LEFT JOINs as Virtual Layer in QGIS

In QGIS 2.18, there are two layers, e.g. "Locations" and "Connections" "Locations" has values Id | Dimension --------------- 1 | 4 2 | 8 3 | 2 "Connections" maintains attributes ...
2
votes
1answer
201 views

Query and export a grouped subset of fields from a shapefile layer

I have several shapefile vector layers that I need to query so I can group records and export a subset of fields to go into an excel spreadsheet. I thought I could do this by using the graphical ...
2
votes
1answer
574 views

How to save a virtual layer (from a filtered join) with features from original layer in QGIS?

To be specific, I have a shapefile on census block groups (CBGs) in Georgia, but I only want to use those in Atlanta's commuting zone (CZ). However, commuting zone is not a field in the census ...
2
votes
1answer
225 views

QGIS virtual layer path never saved as relative

When I try to use virtual layers in QGIS, I'm unable to use relative paths. I've already set in the "Project Properties", in the tab "General", the "Save paths" as relative. You can see a ...
2
votes
0answers
33 views

Extract Geometry information from NMEA GGA sentence in SQLite database for display in QGIS via a Virtual Layer

I have a SQLite database containing a GGA sentence in one of its fields. I'd like to display this information as a POINT layer. I've looked at OGR Virtual Format solution as suggested here but I ...
2
votes
0answers
48 views

Grouping points by attributes from field with possibly many values

I have a shapefile "cities" with one unique city_id for each city (geometry polygon, although not relevant here) : city_name ; city_id New-York ; 0001 Paris ; 0002 London ; 0003 And a ...
2
votes
0answers
297 views

Unable to show geometry in virtual layer qgis

I'm trying to create a virtual layer starting from a municipality layer and from a table of attributes, both stored in a Postgresql DB. So I've done a join like: *SELECT munic, country_of_origin, ...
2
votes
0answers
410 views

Clipping Virtual Raster in QGIS 3 [closed]

I have generated a virtual raster out of a large number of tifs but I am only interested in an area so I want to clip it. When I do it, it saves a raster file of several Gb. I would like to clip the ...
2
votes
0answers
261 views

Virtual Layers Clipping and Large Data Sets in QGIS

When working with large vector data sets in QGIS is there a method where you can ask QGIS to only load a small subset of your data? I know that this can be done based on attributes using a virtual ...