TransWikia.com

Why is a (self) join so slow with Virtual Layer

Geographic Information Systems Asked on December 29, 2020

I use QGIS 3.4 on Windows 10

I have a polygon layer and a point layer. The points have a streetname attribute. I want to check if there are polygons with more then 1 streetname.

I took 2 steps, first Join attributes by location to get the streetnames as attribute in the polygons.
The second step is a self join in a virtual layer

SELECT T1.POLid, T1.Postalcode, T1.streetname, T2.streetname
FROM TestStreet AS T1, TestStreet AS T2
WHERE T1.POLid = T2.POLid AND T1.streetname <> T2.streetname;

I have to interrupt the processing after waiting very long.

My workaround is:

Save features As csv file
Import csv file in MSAccess
MSAccess gives instantaneous results with the same query.

What is it what I do wrong in QGIS, is there a better way just with QGIS?

One Answer

The bottleneck is likely with the join by attribute being re-evaluated many times.

You can skip this step and compute everything at once in a virtual layer. As a bonus, it will tell you if you have more than 2 streets in a polygon. Eventually, you can filter the entries having a single street name

SELECT p.polyID, COUNT(DISTINCT s.streetName) as cnt, GROUP_CONCAT(DISTINCT s.streetName) as names
FROM myPolygonLayer p
JOIN myStreetLayer s ON ST_INTERSECTS(p.geometry, s.geometry)
GROUP BY p.polyID
--HAVING COUNT(DISTINCT s.streetName) >= 2

Answered by JGH on December 29, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP