1

I have two large WFS layers in QGIS (2.16.3): one with polygons and the other with points. I've selected some of the features from the polygon layer and now I'd like to select all the features from the point layer that intersect only with the selected features from the polygon layer. How would I go about doing this?

In the past I had solved the problem by saving the polygon layer's selection as a new shapefile layer. Then I would select the features from the point layer that intersect with the new layer. The problem with this approach is that the size of the shapefiles can end up being very large. I also face the first world problem of having to delete the shapefile once I'm done using it for selecting the features from the point layer.

I had also tried to copy the selected polygons and then pasting them as a temporary scratch layer, but maybe QGIS doesn't like the WFS layer I'm using, or something, because depending on which polygons I've selected, it creates only some of the features for the temporary layer, refuses to create the layer or even crashes QGIS altogether.

I had also tried to use the intersects(), geomintersects() (refFunctions 1.0 plugin) and isselected() (Expressions+ plugin) functions when selecting from the point layer with "Select by expression", but couldn't figure it out.

In another similar question posted on this site it was recommended to use Vector->Research tools->Select by Location with the "Use selected features only" checkbox ticked, but as JaakL had commented, there is no such checkbox for me either. (I would have actually just commented on that question, instead of creating a new question, had I had enough reputation to allow commenting.)

  • The function isselected() isn't a standard function in QGIS 2.x. Did you remember to load it as a custom function? instructions here: gist.github.com/kgjenkins/fc4664ddd66906957069538e89acc454 – csk Apr 4 '18 at 16:11
  • Also, you should update to the latest long term release, 2.18. Long term releases are more stable, so this may fix the crashing issue. – csk Apr 4 '18 at 16:12
0

VirtualLayers possibly to the first world problem rescue; this is a nice solution if you can express your polygon selection with some condition (I use an id <some_id> as an example here):

  • Layer -> Add Layer -> Add/Edit Virtual Layer...
  • Import -> both your WFS layers when loaded
    (you can try adding the service directly via Add -> select WFS as provider and paste in the URL, but it keeps on throwing errors for me on QGIS 2.18)

and then type

SELECT pts.*
FROM <point_layer> AS pts,
     <polygon_layer> AS plg
WHERE plg.<id_column> = <some_id>
  AND ST_Intersects(pts.geometry, plg.geometry);

into the Query field.

If you want to manually select features:

  • Edit -> Copy Features
  • Edit -> Past Features As -> Temporary Scratch Layer...

and continue with your usual workflow from there
(you could of course use that layer in the above query to get the intersecting points into a virtual layer; just omit plg.<id_column> = <some_id> AND in above query and replace <polygon_layer> with the name of the scratch layer).

  • Thank you! Using virtual layers may just be the solution I'm looking for. First I tried your concept on some test shapefiles I had created and everything worked perfectly. However, when I try it with the real (large) dataset, QGIS reaches about 44 % creating the layer and the program crashes. Is there a limitation on how much data virtual layers can handle? Maybe I'll have to see if I can get our IT department to update my QGIS to the latest version. Hopefully that will fix the crashing issue. Until then I may have to keep saving my selections as separate (temporary) shapefiles. – Esko Laiho Apr 5 '18 at 9:15
  • @EskoLaiho at what point did it crash? it sounds like while caching the WFS layers...thing is, it´s completely in-memory; both WFS layers, the virtual layer plus the query execution (and spatialite instance). it might just be too much and the WFS layer integration too needy. it´s possible that you can do better with simply creating a scratch layer with your selection and using the toolbox intersection options. updating is a good thing, though... – ThingumaBob Apr 5 '18 at 11:56
  • Now that you mention it, yes, QGIS crashes while loading features from the WFS layer at somewhere between 40 an 60 %. Weird, though, because I loaded the whole layer (with the attribute table opened too) with its around 5500 features before starting to create the virtual layer. Still, the program insisted on reloading the WFS layer again after initiating the creation of the virtual layer. As stated in my original question, the program crashes also when trying to create a scratch layer from the selection. – Esko Laiho Apr 5 '18 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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